Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 20, 2021 05:29
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/ff8a1e59437696dc285742797464c28f to your computer and use it in GitHub Desktop.
Save todorok1/ff8a1e59437696dc285742797464c28f to your computer and use it in GitHub Desktop.
エディタ上でパーリンノイズによる地形を生成するサンプル
// 結合処理の進捗を表示します。
int step = 0;
int maxStep = 6;
EditorUtility.DisplayProgressBar(
"メッシュの結合中(" + pair.Key + ")",
"メッシュを結合しています。",
(float) step / maxStep
);
// 作成したゲームオブジェクトにセットします。
combinedMeshFilter.sharedMesh = new Mesh();
combinedMeshFilter.sharedMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
combinedMeshFilter.sharedMesh.CombineMeshes(combine);
combinedMeshFilter.sharedMesh.name = pair.Key;
step++;
EditorUtility.DisplayProgressBar(
"メッシュの結合中(" + pair.Key + ")",
"UVを生成しています。",
(float) step / maxStep
);
// 結合したメッシュでUV2を自動生成します。
Unwrapping.GenerateSecondaryUVSet(combinedMeshFilter.sharedMesh);
step++;
EditorUtility.DisplayProgressBar(
"メッシュの結合中(" + pair.Key + ")",
"メッシュをアセットとして保存しています。",
(float) step / maxStep
);
// 結合したメッシュをアセットとして保存します。
SaveMeshAsAsset(combinedMeshFilter.sharedMesh);
step++;
EditorUtility.DisplayProgressBar(
"メッシュの結合中(" + pair.Key + ")",
"結合したメッシュにマテリアルをセットしています。",
(float) step / maxStep
);
// 結合したメッシュにマテリアルをセットします。
combinedMeshRenderer.sharedMaterial = matNameDict[pair.Key];
step++;
EditorUtility.DisplayProgressBar(
"メッシュの結合中(" + pair.Key + ")",
"結合したメッシュをコライダーにセットしています。",
(float) step / maxStep
);
// 結合したメッシュをコライダーにセットします。
MeshCollider meshCol = CheckComponent<MeshCollider>(obj);
meshCol.sharedMesh = combinedMeshFilter.sharedMesh;
step++;
EditorUtility.DisplayProgressBar(
"メッシュの結合中(" + pair.Key + ")",
"結合したメッシュを表示します。",
(float) step / maxStep
);
// 親オブジェクトを表示します。
generator.fieldParent.gameObject.SetActive(true);
EditorUtility.ClearProgressBar();
}
// 結合済みのオブジェクトを削除します。
DestroyImmediate(combinedObjects);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment