本文整理汇总了C#中Vector3.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.ToArray方法的具体用法?C# Vector3.ToArray怎么用?C# Vector3.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.ToArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addLine
private void addLine(Vector3 start, Vector3 end)
{
addLine(start.ToArray(), color, end.ToArray(), color);
}
示例2: CreateMesh
/// <summary>
/// Helper method that creates a Unity Mesh from the given attribute arrays.
/// </summary>
protected static Mesh[] CreateMesh(string name, int[] triangles, Vector3[] vertices, Vector3[] normals, Vector4[] tangents, Vector2[][] uv, Color[] colors, int vertexLimit)
{
if (triangles != null && triangles.Length < 3 || vertices == null || vertices.Length < 3)
return new Mesh[] { };
if (triangles == null)
triangles = Enumerable.Range(0, vertices.Length).ToArray();
//Debug.Log("Building Meshes for attribute arrays of " + vertices.Length + " vertices and " + triangles.Length/3 + " faces.");
// The input will be split up into chunks, each with at most vertexLimit / 3 faces.
vertexLimit -= vertexLimit % 3; //Make sure it's divisible by 3.
var meshCount = (triangles.Length - 1) / vertexLimit + 1;
var result = new Mesh[meshCount];
var indexTable = new Dictionary<int, int>();
var indexTableInv = new Dictionary<int, int>();
for (int i = 0; i < result.Length; ++i)
{
result[i] = new Mesh();
result[i].name = (result.Length == 1) ? name : name + i;
// Re-index triangles to the minimum subset of vertices needed by this submesh.
var trianglesChunk = triangles.Skip(i * vertexLimit).Take(vertexLimit).ToArray();
var subTriangles = new int[trianglesChunk.Length];
for (int j = 0; j < trianglesChunk.Length; ++j)
{
int index = trianglesChunk[j];
if (!indexTable.ContainsKey(index))
{
int subIndex = indexTableInv.Count;
indexTable[index] = subIndex;
indexTableInv[subIndex] = index;
}
subTriangles[j] = indexTable[index];
}
var subVertexCount = indexTable.Count;
var subVertices = new Vector3[subVertexCount];
for (int j = 0; j < subVertexCount; ++j)
subVertices[j] = vertices[indexTableInv[j]];
result[i].vertices = subVertices.ToArray();
if (normals != null)
{
var subNormals = new Vector3[subVertexCount];
for (int j = 0; j < subVertexCount; ++j)
subNormals[j] = normals[indexTableInv[j]];
result[i].normals = subNormals;
}
if (tangents != null)
{
var subTangents = new Vector4[subVertexCount];
for (int j = 0; j < subVertexCount; ++j)
subTangents[j] = tangents[indexTableInv[j]];
result[i].tangents = subTangents;
}
if (uv.Length > 0 && uv[0] != null)
{
var subUv = new Vector2[subVertexCount];
for (int j = 0; j < subVertexCount; ++j)
subUv[j] = uv[0][indexTableInv[j]];
result[i].uv = subUv;
}
if (uv.Length > 1 && uv[1] != null)
{
var subUv1 = new Vector2[subVertexCount];
for (int j = 0; j < subVertexCount; ++j)
subUv1[j] = uv[1][indexTableInv[j]];
result[i].uv1 = subUv1;
}
if (colors != null)
{
var subColors = new Color[subVertexCount];
for (int j = 0; j < subVertexCount; ++j)
subColors[j] = colors[indexTableInv[j]];
result[i].colors = subColors;
}
result[i].triangles = subTriangles;
indexTableInv.Clear();
indexTable.Clear();
}
return result;
}
示例3: loadLevel
//.........这里部分代码省略.........
{
LinkedList<Vector3> useTargets = new LinkedList<Vector3>();
int number = int.Parse(xml.Name.Substring(3));
string variety = xml.GetAttribute("type");
useActions[number] = variety;
xml.Read();
while (!xml.Name.StartsWith("use"))
{
//read in nodes, which are all targets
//each target has a point corresponding to a tile in the layout and a type to change that tile to
if (xml.NodeType == XmlNodeType.Element && xml.Name == "target")
{
int x = int.Parse(xml.GetAttribute("x"));
int y = int.Parse(xml.GetAttribute("y"));
int type = int.Parse(xml.GetAttribute("type"));
useTargets.AddLast(new Vector3(x, y, type));
level.layout[x, y].isChangedbyButton = true;
}
else if (xml.NodeType == XmlNodeType.Element && xml.Name == "enemy")
{
xml.MoveToAttribute(0);
for (int i = 0; i < xml.AttributeCount; i++)
{
enemyFields.Add(xml.Name, xml.Value);
xml.MoveToNextAttribute();
}
}
else if (xml.NodeType == XmlNodeType.Element && xml.Name == "display")
{
messages.AddLast(xml.GetAttribute("message"));
}
xml.Read();
}
targets[number] = useTargets.ToArray();
}
xml.Read();
}
Button b = new Button();
b.useActions = useActions;
b.enemyParams = enemyFields;
b.messages = messages;
b.tiles = targets.ToArray();
foreach (KeyValuePair<string, string> entry in buttonFields)
{
if (entry.Key == "uses")
{
b.totalUses = int.Parse(entry.Value);
b.isMultipleUse = (b.totalUses > 1);
}
else if (entry.Key == "cycles")
{
b.cycles = Boolean.Parse(entry.Value);
}
else if (entry.Key == "sensor")
{
b.isMotionSensor = Boolean.Parse(entry.Value);
}
}
if (b.isMotionSensor)
{
b.assignBooleans(7);
}
level.layout[buttonX, buttonY] = b;
Vector2 position = new Vector2();
position.X = buttonX * Level.tileWidth + Level.tileWidth/2; position.Y = buttonY * Level.tileHeight+Level.tileHeight/2;
level.layout[buttonX, buttonY].position = position;
level.layout[buttonX, buttonY].setWidth(Level.tileWidth);
level.layout[buttonX, buttonY].setHeight(Level.tileHeight);
level.layout[buttonX, buttonY].origin = new Vector2(Level.tileWidth, Level.tileHeight) * .05f;
level.layout[buttonX, buttonY].updateBound();
}
//the player xml name sets player initial position
else if (xml.Name == "player")
{
int playerX = int.Parse(xml.GetAttribute("x"));
int playerY = int.Parse(xml.GetAttribute("y"));
level.player.position = new Vector2(playerX * Level.tileWidth, playerY * Level.tileHeight);
}
//enemy expects an initial position
else if (xml.Name == "enemy")
{
Dictionary<string,string> fields = new Dictionary<string,string>();
xml.MoveToAttribute(0);
for (int i = 0; i < xml.AttributeCount; i++)
{
fields.Add(xml.Name,xml.Value);
xml.MoveToNextAttribute();
}
level.enemies.AddLast(FileIOManager.createEnemyWithParams(fields));
}
}
}
xml.Close();
return level;
}
示例4: LoadMeshes
private IEnumerator LoadMeshes()
{
Debug.Log("LoadMeshes");
foreach (var way in map.ways)
{
Debug.Log("LoadWay");
var cpolyShape = new CPolygonShape(way.points.ToArray());
cpolyShape.CutEar();
var count = cpolyShape.NumberOfPolygons * 3;
Vector3[] vertices = new Vector3[count];
int[] triangles = new int[count];
int ji = 0;
for (int i = 0; i < cpolyShape.NumberOfPolygons; i++)
{
var p = cpolyShape.Polygons(i);
for (int j = 0; j < p.Length; j++)
{
triangles[ji] = ji; ;
vertices[ji] = new Vector3(0, (float)p[j].Y, (float)p[j].X);
ji++;
}
}
var g = new GameObject();
var f = g.AddComponent<MeshFilter>();
var info = g.AddComponent<Info>();
info.tags = way.tags;
var mesh = f.mesh = new Mesh();
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
mesh.RecalculateNormals();
mesh.RecalculateBounds();
var r = g.AddComponent<MeshRenderer>();
r.material = mat;
g.AddComponent<BoxCollider>();
yield return null;
}
yield return null;
}
示例5: CreateMesh2
public void CreateMesh2(List<Vector3> vertices, List<Vector2> uvs, List<Vector3> normals)
{
double t0 = EditorApplication.timeSinceStartup;
//Debug.Log ("Face Count: " + faces.Count ());
if (faces.Count () <= 0)
return;
List<int> mVerticesID = new List<int> ();
List<int> mTriangles = new List<int> ();
//populate mVerticesID containing all vertices used in all faces of mesh
foreach (List<int> face in faces) {
mVerticesID.AddRange(face);
}
//make it unique
int[] mVerticesIDArr = mVerticesID.Distinct ().ToArray ();
int[] vertLookup = new int[vertices.Count];
for (int i=0; i<vertLookup.Length; i++) {
vertLookup[i] = -1; //init values to -1
}
for (int i = 0; i < mVerticesIDArr.Length; i++) {
vertLookup[mVerticesIDArr[i]] = i;
}
Vector3[] mVertices = new Vector3[mVerticesIDArr.Length];
Vector2[] mUVs = new Vector2[mVerticesIDArr.Length];
Vector3[] mNormals = new Vector3[mVerticesIDArr.Length];
//populate data array
for (int i = 0; i < mVerticesIDArr.Length; i++) {
mVertices[i]= vertices[mVerticesIDArr[i]];
mUVs[i] = uvs[mVerticesIDArr[i]];
mNormals[i] = normals[mVerticesIDArr[i]];
}
Debug.Log ("Preparing vert data took: " + (t0 - EditorApplication.timeSinceStartup));
t0 = EditorApplication.timeSinceStartup;
double tVertLookup = 0;
double tFaceCreation = 0;
double tf;
//generate face and vertices data
foreach (List<int> face in faces) {
tf = EditorApplication.timeSinceStartup;
List<int> newFace = new List<int> ();
foreach (int vertID in face){
int newID = vertLookup[vertID];//Array.IndexOf(mVerticesIDArr, vertID); //mVerticesIDArr.Contains(vertID);
if (newID >= 0){
newFace.Add(newID);
}
}
tVertLookup += EditorApplication.timeSinceStartup - tf;
tf = EditorApplication.timeSinceStartup;
newFace.Reverse();
if (newFace.Count() == 3) {
mTriangles.AddRange(newFace);
} else { //implement face triangulation algorithm
Debug.Log ("Non-triangle face");
}
tFaceCreation += EditorApplication.timeSinceStartup - tf;
}
Debug.Log ("Computing face verts took: " + (t0 - EditorApplication.timeSinceStartup));
Debug.Log (" vertex lookup: " + tVertLookup);
Debug.Log (" face data creation: " + tFaceCreation);
t0 = EditorApplication.timeSinceStartup;
//Generate mesh object
Mesh mesh = new Mesh ();
mesh.vertices = mVertices.ToArray ();
mesh.uv = mUVs.ToArray ();
mesh.normals = mNormals.ToArray ();
mesh.triangles = mTriangles.ToArray ();
//add meshrenderer / meshfilters to parent and apply mesh
MeshRenderer mr = parent.AddComponent<MeshRenderer> ();
mr.sharedMaterial = new Material (Shader.Find ("Standard"));
MeshFilter mf = parent.AddComponent<MeshFilter> ();
mf.sharedMesh = mesh;
}