void BuildChunkPrefab(string[] chunkNames, int index) { ChunkGenerator generator = target as ChunkGenerator; generator.levelLayers[index].chunks = new List <GameObject>(); for (int i = 0; i < chunkNames.Length; i++) { if (!generator.levelLayers[index].chunksSelected[i]) { continue; } generator.levelLayers[index].chunks.Add(CreateSceneObject(CubeFile.DeSerializeObject <Chunk>(chunkNames[i], "Chunks"))); } }
void LoadChunk(string chunkName) { chunk = CubeFile.DeSerializeObject <Chunk>(chunkName, "Chunks/"); autoAdjustCOC = false; foreach (var item in chunk.objects) { item.position = new ObjRect(item.position.left + chunk.centerOfChunk.left, item.position.top + chunk.centerOfChunk.top, item.position.width, item.position.height, item.position.depth); } RefreshEditor(); CommitChanges(); }
void CreateLayerSection(int index) { ChunkGenerator generator = target as ChunkGenerator; GUILayout.BeginHorizontal(); if (GUILayout.Button(Resources.Load <Texture>("RedTriangle"), GUILayout.Width(20), GUILayout.Height(20))) { generator.visibleLayers[index] = false; } GUILayout.Box("Layer " + index.ToString()); GUILayout.EndHorizontal(); GUILayout.Box("Remember, in order to better see previews, put the CoC on top-left corner of the chunk."); GUILayout.BeginHorizontal(); GUILayout.Label("Search: ", GUILayout.Width(60)); layersInfo[index].searchPhrase = GUILayout.TextField(layersInfo[index].searchPhrase); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); layersInfo[index].showNotSelecteds = GUILayout.Toggle(layersInfo[index].showNotSelecteds, "ShowNotSelecteds"); layersInfo[index].showSelecteds = GUILayout.Toggle(layersInfo[index].showSelecteds, "ShowSelecteds"); layersInfo[index].showPreview = GUILayout.Toggle(layersInfo[index].showPreview, "Show Preview"); GUILayout.EndHorizontal(); string[] savedChunkNames = CubeFile.CheckDirectory("SavedFiles/Chunks"); if (GUILayout.Button("Build Prefabs")) { BuildChunkPrefab(savedChunkNames, index); } if (generator.levelLayers[index].chunksSelected.Length < savedChunkNames.Length) { generator.levelLayers[index].chunksSelected = new bool[savedChunkNames.Length]; } float maxX = 0; float minX = 0; float maxY = 0; float minY = 0; if (generator.levelLayers[index].hSpeed.Length == 0) { generator.levelLayers[index].hSpeed = new float[savedChunkNames.Length]; } for (int j = 0; j < savedChunkNames.Length; j++) { if (!savedChunkNames[j].Contains(layersInfo[index].searchPhrase)) { continue; } if (!(layersInfo[index].showSelecteds && layersInfo[index].showNotSelecteds)) { if ((layersInfo[index].showSelecteds && !generator.levelLayers[index].chunksSelected[j]) || (layersInfo[index].showNotSelecteds && generator.levelLayers[index].chunksSelected[j]) || (!layersInfo[index].showSelecteds && !layersInfo[index].showNotSelecteds)) { continue; } } Chunk c1 = CubeFile.DeSerializeObject <Chunk>(savedChunkNames[j], "Chunks"); Rect ChunksRect; if (layersInfo[index].showPreview) { maxX = c1.objects[0].position.left + c1.objects[0].position.width; minX = c1.objects[0].position.left; maxY = c1.objects[0].position.top + c1.objects[0].position.height; minY = c1.objects[0].position.top; foreach (var item in c1.objects) { maxX = Mathf.Max(maxX, item.position.left + item.position.width); minX = Mathf.Min(minX, item.position.left); maxY = Mathf.Max(maxY, item.position.top + item.position.height); minY = Mathf.Min(minY, item.position.top); } float scaler = (maxY - minY > maxX - minX ? 450.0f : 300.0f) / Mathf.Max((maxX - minX), (maxY - minY)); ChunksRect = GUILayoutUtility.GetRect(400, 200); GUI.Box(ChunksRect, GUIContent.none); Vector2 Offset = new Vector2(ChunksRect.xMin + 20, ChunksRect.yMin + 20); for (int i = 0; i < 10; i++) { foreach (var chunkObject in c1.objects) { if (chunkObject.position.depth != ((i + 1) * 0.5f)) { continue; } Rect tmpRect = new Rect(Offset.x + (chunkObject.position.left) * scaler, Offset.y + (chunkObject.position.top) * scaler, chunkObject.position.width * scaler, chunkObject.position.height * scaler); GUI.Label(tmpRect, Resources.Load <Texture>("Objects/" + chunkObject.texture)); } } } else { ChunksRect = GUILayoutUtility.GetRect(200, 30); } Color guiDefColor = GUI.color; if (generator.levelLayers[index].chunksSelected[j]) { GUI.color = Color.green; } else { GUI.color = Color.red; } if (GUI.Button(new Rect(ChunksRect.xMax - 105, ChunksRect.yMax - 24, 100, 20), !generator.levelLayers[index].chunksSelected[j] ? "Select" : "Deselect")) { generator.levelLayers[index].chunksSelected[j] = true ^ generator.levelLayers[index].chunksSelected[j]; } GUI.color = guiDefColor; GUI.Label(new Rect(ChunksRect.xMax - 210, ChunksRect.yMax - 24, 100, 20), c1.Name); GUI.Label(new Rect(ChunksRect.xMax - 400, ChunksRect.yMax - 44, 100, 20), "Speed: "); generator.levelLayers[index].hSpeed[j] = float.Parse(GUI.TextField(new Rect(ChunksRect.xMax - 300, ChunksRect.yMax - 44, 100, 20), generator.levelLayers[index].hSpeed[j].ToString())); GUI.Label(new Rect(ChunksRect.xMax - 400, ChunksRect.yMax - 24, 200, 20), "Chunk Size: " + (maxX - minX).ToString() + " X " + (maxY - minY).ToString()); } }