void Start() { colliderDictionary.Clear(); gridDictionary.Clear(); vertices = new List <Vector3>(); triangles = new List <int>(); UVs = new List <Vector2> (); vertices.Add(new Vector3(0.5f, -0.5f, 0)); vertices.Add(new Vector3(0.5f, 0.5f, 0)); vertices.Add(new Vector3(-0.5f, 0.5f, 0)); vertices.Add(new Vector3(-0.5f, -0.5f, 0)); int[] square = new int[4]; for (int i = 0; i < 4; i++) { square [i] = i; } BoxCollider2D coll = gameObject.AddComponent <BoxCollider2D> (); OldModule core = new OldModule(Vector2.zero, 1, square, this.gameObject, ref coll, pickup); core.baconNumber = 0; core.relations = new OldModule[4]; indexedOldModules.Add(core); core.index = 0; foreach (Vector2 uv in core.GetUV()) { UVs.Add(uv); } colliderDictionary.Add(core.collider, core); gridDictionary.Add(core.gridLocation, core); for (int i = 0; i < 4; i++) { bounds [i] = core; } width = 1; height = 1; centre = Vector2.zero; triangles.Add(2); triangles.Add(1); triangles.Add(0); triangles.Add(3); triangles.Add(2); triangles.Add(0); GenerateMesh(); }
void AddOldModule(object[] package) { BoxCollider2D rootCollider = (BoxCollider2D)package [0]; int[] rootVerts = colliderDictionary [rootCollider].vertReference; Vector2 rootLoctaion = colliderDictionary [rootCollider].gridLocation; int direction = (int)package [1]; Vector2 transform = Vector2.right; Vector2 gridLocation = Vector2.zero; bool outOfBounds = false; int se = 0; int ne = 0; int nw = 0; int sw = 0; switch (direction) { case 0: vertices.Add(vertices [rootVerts [0]] + Vector3.right); se = vertices.Count - 1; vertices.Add(vertices [rootVerts [1]] + Vector3.right); ne = vertices.Count - 1; vertices.Add(vertices [rootVerts [1]]); nw = vertices.Count - 1; vertices.Add(vertices [rootVerts [0]]); sw = vertices.Count - 1; gridLocation = rootLoctaion + transform; if (bounds [0].gridLocation [0] < gridLocation [0]) { outOfBounds = true; } break; case 1: transform = Vector2.up; vertices.Add(vertices [rootVerts [1]]); se = vertices.Count - 1; vertices.Add(vertices [rootVerts [1]] + Vector3.up); ne = vertices.Count - 1; vertices.Add(vertices [rootVerts [2]] + Vector3.up); nw = vertices.Count - 1; vertices.Add(vertices [rootVerts [2]]); sw = vertices.Count - 1; gridLocation = rootLoctaion + transform; if (bounds [1].gridLocation [1] < gridLocation [1]) { outOfBounds = true; } break; case 2: transform = Vector2.left; vertices.Add(vertices [rootVerts [3]]); se = vertices.Count - 1; vertices.Add(vertices [rootVerts [2]]); ne = vertices.Count - 1; vertices.Add(vertices [rootVerts [2]] + Vector3.left); nw = vertices.Count - 1; vertices.Add(vertices [rootVerts [3]] + Vector3.left); sw = vertices.Count - 1; gridLocation = rootLoctaion + transform; if (bounds [2].gridLocation [0] > gridLocation [0]) { outOfBounds = true; } break; case 3: transform = Vector2.down; vertices.Add(vertices [rootVerts [0]] + Vector3.down); se = vertices.Count - 1; vertices.Add(vertices [rootVerts [0]]); ne = vertices.Count - 1; vertices.Add(vertices [rootVerts [3]]); nw = vertices.Count - 1; vertices.Add(vertices [rootVerts [3]] + Vector3.down); sw = vertices.Count - 1; gridLocation = rootLoctaion + transform; if (bounds [3].gridLocation [1] > gridLocation [1]) { outOfBounds = true; } break; } int[] square = new int[4]; square [0] = se; square [1] = ne; square [2] = nw; square [3] = sw; BoxCollider2D coll = gameObject.AddComponent <BoxCollider2D> (); OldModule module = new OldModule(rootLoctaion + transform, direction, square, this.gameObject, ref coll, (GameObject)package[2]); indexedOldModules.Add(module); module.index = indexedOldModules.IndexOf(module); AddOldModuleRelations(module); foreach (Vector2 uv in module.GetUV()) { UVs.Add(uv); } colliderDictionary.Add(module.collider, module); gridDictionary.Add(module.gridLocation, module); if (outOfBounds) { bounds [direction] = module; } triangles.Add(nw); triangles.Add(ne); triangles.Add(se); triangles.Add(nw); triangles.Add(se); triangles.Add(sw); GenerateMesh(); }