Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 20, 2021 05:39
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/fa4fd8558f2c31c3eb56b2827be0b298 to your computer and use it in GitHub Desktop.
Save todorok1/fa4fd8558f2c31c3eb56b2827be0b298 to your computer and use it in GitHub Desktop.
エディタ上でパーリンノイズによる地形を生成するサンプル
/// <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