The system cannot find the file specifiedでビルドエラーになる場合

Unityのバージョンを更新した場合などに次のようなビルドエラーになってしまうことがあるようです。

Win32Exception: ApplicationName='...\tools\bin\sdkmanager.bat', CommandLine='--list', CurrentDirectory='...', Native error= The system cannot find the file specified.

そういう場合はUnityを一旦終了させて、Libraryフォルダーを削除してみるとビルドできるようになることもあるみたいです。(自己責任ですが)困っている人は試してみるのも良いかなと思います。

...の部分は省略です。

リンク

Unity Issue Tracker – “The system cannot find file specified” error while opening the project for the first time
https://issuetracker.unity3d.com/issues/the-system-cannot-find-file-specified-error-while-opening-the-project-for-the-first-time

C#で文字列の分割

C#ではSplitというメソッドを使うことで簡単に文字列の分割ができます。
使い方は次のような感じです。

コンマ「,」かハイフン「-」で分割

using System;

class Example1
{
  static public void Main()
  {
    string str = "one,two-three";
    char[] sep = { ',', '-' };

    string[] ar = str.Split(sep, StringSplitOptions.None);

    foreach(string s in ar) {
      Console.WriteLine(s);
    }
  }
}

実行結果

one
two
three

連続した3つのハイフン「---」で分割

using System;

class Example2
{
  static public void Main()
  {
    string str = "one---two-three";
    string[] sep = { "---" };

    string[] ar = str.Split(sep, StringSplitOptions.None);

    foreach(string s in ar) {
      Console.WriteLine(s);
    }
  }
}

実行結果

one
two-three

他に、正規表現を使って分割したりもできます。

リンク

String.Split Method (System) | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/api/system.string.split

文字列に合わせたUI.Textのサイズを取得する方法

UnityのUI.Textで、実際にテキストを表示した際のサイズが知りたい場合はpreferredWidthpreferredHeightを使って調べることができるそうです。

使い方

Text text;

float width = text.preferredWidth;
float height = text.preferredHeight;

テキストのサイズに合わせてUIを調整したい場合に便利かなと思います。

TextMeshPro

TexhMeshProの場合もpreferredWidthpreferredHeightを使って実際のサイズを調べることができるようです。

使い方

TMPro.TextMeshProUGUI text;

float width = text.preferredWidth;
float height = text.preferredHeight;

リンク

Unity – Scripting API: ILayoutElement
https://docs.unity3d.com/ScriptReference/UI.ILayoutElement.html

Class TextMeshProUGUI | TextMeshPro | 1.5.6
https://docs.unity3d.com/Packages/[email protected]/api/TMPro.TextMeshProUGUI.html