本文整理汇总了C#中Polygon.SetColor方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.SetColor方法的具体用法?C# Polygon.SetColor怎么用?C# Polygon.SetColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.SetColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransferPolygon
void TransferPolygon(Polygon polygon, Material destinationMaterial, Color32 destinationColor)
{
// Only attempt to transfer the polygon if it's to a different material!
if(polygon.Material == destinationMaterial)
{
return;
}
PolygonDirectory.PolygonMeshMapping originalMapping = csgModel.PolygonDirectory.FindMapping(polygon);
// Repoint the polygon's material, so it will change with rebuilds
polygon.Material = destinationMaterial;
polygon.SetColor(destinationColor);
if(originalMapping == null)
{
// This polygon hasn't actually been built
return;
}
int verticesToAdd = originalMapping.VertexIndices.Count;
int[] sourceTriangleIndices = new int[originalMapping.TriangleIndices.Count];
originalMapping.TriangleIndices.CopyTo(sourceTriangleIndices);
int[] sourceTriangles = originalMapping.Mesh.triangles;
Vector3[] sourceVertices = originalMapping.Mesh.vertices;
Vector2[] sourceUV = originalMapping.Mesh.uv;
Vector3[] sourceNormals = originalMapping.Mesh.normals;
Mesh newMesh = csgModel.GetMeshForMaterial(destinationMaterial, verticesToAdd);
#if UNITY_5_1
int[] destTriangles;
// Unfortunately in Unity 5.1 accessing .triangles on an empty mesh throws an error
if(newMesh.vertexCount == 0)
{
destTriangles = new int[0];
}
else
{
destTriangles = newMesh.triangles;
}
#else
int[] destTriangles = newMesh.triangles;
#endif
Vector3[] destVertices = newMesh.vertices;
Vector2[] destUV = newMesh.uv;
Vector3[] destNormals = newMesh.normals;
Color32[] destColors = newMesh.colors32;
int destVertexCount = destVertices.Length;
System.Array.Resize(ref destVertices, destVertexCount + verticesToAdd);
System.Array.Resize(ref destUV, destVertexCount + verticesToAdd);
System.Array.Resize(ref destNormals, destVertexCount + verticesToAdd);
System.Array.Resize(ref destColors, destVertexCount + verticesToAdd);
int[] newTriangles = new int[originalMapping.TriangleIndices.Count];
for (int i = 0; i < verticesToAdd; i++)
{
destVertices[destVertexCount + i] = sourceVertices[originalMapping.VertexIndices[i]];
destUV[destVertexCount + i] = sourceUV[originalMapping.VertexIndices[i]];
destNormals[destVertexCount + i] = sourceNormals[originalMapping.VertexIndices[i]];
destColors[destVertexCount + i] = destinationColor;
// Repoint triangles to the new location
for (int j = 0; j < originalMapping.TriangleIndices.Count; j++)
{
// TODO: Not sure about this bit
if(sourceTriangles[originalMapping.TriangleIndices[j]] == originalMapping.VertexIndices[i])
{
newTriangles[j] = destVertexCount + i;
}
}
// Repoint the vertex to the new location
originalMapping.VertexIndices[i] = destVertexCount + i;
}
int destTrianglesCount = destTriangles.Length;
int trianglesToAdd = originalMapping.TriangleIndices.Count;
for (int i = 0; i < originalMapping.TriangleIndices.Count; i++)
{
originalMapping.TriangleIndices[i] = destTrianglesCount + i;
}
System.Array.Resize(ref destTriangles, destTrianglesCount + trianglesToAdd);
for (int i = 0; i < trianglesToAdd; i++)
{
destTriangles[destTrianglesCount + i] = newTriangles[i]; //originalMapping.TriangleIndices[i];
}
newMesh.vertices = destVertices;
newMesh.triangles = destTriangles;
newMesh.uv = destUV;
newMesh.colors32 = destColors;
newMesh.normals = destNormals;
//.........这里部分代码省略.........