UnityC#
文字列のn文字目を置換する方法をメモ。 [ 方法 ] 文字列targetのn文字目をrに置換します。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScriptTest : MonoBehaviour { private void Start() { string ta…
「Player」という名前のC#スクリプトを作成して以下のスクリプトをコピペして保存します。そしてインスペクター内にある「Main Camera」にアタッチすれば、FPS視点のような動きができます。 [ スクリプト ] WASDで移動、Spaceで上昇、Ctrlで下降、Rで原点に…
Array.IndexOf、List.IndexOfの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2021.2.19.f1 [ 比較結果 ] Array.IndexOf 12702 ms List.IndexOf 12864 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using Un…
==、GameObject.CompareTagの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] == 340 ms GameObject.CompareTag 99 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using UnityEngine…
string.Contains、string.StartsWith、string.IndexOfの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] string.Contains 94 ms string.StartsWith 925 ms string.IndexOf 232 ms [ スクリプト ] using System.Collecti…
スクリプトからVolumeを変更する方法をメモ。 [ 変更方法 ] VolumeにあるBloomのIntensityを10.0fに変更するスクリプトです。 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using UnityEn…
配列のコピー方法をまとめました。 [ 一覧 ] = 「=」を使って配列をコピーするとシャローコピーになります。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScriptTest : MonoBehaviour { private void Sta…
Math.Pow(i, 3)、Mathf.Pow(i, 3)、i * i * iの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2021.2.19.f1 [ 比較結果 ] Math.Pow(i, 3) 26 ms Mathf.Pow(i, 3) 55 ms i * i * i 0 ms PowInt(i, 3) 3 ms [ スクリプト ] using System.Collectio…
Math.Cos、Mathf.Cosの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] Math.Cos 20 ms Mathf.Cos 31 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using UnityEngine; using Syste…
Math.Sin、Mathf.Sinの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] Math.Sin 20 ms Mathf.Sin 30 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using UnityEngine; using Syste…
Math.Clamp、Mathf.Clampの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] Math.Clamp 8 ms Mathf.Clamp 9 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using UnityEngine; using…
Math.Sqrt、Mathf.Sqrtの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] Math.Sqrt 4 ms Mathf.Sqrt 21 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using UnityEngine; using Sy…
Math.Abs、Mathf.Absの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] Math.Abs 6 ms Mathf.Abs 18 ms [ スクリプト ] using System.Collections; using System.Collections.Generic; using UnityEngine; using System…
Array.Contains、List.Contains、LinkedList.Contains、HashSet.Contains、Dictionary.ContainsKey、Dictionary.ContainsValueの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] Array.Contains 13984 ms List.Contains…
List.RemoveAt、LinkedList.RemoveFirst、HashSet.Remove、Dictionary.Removeの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] List.RemoveAt 261 ms LinkedList.RemoveFirst 5 ms HashSet.Remove 2 ms Dictionary.Rem…
List.Add、LinkedList.Add、HashSet.Add、Dictionary.Addの速度比較をしたので結果を残しておきます。 [ 環境 ] Unity 2018.4.14.f1 [ 比較結果 ] List.Add 0 ms LinkedList.Add 23 ms HashSet.Add 2 ms Dictionary.Add 6 ms [ スクリプト ] using System.Co…
Text/TextMeshProコンポーネントの行数の取得方法を自分用にメモ。 [ 取得方法 ] Textコンポーネント int LineCount = Text.cachedTextGeneratorForLayout.lineCount; TextMeshProコンポーネント int LineCount = TextMeshPro.textInfo.lineCount;
LightningのEnviromentにあるIntensity Multiplierの変更方法を自分用にメモ。 [ 変更方法 ] RenderSettings.ambientIntensity = 1.0f; [ 関連記事 ] edunity.hatenablog.com
LightningのEnviromentにあるAmbient Colorの変更方法を自分用にメモ。 [ 変更方法 ] RenderSettings.ambientLight = new Color(1.0f, 1.0f, 1.0f, 1.0f); [ 関連記事 ] edunity.hatenablog.com
自分用に親オブジェクトと子オブジェクトの取得方法一覧を作ることにしました。 [ 取得方法一覧 ] 親オブジェクト 親オブジェクト取得 一番上の親オブジェクト取得 子オブジェクト n番目の子オブジェクト取得 全子オブジェクト取得 子オブジェクト数取得 [ …
Lightコンポーネントの色の変更方法を自分用にメモ。 [ 変更方法 ] GameObject.Find("Directional Light").GetComponent<Light>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);</light>
ゲームオブジェクトのレイヤーの変更方法を自分用にメモ。 [ 方法 ] "hogehoge"はレイヤー名です。 gameObject.layer = LayerMask.NameToLayer("HogeHoge");
n番目の子オブジェクトの取得方法を自分用にメモ。 [ 方法 ] nは任意の値 gameObject.transform.GetChild(n).gameObject
RectTransformのWidthとHeightの変更方法をメモすることにしました。 [ 変更方法 ] using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScriptTest : MonoBehaviour { private void Start() { float Width = 100…
eulerAnglesをClampする方法を残しておくことにしました。 [ 方法 ] 下記はtransform.eulerAngles.xの範囲を-45から45にClampしています。 Vector3 EulerAngle = transform.eulerAngles; float EulerAngleX = EulerAngle.x;// 0 ~ 360 EulerAngleX = Mathf.R…
処理時間の計測方法を自分用にメモすることにしました。 [ 計測方法 ] using UnityEngine; public class ScriptTest : MonoBehaviour { private void Start() { System.Diagnostics.Stopwatch StopWatch = new System.Diagnostics.Stopwatch(); StopWatch.St…
HashSetの使い方を自分用にメモすることにしました。 [ HashSetとは ] [ 使い方 ] 宣言 初期化 要素の追加 要素の消去 全要素の消去 要素数を取得 特定の要素を含むか [ 関連記事 ] [ HashSetとは ] HashSetとは特定の要素を含むかどうかの判定はArrayやList…
自分用に文字列操作のまとめのようなもの作ってみました。 [ 文字列操作まとめ ] 文字列の連結 文字列の改行 文字列を比較 文字列の一部を消去 文字列の一部を置換 文字列の一部を取得 文字列の長さ(文字数)を取得 文字列が特定の文字を含むか取得 特定の文…
intからboolに変換する方法をメモ。 [ 方法 ] 「Convert.ToBoolean(int)」で変換できます。 [ 使用例 ] 下記はint型のIntTestをbool型に変換しBoolTestに代入しています。 using System.Collections; using System.Collections.Generic; using UnityEngine; …
UnityC#を高速化する方法を自分用にメモすることにしました。 [ 対処法 ] GameObject.Find()の使用を避ける GetComponentの使用を避ける transformの読み書きを避ける Instantiate()の使用を避ける Destroy()の使用を避ける GCが重たくなる処理を避ける Hash…