void RefreshEditor() { if (chunk.objects == null) { return; } string[] chunkItems = new string[chunk.objects.Count]; for (int i = 0; i < chunkItems.Length; i++) { chunkItems[i] = chunk.objects[i].texture + "." + chunk.objects[i].id.ToString(); } ChunkItemList = new Listbox(chunkItems, "Items", new Rect(10, 480, 200, 140), 20); string[] savedChunks = CubeFile.CheckDirectory("SavedFiles/Chunks"); SavedChunksList = new Listbox(savedChunks, "SavedChunks", new Rect(10, 295, 200, 140), 20); foreach (var item in SavedChunksList.items) { item.action = window.LoadChunk; Debug.Log(item.content[0].text + " " + chunk.Name); if (item.content[0].text.Contains(chunk.Name)) { SavedChunksList.SelectItem(item.id); } } //chunk = new Chunk("NewChunk", new Rect(0, 0, 1, 1), 0, 0, new List<LevelObj>(), 0); }
static void Init() { objSelectorGrid = new LevelObj(new Rect(0, 0, 0, 0), Resources.Load <Texture>("HexaGridRed"), 0, 0); grid = new Grid(800, 400, new Rect(215, 90, 500, 400), 40, 40); ChunkItemList = new Listbox(new string[] { "None" }, "LevelChunksHirarchy", new Rect(10, 480, 200, 140), 20); window = (ChuckEditor)EditorWindow.GetWindow(typeof(ChuckEditor)); window.minSize = new Vector2(735, 650); chunk = new Chunk("NewChunk", new Rect(0, 0, 1, 1), 0, 0, new List <LevelObj>()); string[] savedChunks = CubeFile.CheckDirectory("SavedFiles/Chunks"); window.Canvas = new ObjRect(180, 90, 800, 400); window.movingCenterOfChunk = false; SavedChunksList = new Listbox(savedChunks, "SavedLevels", new Rect(10, 295, 200, 140), 20); window.autoAdjustCOC = true; foreach (var item in SavedChunksList.items) { item.action = window.LoadChunk; } window.gridScalerRect = new Rect(715, 490, 20, 150); //foreach (var item in ChunkItemList.items) //{ // item.action = window.SelectItemOnScene; //} window.lastGrabbedObjScale = new Vector2(40, 40); window.deletedItems = new List <string>(0); window.grabbedObj = new Rect(0, 0, window.lastGrabbedObjScale.x, window.lastGrabbedObjScale.y); string[] availObjs = window.LoadAvailableObjects(); TextureList = new Listbox(availObjs, "AvailableObjects", new Rect(10, 110, 200, 140), 20); foreach (var item in TextureList.items) { item.action = window.changeSelectedBlockTexture; } window.layers = new bool[10]; window.layers[0] = true; window.layersName = new string[] { "L1", "L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9", "L10" }; window.wantsMouseMove = true; window.changeSelectedBlockTexture(""); }
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()); } }