public void OnAfterDeserialize () { if (serializedMM_mapMagic != null) mapMagic = serializedMM_mapMagic; #if VOXELAND else if (serializedMM_voxeland != null) mapMagic = serializedMM_voxeland; #endif }
private void OnEnable () { //finding mapmagic object if window is empty (has no gens) if (gens==null) { MapMagic mm = GameObject.FindObjectOfType<MapMagic>(); if (mm!=null) { mapMagic = mm; gensBiomeHierarchy.Clear(); gensBiomeHierarchy.Add(mm.gens); } #if VOXELAND else { Voxeland5.Voxeland voxeland = GameObject.FindObjectOfType<Voxeland5.Voxeland>(); if (voxeland!=null) { mapMagic = voxeland; gensBiomeHierarchy.Clear(); if (voxeland.data!=null && voxeland.data.generator!=null && voxeland.data.generator.mapMagicGens!=null) gensBiomeHierarchy.Add(voxeland.data.generator.mapMagicGens); } } #endif } instance = this; }
//could be an editor class, but scripts need an access to enabled and previewGenerator public static void Show(IMapMagic mapMagic, Generator generator, Generator.Output output) { #if UNITY_EDITOR Preview.mapMagic = mapMagic; Preview.previewGenerator = generator; Preview.previewOutput = output; #endif }
//public static virtual void Process (Chunk chunk) //gui public void DrawHeader(IMapMagic mapMagic, GeneratorsAsset gens, bool debug = false) { //drawing header background layout.Icon("MapMagic_Window_Header", new Rect(layout.field.x, layout.field.y, layout.field.width, 16)); //drawing eye icon layout.Par(14); layout.Inset(2); Rect eyeRect = layout.Inset(18); GeneratorMenuAttribute attribute = System.Attribute.GetCustomAttribute(GetType(), typeof(GeneratorMenuAttribute)) as GeneratorMenuAttribute; if (attribute != null && attribute.disengageable) { layout.Toggle(ref enabled, rect: eyeRect, onIcon: "MapMagic_GeneratorEnabled", offIcon: "MapMagic_GeneratorDisabled"); } else { layout.Icon("MapMagic_GeneratorAlwaysOn", eyeRect, Layout.IconAligment.center, Layout.IconAligment.center); } //drawing label string genName = ""; if (mapMagic != null && debug) { int num = -1; for (int n = 0; n < gens.list.Length; n++) { if (gens.list[n] == this) { num = n; } } genName += num + ". "; } genName += attribute == null? "Unknown" : attribute.name; if (mapMagic != null && debug && !mapMagic.IsGeneratorReady(this)) { genName += "*"; } Rect labelRect = layout.Inset(layout.field.width - 18 - 22); labelRect.height = 25; labelRect.y -= (1f - layout.zoom) * 6 + 2; layout.Label(genName, labelRect, fontStyle: FontStyle.Bold, fontSize: 19 - layout.zoom * 8); //drawing help link Rect helpRect = layout.Inset(22); if (attribute != null && attribute.helpLink != null && attribute.helpLink.Length != 0) { layout.Label("", helpRect, url: attribute.helpLink, icon: "MapMagic_Help"); //if (layout.Button("", helpRect, icon:"MapMagic_Help")) Application.OpenURL(attribute.helpLink); //UnityEditor.EditorGUIUtility.AddCursorRect (layout.ToDisplay(helpRect), UnityEditor.MouseCursor.Link); } layout.Par(4); }
static public void ShowWindow(IMapMagic mapMagic) { instance = (PreviewWindow)GetWindow(typeof(PreviewWindow)); //PreviewWindow window = new PreviewWindow(); // instance.mapMagic = mapMagic; instance.position = new Rect(100, 100, instance.position.width, instance.position.height); instance.titleContent = new GUIContent("Preview"); instance.Show(); }
public static void Show (GeneratorsAsset gens, IMapMagic mapMagic, bool forceOpen=true, bool asBiome=false) { //opening if force open if (forceOpen) instance = (MapMagicWindow)EditorWindow.GetWindow (typeof (MapMagicWindow)); //finding instance if (instance == null) { MapMagicWindow[] windows = Resources.FindObjectsOfTypeAll<MapMagicWindow>(); if (windows.Length==0) return; instance = windows[0]; } instance.mapMagic = mapMagic; if (!asBiome) instance.gensBiomeHierarchy.Clear(); instance.gensBiomeHierarchy.Add(gens); instance.Show(); instance.Repaint(); }
void OnGUI() { //finding the preiew object if (mapMagic == null) { mapMagic = FindObjectOfType <MapMagic>(); } if (mapMagic == null) { EditorGUI.LabelField(new Rect(10, 10, 200, 200), "No MapMagic object found, re-open the window."); return; } Vector3 camPos = new Vector3(); if (UnityEditor.SceneView.lastActiveSceneView != null) { camPos = UnityEditor.SceneView.lastActiveSceneView.camera.transform.position; } Chunk.Results closestResults = mapMagic.ClosestResults(camPos); if (closestResults == null) { EditorGUI.LabelField(new Rect(10, 10, 200, 200), "No terrains are pinned for preview"); return; } if (Preview.previewOutput == null) { EditorGUI.LabelField(new Rect(10, 10, 200, 200), "No preview output is selected"); return; } object currentObj = Preview.previewOutput.GetObject <object>(closestResults); if (currentObj == null) { EditorGUI.LabelField(new Rect(10, 10, 200, 200), "Please wait until preview \nobject is being generated."); return; } if (currentObj != lastUsedObject) { Repaint(); } //updating layouts if (baseLayout == null) { baseLayout = new Layout(); } baseLayout.maxZoom = 8; baseLayout.minZoom = 0.125f; baseLayout.zoomStep = 0.125f; baseLayout.Zoom(); baseLayout.Scroll(); //scrolling and zooming if (infoLayout == null) { infoLayout = new Layout(); } infoLayout.cursor = new Rect(); infoLayout.margin = 10; infoLayout.rightMargin = 10; infoLayout.field = new Rect(this.position.width - 200 - 10, this.position.height - 80 - 10, 200, 80); //drawing hash preview if (currentObj is SpatialHash) { SpatialHash spatialHash = (SpatialHash)currentObj; for (int i = 0; i < spatialHash.cells.Length; i++) { SpatialHash.Cell cell = spatialHash.cells[i]; //drawing grid UnityEditor.Handles.color = Color.gray; UnityEditor.Handles.DrawPolyLine( baseLayout.ToDisplay((cell.min - spatialHash.offset) / spatialHash.size * 1000), baseLayout.ToDisplay((new Vector2(cell.max.x, cell.min.y) - spatialHash.offset) / spatialHash.size * 1000), baseLayout.ToDisplay((cell.max - spatialHash.offset) / spatialHash.size * 1000), baseLayout.ToDisplay((new Vector2(cell.min.x, cell.max.y) - spatialHash.offset) / spatialHash.size * 1000), baseLayout.ToDisplay((cell.min - spatialHash.offset) / spatialHash.size * 1000)); //drawing objects UnityEditor.Handles.color = new Color(0.4f, 0.9f, 0.2f); for (int j = 0; j < cell.objs.Count; j++) { DrawCircle(baseLayout.ToDisplay((cell.objs[j].pos - spatialHash.offset) / spatialHash.size * 1000), 5); } } //drawing info UnityEditor.EditorGUI.HelpBox(infoLayout.field, "", UnityEditor.MessageType.None); UnityEditor.EditorGUI.HelpBox(infoLayout.field, "", UnityEditor.MessageType.None); infoLayout.Par(); infoLayout.fieldSize = 0.7f; //infoLayout.inputSize = 0.3f; infoLayout.Label("Count: " + spatialHash.Count); } //drawing matrix preview else if (currentObj is Matrix) { Matrix matrix = (Matrix)currentObj; //refreshing texture if matrix has changed if (matrix != lastUsedObject || (range - lastUsedRange).sqrMagnitude > 0.01f) { lastUsedObject = matrix; lastUsedRange = range; texture = new Texture2D(matrix.rect.size.x, matrix.rect.size.z); texture.filterMode = FilterMode.Point; matrix.SimpleToTexture(texture, rangeMin: range.x, rangeMax: range.y); } //drawing texture UnityEditor.EditorGUI.DrawPreviewTexture(baseLayout.ToDisplay(new Rect(0, 0, texture.width, texture.height)), texture); //drawing texture info UnityEditor.EditorGUI.HelpBox(infoLayout.field, "", UnityEditor.MessageType.None); UnityEditor.EditorGUI.HelpBox(infoLayout.field, "", UnityEditor.MessageType.None); infoLayout.fieldSize = 0.7f; //infoLayout.inputSize = 0.3f; infoLayout.Label("Size: " + texture.width + "x" + texture.height); infoLayout.Field(ref baseLayout.zoom, "Zoom: ", min: baseLayout.minZoom, max: baseLayout.maxZoom, slider: true, quadratic: true); if (matrix != null) { infoLayout.Field(ref range, "Range: ", min: 0, max: 1, slider: true); infoLayout.Par(3); if (infoLayout.Button("Save To Texture")) { #if !UNITY_WEBPLAYER string path = UnityEditor.EditorUtility.SaveFilePanel( "Save Output Texture", "Assets", "OutputTexture.png", "png"); if (path != null && path.Length != 0) { byte[] bytes = texture.EncodeToPNG(); System.IO.File.WriteAllBytes(path, bytes); } #endif } } } }