尝试使用void Start () {
Mesh mesh = GetComponent<MeshFilter>().mesh;
SplitMesh(mesh);
SetColors(mesh);
}
void SplitMesh(Mesh mesh)
{
int[] triangles = mesh.triangles;
Vector3[] verts = mesh.vertices;
Vector3[] normals = mesh.normals;
Vector2[] uvs = mesh.uv;
Vector3[] newVerts;
Vector3[] newNormals;
Vector2[] newUvs;
int n = triangles.Length;
newVerts = new Vector3[n];
newNormals = new Vector3[n];
newUvs = new Vector2[n];
for(int i = 0; i < n; i++)
{
newVerts[i] = verts[triangles[i]];
newNormals[i] = normals[triangles[i]];
if (uvs.Length > 0)
{
newUvs[i] = uvs[triangles[i]];
}
triangles[i] = i;
}
mesh.vertices = newVerts;
mesh.normals = newNormals;
mesh.uv = newUvs;
mesh.triangles = triangles;
}
void SetColors(Mesh mesh)
{
Color[] colors = new Color[mesh.vertexCount];
for (int i = 0; i < colors.Length; i+=3)
{
colors[i] = Color.red;
colors[i + 1] = Color.green;
colors[i + 2] = Color.blue;
}
mesh.colors = colors;
}
,如下所示
UICollectionView
.h
和#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>
@property(strong, nonatomic) UICollectionView *collectionView;
@end
.m
我打算在红色背景上显示绿色矩形列表,但只有红色背景显示,我错过了什么?
答案 0 :(得分:2)
使用&#34; UICollectionViewFlowLayout&#34;取代&#34; UICollectionViewLayout&#34;初始化布局时。
UICollectionViewLayout *layout = [[UICollectionViewFlowLayout alloc] init];