質問編集履歴

1

スクリプトの修正

2019/07/01 16:14

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -102,10 +102,6 @@
102
102
 
103
103
 
104
104
 
105
- private List<Mesh> meshes = new List<Mesh>();
106
-
107
-
108
-
109
105
  // Use this for initialization
110
106
 
111
107
  void Start()
@@ -122,15 +118,41 @@
122
118
 
123
119
 
124
120
 
125
- MeshFilter meshFilter = GetComponent<MeshFilter>();
121
+ var meshs = CombineMeshes(new List<Mesh> { mesh });
126
-
122
+
127
- meshFilter.sharedMesh = mesh;
123
+ GetComponent<MeshFilter>().mesh = meshs;
128
-
124
+
129
- MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
125
+ var renderer = GetComponent<MeshRenderer>();
130
-
126
+
131
- meshRenderer.material = material;
127
+ renderer.material = material;
128
+
132
-
129
+ }
130
+
131
+
132
+
133
-
133
+ private Mesh CombineMeshes(List<Mesh> meshes)
134
+
135
+ {
136
+
137
+ var combine = new CombineInstance[125000];
138
+
139
+ for (int i = 0; i < meshes.Count; i++)
140
+
141
+ {
142
+
143
+ combine[i].mesh = meshes[i];
144
+
145
+ combine[i].transform = transform.localToWorldMatrix;
146
+
147
+ }
148
+
149
+
150
+
151
+ Mesh newMesh = new Mesh();
152
+
153
+ newMesh.CombineMeshes(combine);
154
+
155
+ return mesh;
134
156
 
135
157
  }
136
158
 
@@ -400,10 +422,6 @@
400
422
 
401
423
  mesh.RecalculateBounds();
402
424
 
403
-
404
-
405
- meshes.Add(mesh);
406
-
407
425
  }
408
426
 
409
427
  }