public void initLevelShapes() { Object[] content = Resources.LoadAll("ScriptableObj/LevelShape"); foreach (Object o in content) { LevelShape ls = (LevelShape)o; int num = ls.activePos.Count; if (!randomLevelShapeDic.ContainsKey(num)) { randomLevelShapeDic[num] = new List <LevelShape>(); } randomLevelShapeDic [num].Add(ls); } // randomLevelShapeDic[4] = new List<LevelShape>(); // { // LevelShape ls = new LevelShape (); // ls.activePos.Add (new int[]{2,0}); // ls.activePos.Add (new int[]{2,1}); // ls.activePos.Add (new int[]{2,2}); // ls.activePos.Add (new int[]{2,3}); // ls.spawnPos = new int[]{2,0}; // randomLevelShapeDic [4].Add (ls); // } // // { // LevelShape ls = new LevelShape (); // ls.activePos.Add (new int[]{1,1}); // ls.activePos.Add (new int[]{2,1}); // ls.activePos.Add (new int[]{1,2}); // ls.activePos.Add (new int[]{2,2}); // ls.spawnPos = new int[]{1,2}; // randomLevelShapeDic [4].Add (ls); // } }
public Level(LevelShape shape, LevelType type) { Shape = shape; Type = type; Position = new Vector2(0, 0); }
public void Init(Shapes.ShapeValue values) { levelShape = new LevelShape(values, 0, 0); Align(); }
public void Init() { levelShape = new LevelShape(new Shapes.ShapeValue(), 0, 0); }
public void generateDungeon(string levelId) { LevelEntry levelInfo = GameStaticData.getInstance().getLevelInfo(levelId); int gridNum = levelInfo.NumOfGrid; List <EncounterEntry> toChooseFrom = new List <EncounterEntry>(levelInfo.PossibleEncounters); LevelShape ls = GameStaticData.getInstance().pickRandomShape(gridNum); if (nowLevelId == "toturial") { ls = GameStaticData.getInstance().getToturialShape(); grids = new EncounterState[GridManager.GRID_HEIGHT][]; for (int i = 0; i < GridManager.GRID_HEIGHT; i++) { grids[i] = new EncounterState[GridManager.GRID_WIDTH]; } EncounterEntry entry1 = toChooseFrom [0]; EncounterEntry entry2 = toChooseFrom [1]; grids [ls.activePos[0].x] [ls.activePos[0].y] = new EncounterState("empty"); grids [ls.activePos[1].x] [ls.activePos[1].y] = new EncounterState(entry1.eid); grids [ls.activePos[2].x] [ls.activePos[2].y] = new EncounterState(entry2.eid); playerPos = ls.spawnPos; grids [ls.endPos.x] [ls.endPos.y] = new EncounterState("next_level_01"); return; } int totalLeft = gridNum - 2; int encounterLeft = levelInfo.NumOfEncounter; if (encounterLeft > totalLeft) { encounterLeft = totalLeft; } grids = new EncounterState[GridManager.GRID_HEIGHT][]; for (int i = 0; i < GridManager.GRID_HEIGHT; i++) { grids[i] = new EncounterState[GridManager.GRID_WIDTH]; } for (int i = 0; i < ls.activePos.Count; i++) { if (ls.activePos [i] == ls.endPos || ls.activePos [i] == ls.spawnPos) { continue; } int ranInt = Random.Range(0, totalLeft); if (ranInt < encounterLeft) { totalLeft--; encounterLeft--; EncounterEntry entry = toChooseFrom [Random.Range(0, toChooseFrom.Count)]; grids [ls.activePos[i][0]] [ls.activePos[i][1]] = new EncounterState(entry.eid); } else { totalLeft--; grids [ls.activePos[i][0]] [ls.activePos[i][1]] = new EncounterState(); } } //grids [2] [3] = new EncounterState ("shop"); playerPos = ls.spawnPos; grids [ls.spawnPos.x] [ls.spawnPos.y] = new EncounterState("empty"); grids[ls.endPos.x][ls.endPos.y] = new EncounterState("next_level_01"); }
static GameObject CreateMeshFromColl(LevelBase l, Transform t, LevelShape[] s) { GameObject partObj = new GameObject("Part"); PolygonCollider2D[] colls = t.GetComponents<PolygonCollider2D>(); Polygon polygon = null; List<EdgeCollider2D> collsToAdd = new List<EdgeCollider2D>(); foreach (PolygonCollider2D c in colls) { if (c.enabled == false) continue; Vector2[] vecs = c.points; List<Vector2> edgeVecs = new List<Vector2>(); edgeVecs.AddRange(vecs); edgeVecs.Add(vecs[0]); EdgeCollider2D e = partObj.AddComponent<EdgeCollider2D>(); e.points = edgeVecs.ToArray(); List<PolygonPoint> pts = new List<Poly2Tri.PolygonPoint>(); for (int i = 0; i < vecs.Length; i++) { PolygonPoint pt = new Poly2Tri.PolygonPoint(vecs[i].x * l.factor, vecs[i].y * l.factor); pts.Add(pt); } if (polygon == null) { polygon = new Polygon(pts); } else { pts.Reverse(); polygon.AddHole(new Polygon(pts)); } c.enabled = false; } P2T.Triangulate(polygon); Mesh m = CreateMesh2(polygon.Points, polygon.Triangles); Vector3[] vertices = m.vertices; Color[] colors = new Color[vertices.Length]; int j = 0; while (j < vertices.Length) { colors[j] = l.fillColor; j++; } m.colors = colors; MeshFilter mf = partObj.AddComponent<MeshFilter>(); bool extrudeMesh = false; if (extrudeMesh) { Mesh extruded = new Mesh(); Matrix4x4 m1 = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1, 1, 1)); List<Matrix4x4> mxs = new List<Matrix4x4>(); mxs.Add(m1); for (int i = 0; i < s.Length; i++) { Matrix4x4 m3 = Matrix4x4.TRS(s[i].exturePos, Quaternion.Euler(s[i].extrudeRotation.x, s[i].extrudeRotation.y, s[i].extrudeRotation.z), s[i].extrudeScale); mxs.Add(m3); } MeshExtrusion.ExtrudeMesh(m, extruded, mxs.ToArray(), false); mf.sharedMesh = extruded; } else { mf.sharedMesh = m; } MeshRenderer mr = partObj.AddComponent<MeshRenderer>(); mr.material = l.hillMaterial; return partObj; }