-
-
Save todorok1/edc85fa26f97075ed16f18d5db2040b4 to your computer and use it in GitHub Desktop.
メッシュを結合するメソッドの準備部分
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <Summary> | |
/// メッシュとマテリアルを結合します。 | |
/// </Summary> | |
void CombineMeshWithMaterial() | |
{ | |
// 地形オブジェクトのMeshFilterへの参照を配列として保持します。 | |
MeshFilter[] meshFilters = fieldParent.GetComponentsInChildren<MeshFilter>(); | |
MeshRenderer[] meshRenderers = fieldParent.GetComponentsInChildren<MeshRenderer>(); | |
// MeshFilterとMeshRendererの数が合っていない場合は処理を抜けます。 | |
if (meshFilters.Length != meshRenderers.Length) | |
{ | |
return; | |
} | |
// 子オブジェクトのメッシュをマテリアルごとにグループ分けします。 | |
Dictionary<string, Material> matNameDict = new Dictionary<string, Material>(); | |
Dictionary<string, List<MeshFilter>> matFilterDict = new Dictionary<string, List<MeshFilter>>(); | |
for (int i = 0; i < meshFilters.Length; i++) | |
{ | |
Material mat = meshRenderers[i].material; | |
string matName = mat.name; | |
// 辞書のキーにマテリアルが登録されていない場合はMeshFilterのリストを追加します。 | |
if (!matFilterDict.ContainsKey(matName)) | |
{ | |
List<MeshFilter> filterList = new List<MeshFilter>(); | |
matFilterDict.Add(matName, filterList); | |
matNameDict.Add(matName, mat); | |
} | |
matFilterDict[matName].Add(meshFilters[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment