Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 3, 2021 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/973e7a08029a5768b319b8adf9da7b23 to your computer and use it in GitHub Desktop.
Save todorok1/973e7a08029a5768b319b8adf9da7b23 to your computer and use it in GitHub Desktop.
メッシュを保持するオブジェクトの作成とコンポーネントの確認用メソッド
/// <Summary>
/// 結合したメッシュを表示するGameObjectを作成します。
/// </Summary>
GameObject CreateMeshObj(string matName)
{
GameObject obj = new GameObject();
obj.name = $"CombinedMesh_{matName}";
obj.transform.SetParent(fieldParent);
obj.transform.localPosition = Vector3.zero;
return obj;
}
/// <Summary>
/// 指定されたコンポーネントへの参照を取得します。
/// コンポーネントがない場合はアタッチします。
/// </Summary>
T CheckComponent<T>(GameObject obj) where T : Component
{
// 型パラメータで指定したコンポーネントへの参照を取得します。
var targetComp = obj.GetComponent<T>();
if (targetComp == null)
{
targetComp = obj.AddComponent<T>();
}
return targetComp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment