public void OnGUI() { titleContent = new GUIContent("Select Texture Type:"); //position = new Rect(position.x, position.y, 50, 150); EditorGUILayout.BeginVertical(); if (GUILayout.Button("RGBA")) { inspector.texArrDec.Format(TextureExtensions.AutoFormat(TextureExtensions.TextureType.RGBA, compresed)); Close(); } if (GUILayout.Button("RGB (no alpha)")) { inspector.texArrDec.Format(TextureExtensions.AutoFormat(TextureExtensions.TextureType.RGB, compresed)); Close(); } if (GUILayout.Button("Normap Map")) { inspector.texArrDec.Format(TextureExtensions.AutoFormat(TextureExtensions.TextureType.Normal, compresed)); Close(); } if (GUILayout.Button("Monochrome")) { inspector.texArrDec.Format(TextureExtensions.AutoFormat(TextureExtensions.TextureType.Monochrome, compresed)); Close(); } if (GUILayout.Button("Monochrome 32bit float")) { inspector.texArrDec.Format(TextureExtensions.AutoFormat(TextureExtensions.TextureType.MonochromeFloat, compresed)); Close(); } EditorGUILayout.Space(); if (GUILayout.Button("Cancel")) { Close(); } EditorGUILayout.EndVertical(); }
static void CreateVoxeland (bool infinite=true) { GameObject go = new GameObject(); go.name = "Voxeland"; Voxeland voxeland = go.AddComponent<Voxeland>(); voxeland.chunks = new ChunkGrid<Chunk>(); voxeland.chunkSize = 30; Voxeland.instances.Add(voxeland); //adding empty layer voxeland.landTypes = new LandTypeList(); ArrayTools.Add(ref voxeland.landTypes.array, new BlockType()); voxeland.landTypes.array[0].mainTex = TextureExtensions.ColorTexture(2,2,new Color(0.666f, 0.666f, 0.666f, 0.5f), linear:false); #if UNITY_2017_3_OR_NEWER voxeland.landTypes.array[0].bumpMap = TextureExtensions.ColorTexture(2,2,new Color(0.5f, 0.5f, 0.5f, 1f), linear:true); #else voxeland.landTypes.array[0].bumpMap = TextureExtensions.ColorTexture(2,2,new Color(0.5f, 0.5f, 0.5f, 0.5f), linear:true); #endif //voxeland.landTypes.mainTexArray = new Texture2DArray(1024, 1024, 1, TextureFormat.DXT5, true) { name = "Albedo Height Array" }; //voxeland.landTypes.mainTexArray.SetTexture( TextureExtensions.ColorTexture(1024,1024,Color.gray), 0); //voxeland.landTypes.bumpMapArray = new Texture2DArray(1024, 1024, 1, TextureFormat.DXT5, true, linear:true) { name = "Normals Array" }; //voxeland.landTypes.bumpMapArray.SetTexture( TextureExtensions.ColorTexture(1024,1024,new Color(0.5f,0.5f,0.5f,0.5f)), 0); voxeland.landTypes.selected = 0; //adding empty grass voxeland.grassTypes = new GrassTypeList(); voxeland.grassTypes.selected = -1; //objects voxeland.objectsTypes = new ObjectTypeList(); voxeland.objectsTypes.selected = -1; //data voxeland.data = ScriptableObject.CreateInstance<Data>(); voxeland.data.areas = new ChunkGrid<Data.Area>(); voxeland.data.areaSize = 512; //materials voxeland.material = Voxeland.GetDefaultLandMaterial(); voxeland.farMaterial = Voxeland.GetDefaultFarMaterial(); voxeland.grassMaterial = Voxeland.GetDefaultGrassMaterial(); voxeland.landTypes.ApplyToMaterial(voxeland.material); voxeland.landTypes.ApplyToMaterial(voxeland.farMaterial, horizon:true); voxeland.grassTypes.ApplyToMaterial(voxeland.grassMaterial); if (voxeland.horizon != null) voxeland.horizon.meshRenderer.sharedMaterial = voxeland.farMaterial; //highlight if (voxeland.highlight == null) //could be created on de-prefab in onenable { voxeland.highlight = Highlight.Create(voxeland); voxeland.highlight.material = Voxeland.GetDefaultHighlightMaterial(); //new Material( Shader.Find("Voxeland/Highlight") ); } //static and infinite if (infinite) { voxeland.playmodeSizeMode = Voxeland.SizeMode.DynamicInfinite; voxeland.editorSizeMode = Voxeland.SizeMode.DynamicInfinite; voxeland.saveMeshes = false; voxeland.horizon = Horizon.Create(voxeland); } else { voxeland.playmodeSizeMode = Voxeland.SizeMode.Static; voxeland.editorSizeMode = Voxeland.SizeMode.Static; voxeland.saveMeshes = true; } //generators voxeland.data.generator.noiseGen.enabled = true; voxeland.data.generator.noiseGenB.enabled = false; voxeland.data.generator.noiseGenB.seed = 1234; voxeland.data.generator.noiseGenB.high = 0.1f; voxeland.data.generator.curveGen.enabled = true; voxeland.data.generator.blurGen.enabled = true; //registering undo Undo.RegisterCreatedObjectUndo (go, "Voxeland Create"); EditorUtility.SetDirty(go); }
public override void OnGUI(Rect rect) { if (background == null) { background = new Texture2D(1, 1, TextureFormat.RGBA32, false); background.SetPixel(0, 0, new Color(0.98f, 0.98f, 0.98f)); background.Apply(); } if (highlight == null) { highlight = new Texture2D(1, 1, TextureFormat.RGBA32, false); highlight.SetPixel(0, 0, new Color(0.6f, 0.7f, 0.9f)); highlight.Apply(); } //background //if (Event.current.type == EventType.repaint) GUI.skin.box.Draw(fullRect, false, true, true, false); GUI.DrawTexture(new Rect(1, 1, width - 2, lineHeight * items.Length), background, ScaleMode.StretchToFill); //list float currentHeight = 0; for (int i = 0; i < items.Length; i++) { MenuItem currentItem = items[i]; Rect lineRect; //labels if (currentItem.name != null) { lineRect = new Rect(1, currentHeight + 1, width - 2, lineHeight - 2); currentHeight += lineHeight; currentItem.clicked = false; bool highlighted = lineRect.Contains(Event.current.mousePosition); if (currentItem.disabled) { highlighted = false; } if (highlighted) { GUI.DrawTexture(lineRect, highlight); } UnityEditor.EditorGUI.BeginDisabledGroup(currentItem.disabled); if (blackLabel == null) { blackLabel = new GUIStyle(UnityEditor.EditorStyles.label); blackLabel.normal.textColor = Color.black; } UnityEditor.EditorGUI.LabelField(new Rect(lineRect.x + 3, lineRect.y, lineRect.width - 3, lineRect.height), currentItem.name, blackLabel); UnityEditor.EditorGUI.EndDisabledGroup(); if (currentItem.hasSubs) { Rect rightRect = lineRect; rightRect.width = 10; rightRect.height = 10; rightRect.x = lineRect.x + lineRect.width - rightRect.width; rightRect.y = lineRect.y + lineRect.height / 2 - rightRect.height / 2; //UnityEditor.EditorGUI.LabelField(rightRect, "\u25B6"); if (triangle == null) { triangle = Resources.Load("PopupMenuTrangleIcon") as Texture2D; } GUI.DrawTexture(rightRect, triangle, ScaleMode.ScaleAndCrop); } //opening subsmenus if (highlighted) { bool clicked = Event.current.type == EventType.MouseDown && Event.current.type == 0; if (clicked && currentItem.onClick != null) { currentItem.onClick(); CloseRecursive(); } //starting timer on selected item change if (currentItem != lastItem) { lastTimestart = System.DateTime.Now; lastItem = currentItem; } //when holding for too long double highlightTime = (System.DateTime.Now - lastTimestart).TotalMilliseconds; if ((highlightTime > 300 && expandedItem != currentItem) || clicked) { //re-opening expanded window if (expandedWindow != null && expandedWindow.editorWindow != null) { expandedWindow.editorWindow.Close(); } expandedWindow = new PopupMenu() { items = currentItem.subItems, parent = this }; expandedItem = currentItem; if (currentItem.subItems != null) { PopupWindow.Show(new Rect(lineRect.max - new Vector2(0, lineHeight), Vector2.zero), expandedWindow); } } } } //separator else { lineRect = new Rect(4, currentHeight + separatorHeight / 2, width - 4 - 4 - 2, 1); currentHeight += separatorHeight; if (separator == null) { separator = TextureExtensions.ColorTexture(2, 2, new Color(0.3f, 0.3f, 0.3f, 1)); } Rect separatorRect = new Rect(lineRect.x + 3, lineRect.y, lineRect.width - 3, lineRect.height); GUI.DrawTexture(separatorRect, separator, ScaleMode.ScaleAndCrop); } } //#if (!UNITY_EDITOR_LINUX) this.editorWindow.Repaint(); //#endif }