public static void DrawMegaSplatAssignedTextureArraysWarning() { Terrains.TerrainSettings settings = GraphWindow.current.mapMagic.terrainSettings; { using (Cell.LinePx(70)) { //Cell.current.margins = new Padding(4); GUIStyle backStyle = UI.current.textures.GetElementStyle("DPUI/Backgrounds/Foldout"); Draw.Element(backStyle); Draw.Element(backStyle); using (Cell.Row) Draw.Label("Material has \nno Albedo/Height \nTexture Array \nassigned"); using (Cell.RowPx(30)) if (Draw.Button("Fix")) { Shader shader = ReflectionExtensions.CallStaticMethodFrom("Assembly-CSharp-Editor", "SplatArrayShaderGUI", "NewShader", null) as Shader; settings.material = new Material(shader); settings.material.EnableKeyword("_TERRAIN"); GraphWindow.current.mapMagic.ApplyTerrainSettings(); GraphWindow.RefreshMapMagic(); } } Cell.EmptyLinePx(5); } }
public static void DuplicateGenerators(this Graph graph, ref HashSet <Generator> gens) /// Changes the selected hashset { GraphWindow.RecordCompleteUndo(); if (gens.Count == 0) { return; } Generator[] duplicatedGens = graph.Duplicate(gens); //placing under source generators Rect selectionRect = new Rect(duplicatedGens[0].guiPosition, Vector2.zero); foreach (Generator gen in duplicatedGens) { selectionRect = selectionRect.Encapsulate(new Rect(gen.guiPosition, gen.guiSize)); } foreach (Generator gen in duplicatedGens) { gen.guiPosition.y += selectionRect.size.y + 20; } gens.Clear(); gens.AddRange(duplicatedGens); GraphWindow.current.Focus(); //to return focus from right-click menu GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static void HeightOutputEditor(MatrixGenerators.HeightOutput200 heightOut) { using (Cell.Padded(1, 1, 0, 0)) { using (Cell.LinePx(0)) { Cell.current.fieldWidth = 0.4f; if (GraphWindow.current.mapMagic != null) { using (Cell.LineStd) GeneratorDraw.DrawGlobalVar(ref GraphWindow.current.mapMagic.globals.height, "Height"); } if (GraphWindow.current.mapMagic != null) { using (Cell.LineStd) GeneratorDraw.DrawGlobalVar(ref GraphWindow.current.mapMagic.globals.heightInterpolation, "Interpolate"); } using (Cell.LineStd) Draw.Field(ref heightOut.outputLevel, "Out Level"); if (Cell.current.valChanged) { GraphWindow.RefreshMapMagic(heightOut); } } } }
public static GraphWindow ShowInNewTab (Graph graph) { GraphWindow window = CreateInstance<GraphWindow>(); window.OpenRoot(graph); ShowWindow(window, inTab:true); return window; }
public static void CurveGeneratorEditor (MatrixGenerators.UnityCurve200 gen) { using (Cell.LinePx(GeneratorDraw.nodeWidth+4)) //don't really know why 4 using (Cell.Padded(5)) { Draw.AnimationCurve(gen.curve); if (Cell.current.valChanged) GraphWindow.RefreshMapMagic(gen); } }
public void OnInspectorUpdate () { current = this; //updating gauge if (mapMagic == null) return; bool isGenerating = mapMagic.IsGenerating() && mapMagic.ContainsGraph(graph); if (wasGenerating) { Repaint(); wasGenerating=false; } //1 frame delay after generate is finished if (isGenerating) { Repaint(); wasGenerating=true; } }
public static PopupMenu.Item InsertItems(Vector2 mousePos, Graph graph, IInlet <object> inlet, int priority = 4) { IOutlet <object> outlet = graph.GetLink(inlet); PopupMenu.Item insertItems; if (inlet != null && outlet != null) { Type genericLinkType = Generator.GetGenericType(inlet); PopupMenu.Item createItems = CreateItems(mousePos, graph); PopupMenu.Item catItems = createItems.Find(GetCategoryByType(genericLinkType)); insertItems = catItems.Find("Modifiers"); //adding link to all create actions foreach (PopupMenu.Item item in insertItems.All(true)) { if (item.onClick != null) { Action baseOnClick = item.onClick; item.onClick = () => { baseOnClick(); Generator createdGen = graph.generators[graph.generators.Length - 1]; //the last on is the one that's just created. Hacky if (createdGen != null && Generator.GetGenericType((Generator)createdGen) == genericLinkType) { //inlet graph.AutoLink(createdGen, outlet); //outlet if (createdGen is IOutlet <object> createdOutlet) { graph.Link(createdOutlet, inlet); } } GraphWindow.RefreshMapMagic(createdGen); }; } } } else { insertItems = new PopupMenu.Item("Add"); insertItems.onDraw = RightClick.DrawItem; insertItems.disabled = true; } insertItems.name = "Add (Insert)"; insertItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Create"); insertItems.color = Color.gray; insertItems.priority = priority; return(insertItems); }
private void OnGUI() { current = this; mapMagic = GetRelatedMapMagic(graph); if (graph==null || graph.generators==null) return; if (graphUI.undo == null) { graphUI.undo = new Den.Tools.GUI.Undo() { undoObject = graph , undoName = "MapMagic Graph Change" }; graphUI.undo.undoAction = GraphWindow.RefreshMapMagic; } graphUI.undo.undoObject = graph; BeginWindows(); //using (Timer.Start("UI_Graph")) graphUI.DrawInSubWindow(DrawGraph, 1, new Rect(0, toolbarSize, position.width, position.height-toolbarSize) ); //using (Timer.Start("UI_Toolbar")) toolbarUI.DrawInSubWindow(DrawToolbar, 2, new Rect(0, 0, position.width, toolbarSize)); EndWindows(); //graphUI.Draw(DrawGraph); //toolbarUI.Draw(DrawToolbar); //storing graph pivot to focus it on load Vector3 scrollZoom = graphUI.scrollZoom.GetWindowCenter(position.size); scrollZoom.z = graphUI.scrollZoom.zoom; if (graphsScrollZooms.ContainsKey(graph)) graphsScrollZooms[graph] = scrollZoom; else graphsScrollZooms.Add(graph, scrollZoom); //debug mouse pos //Draw.DebugMousePos(); //switching to main on field drag release //mapMagic.guiDraggingField = DragDrop.obj!=null && (DragDrop.group=="DragField" || DragDrop.group=="DragCurve" || DragDrop.group=="DragLevels"); if (mapMagic != null) { bool newForceDrafts = DragDrop.obj!=null && (DragDrop.group=="DragField" || DragDrop.group=="DragCurve" || DragDrop.group=="DragLevels"); if (!newForceDrafts && mapMagic.guiDraggingField) { mapMagic.guiDraggingField = newForceDrafts; mapMagic.SwitchLods(); } mapMagic.guiDraggingField = newForceDrafts; } //showing fps /*long currentFrameTime = System.Diagnostics.Stopwatch.GetTimestamp(); float timeDelta = 1f * (currentFrameTime-lastFrameTime) / System.Diagnostics.Stopwatch.Frequency; lastFrameTime = currentFrameTime; float fps = 1 / timeDelta; EditorGUI.LabelField(new Rect(position.x+position.width-70, 0, 70, 18), "FPS:" + fps.ToString("0.0"));*/ }
public static Group CreateGroup(Vector2 mousePos, Graph graph) { GraphWindow.RecordCompleteUndo(); Group grp = new Group(); grp.guiPos = mousePos; graph.Add(grp); return(grp); }
private static void FocusRepaintRefreshWindow() { if (GraphWindow.current == null) { return; } GraphWindow.current.Focus(); GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static void RemoveGroupContents(Group group, Graph graph) /// Called from editor. Removes the enlisted generators on group remove { GraphWindow.RecordCompleteUndo(); Generator[] containedGens = GetContainedGenerators(group, graph.generators); for (int i = 0; i < containedGens.Length; i++) { graph.Remove(containedGens[i]); } }
public static void DrawPortalSelector(Graph graph, IPortalExit <object> portalExit) { //if (MapMagic.instance.guiGens == null) MapMagic.instance.guiGens = MapMagic.instance.gens; //GeneratorsAsset gens = MapMagic.instance.guiGens; //if (MapMagic.instance.guiGens != null) gens = MapMagic.instance.guiGens; Type exitType = portalExit.GetType().BaseType.GetGenericArguments()[0]; if (itemTextStyle == null) { itemTextStyle = new GUIStyle(UnityEditor.EditorStyles.label); itemTextStyle.normal.textColor = itemTextStyle.focused.textColor = itemTextStyle.active.textColor = Color.black; } List <Item> enterPortalsItems = new List <Item>(); for (int g = 0; g < graph.generators.Length; g++) { IPortalEnter <object> portalEnter = graph.generators[g] as IPortalEnter <object>; if (portalEnter == null) { continue; } if (portalEnter.GetType().BaseType.GetGenericArguments()[0] != exitType) { continue; } //TODO: generic portals Item item = new Item(portalEnter.Name, onDraw: (i, r) => EditorGUI.LabelField(r, i.name, itemTextStyle), onClick: () => { if (graph.AreDependent((Generator)portalExit, (Generator)portalEnter)) { EditorUtility.DisplayDialog("MapMagic", "Linking portals this way will create a dependency loop.", "Cancel"); return; } portalExit.AssignEnter(portalEnter, graph); GraphWindow.RefreshMapMagic(); }); enterPortalsItems.Add(item); } PopupMenu menu = new PopupMenu() { items = enterPortalsItems }; menu.Show(Event.current.mousePosition); }
public static bool ShowEditor (int instanceID, int line) { UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID); if (obj is Nodes.Graph graph) { if (UI.current != null) UI.current.DrawAfter( new Action( ()=>GraphWindow.Show(graph) ) ); //if opened via graph while drawing it - opening after draw else Show(graph); return true; } if (obj is MapMagicObject) { GraphWindow.Show(((MapMagicObject)obj).graph); return true; } return false; }
public static GraphWindow Show (Graph graph) { GraphWindow window = null; GraphWindow[] allWindows = Resources.FindObjectsOfTypeAll<GraphWindow>(); //if opened as biome via focused graph window - opening as biome if (focusedWindow is GraphWindow focWin && focWin.graph.ContainsSubGraph(graph)) { focWin.OpenBiome(graph); return focWin; } //if opened only one window - using it (and trying to load mm biomes) if (window == null) { if (allWindows.Length == 1) { window = allWindows[0]; if (!window.TryOpenMapMagicBiome(graph)) window.OpenRoot(graph); } } //if window with this graph currently opened - just focusing it if (window == null) { for (int w=0; w<allWindows.Length; w++) if (allWindows[w].graph == graph) window = allWindows[w]; } //if the window with parent graph currently opened if (window == null) { for (int w=0; w<allWindows.Length; w++) if (allWindows[w].graph.ContainsSubGraph(graph)) { window = allWindows[w]; window.OpenBiome(graph); } } //if no window found after all - creating new tab (and trying to load mm biomes) if (window == null) { window = CreateInstance<GraphWindow>(); if (!window.TryOpenMapMagicBiome(graph)) window.OpenRoot(graph); } ShowWindow(window, inTab:false); return window; }
private static void ShowWindow (GraphWindow window, bool inTab=false) /// Opens the graph window. But it should be created and graph assigned first. { Texture2D icon = TexturesCache.LoadTextureAtPath("MapMagic/Icons/Window"); window.titleContent = new GUIContent("MapMagic Graph", icon); if (inTab) window.ShowTab(); else window.Show(); window.Focus(); window.Repaint(); window.ScrollZoomOnOpen(); //focusing after window has shown (since it needs window size) }
public static void CreateGenerator(this Graph graph, Type type, Vector2 mousePos) { GraphWindow.RecordCompleteUndo(); Generator gen = Generator.Create(type, graph); gen.guiPosition = new Vector2(mousePos.x - GeneratorDraw.nodeWidth / 2, mousePos.y - GeneratorDraw.headerHeight / 2); graph.Add(gen); GraphWindow.current.Focus(); //to return focus from right-click menu GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static Group CreateGroup(Vector2 mousePos, Graph graph) { GraphWindow.RecordCompleteUndo(); Group grp = new Group(); grp.guiPos = mousePos; graph.Add(grp); GraphWindow.current.Focus(); GraphWindow.current.Repaint(); //GraphWindow.RefreshMapMagic(); //not necessary return(grp); }
public static void RemoveGroup(Group grp, Graph graph, bool withContent = false) { GraphWindow.RecordCompleteUndo(); if (withContent) { GroupDraw.RemoveGroupContents(grp, graph); } graph.Remove(grp); GraphWindow.current.Focus(); GraphWindow.current.Repaint(); if (withContent) { GraphWindow.RefreshMapMagic(); } }
public static void RemoveGenerators(this Graph graph, HashSet <Generator> selected) { bool isOutput = false; foreach (Generator gen in selected) { if (gen is IOutputGenerator) { isOutput = true; break; } } if (isOutput && GraphWindow.current.mapMagic != null && EditorUtility.DisplayDialog("Purge Output", "Would you like to clear generated results on the terrain as well?", "Clear", "Keep")) { foreach (Generator gen in selected) { if (gen is IOutputGenerator outGen) { GraphWindow.current.mapMagic.Purge(outGen); } } } GraphWindow.RecordCompleteUndo(); foreach (Generator sgen in selected) { if (graph.ContainsGenerator(sgen)) { graph.Remove(sgen); } } GraphWindow.current.Focus(); GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static void RemoveGenerator(this Graph graph, Generator gen) { if (gen is IOutputGenerator && GraphWindow.current.mapMagic != null) { if (EditorUtility.DisplayDialog("Purge Output", "Would you like to clear generated results on the terrain as well?", "Clear", "Keep")) { GraphWindow.current.mapMagic.Purge((IOutputGenerator)gen); } } GraphWindow.RecordCompleteUndo(); if (graph.ContainsGenerator(gen)) { graph.ThroughLink(gen); //trying to maintain connections between generators graph.Remove(gen); } GraphWindow.current.Focus(); GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
private void DragDrawAddRemove () { //if dragging generator if (DragDrop.IsDragging() && !DragDrop.IsStarted() && DragDrop.obj is Cell && UI.current.cellObjs.TryGetObject((Cell)DragDrop.obj, "Generator", out Generator draggedGen) ) { if (Cell.current.Contains(UI.current.mousePos)) Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemoveActive")); else Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemove")); } //if released generator on remove icon else if (DragDrop.IsReleased() && DragDrop.releasedObj is Cell && UI.current.cellObjs.TryGetObject((Cell)DragDrop.releasedObj, "Generator", out Generator releasedGen) && Cell.current.Contains(UI.current.mousePos)) { GraphEditorActions.RemoveGenerator(graph, releasedGen, selected); GraphWindow.RefreshMapMagic(); } //if not dragging generator else { addDragTo = addDragDefault; if (focusedWindow == this) disableAddRemoveButton = false; //re-enabling when window is focused again after popup if (DragDrop.TryDrag(addDragId, UI.current.scrollZoom.ToScreen(UI.current.mousePos))) { addDragTo += DragDrop.totalDelta; Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd")); //if dragging near link, output or node //Vector2 mousePos = graphUI.mousePos; Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center object clickedObj = RightClick.ClickedOn(graphUI, mousePos); if (clickedObj != null && !(clickedObj is Group)) { Color linkColor = GeneratorDraw.GetLinkColor(Generator.GetGenericType(clickedObj.GetType())); Texture2D frameTex = UI.current.textures.GetColorizedTexture("MapMagic/Icons/NodeAddRemoveFrame", linkColor); Draw.Texture(frameTex); } } else if (!disableAddRemoveButton) //don't show this button if right-click items are shown Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd")); //using Texture since Icon is scaled with scrollzoom if (DragDrop.TryRelease(addDragId)) { disableAddRemoveButton = true; //Vector2 mousePos = graphUI.mousePos; Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center RightClick.ClickedNear (graphUI, mousePos, out Group clickedGroup, out Generator clickedGen, out IOutlet<object> clickedLayer, out IInlet<object> clickedLink, out IInlet<object> clickedInlet, out IOutlet<object> clickedOutlet, out FieldInfo clickedField); if (clickedOutlet != null) CreateRightClick.DrawAppendItems(mousePos, graph, clickedOutlet); else if (clickedLayer != null) CreateRightClick.DrawAppendItems(mousePos, graph, clickedLayer); else if (clickedLink != null) CreateRightClick.DrawInsertItems(mousePos, graph, clickedLink); else CreateRightClick.DrawCreateItems(mousePos, graph); } DragDrop.TryStart(addDragId, new Rect(addDragDefault, new Vector2(addDragSize-4,addDragSize-4))); } }
public static Item GeneratorItems(Vector2 mousePos, Generator gen, Graph graph, int priority = 3) { Item genItems = new Item("Generator"); genItems.onDraw = RightClick.DrawItem; genItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Generator"); genItems.color = RightClick.defaultColor; genItems.subItems = new List <Item>(); genItems.priority = priority; genItems.disabled = gen == null && copiedGenerators == null; { //enable/disable string caption = (gen == null || gen.enabled) ? "Disable" : "Enable"; Item item = new Item(caption, onDraw: RightClick.DrawItem, priority: 11); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Eye"); item.color = RightClick.defaultColor; item.disabled = gen == null; item.onClick = () => { gen.enabled = !gen.enabled; GraphWindow.RefreshMapMagic(gen); GraphWindow.current.Focus(); GraphWindow.current.Repaint(); }; genItems.subItems.Add(item); } //genItems.subItems.Add( new Item("Export", onDraw:RightClick.DrawItem, priority:10) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"), color = Color.gray } ); //genItems.subItems.Add( new Item("Import", onDraw:RightClick.DrawItem, priority:9) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Import"), color = Color.gray } ); { //duplicate Item item = new Item("Duplicate", onDraw: RightClick.DrawItem, priority: 8); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Duplicate"); item.color = RightClick.defaultColor; item.disabled = gen == null; item.onClick = () => GraphEditorActions.DuplicateGenerator(graph, gen, ref GraphWindow.current.selected); genItems.subItems.Add(item); } { //copy Item item = new Item("Copy", onDraw: RightClick.DrawItem, priority: 8); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"); item.color = RightClick.defaultColor; item.disabled = !(gen != null || (GraphWindow.current.selected != null && GraphWindow.current.selected.Count != 0)); item.onClick = () => { HashSet <Generator> gens; if (GraphWindow.current.selected != null && GraphWindow.current.selected.Count != 0) { gens = GraphWindow.current.selected; } else { gens = new HashSet <Generator>(); gens.Add(gen); } copiedGenerators = graph.Export(gens); }; item.closeOnClick = true; genItems.subItems.Add(item); } { //paste Item item = new Item("Paste", onDraw: RightClick.DrawItem, priority: 7); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"); item.color = RightClick.defaultColor; item.disabled = copiedGenerators == null; item.onClick = () => { Generator[] imported = graph.Import(copiedGenerators); Graph.Reposition(imported, mousePos); }; item.closeOnClick = true; genItems.subItems.Add(item); } { //update Item item = new Item("Update", onDraw: RightClick.DrawItem, priority: 7); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Update"); item.color = RightClick.defaultColor; item.closeOnClick = true; item.disabled = gen == null; } { //reset Item item = new Item("Reset", onDraw: RightClick.DrawItem, priority: 4); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Reset"); item.color = RightClick.defaultColor; item.closeOnClick = true; item.disabled = gen == null; } { //remove Item item = new Item("Remove", onDraw: RightClick.DrawItem, priority: 5); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Remove"); item.color = RightClick.defaultColor; item.disabled = gen == null; item.onClick = () => GraphEditorActions.RemoveGenerator(graph, gen, GraphWindow.current.selected); item.closeOnClick = true; genItems.subItems.Add(item); } { //unlink Item item = new Item("Unlink", onDraw: RightClick.DrawItem, priority: 6); item.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Unlink"); item.color = RightClick.defaultColor; item.disabled = gen == null; item.onClick = () => { graph.UnlinkGenerator(gen); GraphWindow.RefreshMapMagic(gen); //undo }; item.closeOnClick = true; genItems.subItems.Add(item); } if (gen != null) { //id Item item = new Item($"Id: {gen.id}", onDraw: RightClick.DrawItem, priority: 3); item.color = RightClick.defaultColor; item.onClick = () => EditorGUIUtility.systemCopyBuffer = gen.id.ToString(); item.closeOnClick = true; genItems.subItems.Add(item); } #if MM_DEBUG if (gen != null) { //position Item item = new Item($"Pos: {gen.guiPosition}", onDraw: RightClick.DrawItem, priority: 2); item.color = RightClick.defaultColor; item.onClick = () => EditorGUIUtility.systemCopyBuffer = gen.guiPosition.ToString(); item.closeOnClick = true; genItems.subItems.Add(item); } #endif return(genItems); }
public static void ShowEditor () { MapMagicObject mm = FindObjectOfType<MapMagicObject>(); Graph gens = mm!=null? mm.graph : null; GraphWindow.Show(mm?.graph); }
private void OnGUI() { current = this; mapMagic = FindRelatedMapMagic(graph); if (graph==null || graph.generators==null) return; if (mapMagic==null) Den.Tools.Tasks.CoroutineManager.Update(); //updating coroutine if no mm assigned (to display brush previews) //fps timer #if MM_DEBUG long frameStart = System.Diagnostics.Stopwatch.GetTimestamp(); #endif //undo if (graphUI.undo == null) { graphUI.undo = new Den.Tools.GUI.Undo() { undoObject = graph , undoName = "MapMagic Graph Change" }; graphUI.undo.undoAction = GraphWindow.RefreshMapMagic; } graphUI.undo.undoObject = graph; //mini with selection if (selected.Count == 1 && IsMini) { Generator selectedGen = selected.Any(); Rect selectedRect = new Rect(PlaceByAnchor(graph.guiMiniAnchor,graph.guiMiniPos,selectedGen.guiSize), selectedGen.guiSize); selectedRect.position = selectedRect.position+new Vector2(0,toolbarSize); //skipping drawing graph if clicked somewhere in generator bool clickedToGen = Event.current.isMouse && selectedRect.Contains(Event.current.mousePosition); using (new UnityEngine.GUI.ClipScope(new Rect(0, toolbarSize, Screen.width, Screen.height-toolbarSize))) { if (clickedToGen) EditorGUI.BeginDisabledGroup(true); //disabling other controls when clicking selected mini gen graphUI.Draw(DrawGraph, inInspector:false); if (clickedToGen) EditorGUI.EndDisabledGroup(); miniSelectedUI.Draw(DrawMiniSelected, inInspector:false); } //using (new UnityEngine.GUI.ClipScope(new Rect(20, 20+toolbarSize, selectedGen.guiSize.x, selectedGen.guiSize.y))) // miniSelectedUI.Draw(DrawMiniSelected, inInspector:false); } //standard graph/mini else using (new UnityEngine.GUI.ClipScope(new Rect(0, toolbarSize, Screen.width, Screen.height-toolbarSize))) graphUI.Draw(DrawGraph, inInspector:false, customRect:new Rect(0, toolbarSize, Screen.width, Screen.height-toolbarSize)); //toolbar using (new UnityEngine.GUI.ClipScope(new Rect(0,0, Screen.width, toolbarSize))) toolbarUI.Draw(DrawToolbar, inInspector:false); //storing graph pivot to focus it on load Vector3 scrollZoom = graphUI.scrollZoom.GetWindowCenter(position.size); scrollZoom.z = graphUI.scrollZoom.zoom; if (graphsScrollZooms.ContainsKey(graph)) graphsScrollZooms[graph] = scrollZoom; else graphsScrollZooms.Add(graph, scrollZoom); //switching to main on field drag release //mapMagic.guiDraggingField = DragDrop.obj!=null && (DragDrop.group=="DragField" || DragDrop.group=="DragCurve" || DragDrop.group=="DragLevels"); if (mapMagic != null) { bool newForceDrafts = DragDrop.obj!=null && (DragDrop.group=="DragField" || DragDrop.group=="DragCurve" || DragDrop.group=="DragLevels"); if (!newForceDrafts && mapMagic.guiDraggingField) { mapMagic.guiDraggingField = newForceDrafts; mapMagic.SwitchLods(); } mapMagic.guiDraggingField = newForceDrafts; } //showing fps #if MM_DEBUG if (graph.debugGraphFps) { long frameEnd = System.Diagnostics.Stopwatch.GetTimestamp(); float timeDelta = 1f * (frameEnd-frameStart) / System.Diagnostics.Stopwatch.Frequency; float fps = 1f / timeDelta; EditorGUI.LabelField(new Rect(10, toolbarSize+10, 70, 18), "FPS:" + fps.ToString("0.0")); } #endif //moving scene view #if MM_DEBUG if (graph.drawInSceneView) MoveSceneView(); #endif }
public void DrawGUI() { using (Cell.LinePx(32)) Draw.Label("WARNING: Keeping this asset selected in \nInspector can slow down editor GUI performance.", style: UI.current.styles.helpBox); Cell.EmptyLinePx(5); using (Cell.LinePx(24)) if (Draw.Button("Open Editor")) { GraphWindow.Show(graph); } using (Cell.LinePx(20)) if (Draw.Button("Open in New Tab")) { GraphWindow.ShowInNewTab(graph); } //seed Cell.EmptyLinePx(5); using (Cell.LineStd) { int newSeed = Draw.Field(graph.random.Seed, "Seed"); // if (newSeed != graph.random.Seed) { graph.random.Seed = newSeed; //Graph.OnChange.Raise(graph); } } using (Cell.LineStd) Draw.DualLabel("Nodes", graph.generators.Length.ToString()); using (Cell.LineStd) Draw.DualLabel("MapMagic ver", graph.serializedVersion.ToString()); Cell.EmptyLinePx(5); //global values /*using (Cell.LineStd) * using (new Draw.FoldoutGroup (ref showShared, "Global Values")) * if (showShared) * { * List<string> changedNames = new List<string>(); * List<object> changedVals = new List<object>(); * * (Type type, string name)[] typeNames = graph.sharedVals.GetTypeNames(); * for (int i=0; i<typeNames.Length; i++) * using (Cell.LineStd) GeneratorDraw.DrawGlobalVar(typeNames[i].type, typeNames[i].name); * * if (Cell.current.valChanged) * { * GraphWindow.current.mapMagic.ClearAllNodes(); * GraphWindow.current.mapMagic.StartGenerate(); * } * }*/ //exposed values using (Cell.LineStd) using (new Draw.FoldoutGroup(ref graph.guiShowExposed, "Overridden Variables")) if (graph.guiShowExposed) { using (Cell.LinePx(0)) OverrideInspector.DrawLayeredOverride(graph); } //dependent graphs using (Cell.LineStd) using (new Draw.FoldoutGroup(ref graph.guiShowDependent, "Dependent Graphs")) if (graph.guiShowDependent) { using (Cell.LinePx(0)) DrawDependentGraphs(graph); } //debug #if MM_DEBUG using (Cell.LineStd) using (new Draw.FoldoutGroup(ref graph.guiShowDebug, "Debug")) if (graph.guiShowDebug) { using (Cell.LineStd) Draw.Toggle(ref graph.debugGenerate, "Generate"); using (Cell.LineStd) Draw.Toggle(ref graph.debugGenInfo, "Info"); using (Cell.LineStd) Draw.Toggle(ref graph.debugGraphBackground, "Background"); using (Cell.LineStd) Draw.Field(ref graph.debugGraphBackColor, "Back Color"); using (Cell.LineStd) Draw.Toggle(ref graph.debugGraphFps, "Graph FPS"); using (Cell.LineStd) Draw.Toggle(ref graph.drawInSceneView, "Draw In Scene View"); } #endif }
private void DragDrawAddRemove () { int origButtonSize = 34; int origButtonOffset = 20; Vector2 buttonPos = new Vector2( UI.current.editorWindow.position.width - (origButtonSize + origButtonOffset)*UI.current.DpiScaleFactor, 20*UI.current.DpiScaleFactor); Vector2 buttonSize = new Vector2(origButtonSize,origButtonSize) * UI.current.DpiScaleFactor; using (Cell.Custom(buttonPos,buttonSize)) //later button pos could be overriden if dragging it { Cell.current.MakeStatic(); //if dragging generator if (DragDrop.IsDragging() && !DragDrop.IsStarted() && DragDrop.obj is Cell && UI.current.cellObjs.TryGetObject((Cell)DragDrop.obj, "Generator", out Generator draggedGen) ) { if (Cell.current.Contains(UI.current.mousePos)) Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemoveActive")); else Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeRemove")); } //if released generator on remove icon else if (DragDrop.IsReleased() && DragDrop.releasedObj is Cell && UI.current.cellObjs.TryGetObject((Cell)DragDrop.releasedObj, "Generator", out Generator releasedGen) && Cell.current.Contains(UI.current.mousePos)) { GraphEditorActions.RemoveGenerator(graph, releasedGen, selected); GraphWindow.RefreshMapMagic(); } //if not dragging generator else { if (focusedWindow==this) drawAddRemoveButton = true; //re-enabling when window is focused again after popup bool drawFrame = false; Color frameColor = new Color(); //dragging button if (DragDrop.TryDrag(addDragId, UI.current.mousePos)) { Cell.current.pixelOffset += DragDrop.totalDelta; //offsetting cell position with the mouse Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd")); //if dragging near link, output or node Vector2 mousePos = graphUI.mousePos; //Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center object clickedObj = RightClick.ClickedOn(graphUI, mousePos); if (clickedObj != null && !(clickedObj is Group)) { drawFrame = true; frameColor = GeneratorDraw.GetLinkColor(Generator.GetGenericType(clickedObj.GetType())); } } //releasing button if (DragDrop.TryRelease(addDragId)) { drawAddRemoveButton = false; Vector2 mousePos = graphUI.mousePos; //Vector2 mousePos = graphUI.scrollZoom.ToInternal(addDragTo + new Vector2(addDragSize/2,addDragSize/2)); //add button center RightClick.ClickedNear (graphUI, mousePos, out Group clickedGroup, out Generator clickedGen, out IOutlet<object> clickedLayer, out IInlet<object> clickedLink, out IInlet<object> clickedInlet, out IOutlet<object> clickedOutlet, out FieldInfo clickedField); if (clickedOutlet != null) CreateRightClick.DrawAppendItems(mousePos, graph, clickedOutlet); else if (clickedLayer != null) CreateRightClick.DrawAppendItems(mousePos, graph, clickedLayer); else if (clickedLink != null) CreateRightClick.DrawInsertItems(mousePos, graph, clickedLink); else CreateRightClick.DrawCreateItems(mousePos, graph); } //starting button drag DragDrop.TryStart(addDragId, UI.current.mousePos, Cell.current.InternalRect); //drawing button if (drawAddRemoveButton) //don't show this button if right-click items are shown Draw.Texture(UI.current.textures.GetTexture("MapMagic/Icons/NodeAdd")); //using Texture since Icon is scaled with scrollzoom if (drawFrame) { Texture2D frameTex = UI.current.textures.GetColorizedTexture("MapMagic/Icons/NodeAddRemoveFrame", frameColor); Draw.Texture(frameTex); } } } }
private void DrawToolbar () { //using (Timer.Start("DrawToolbar")) using (Cell.LinePx(toolbarSize)) { //Graph graph = CurrentGraph; //Graph rootGraph = mapMagic.graph; //if (mapMagic != null && mapMagic.graph!=graph && mapMagic.graph!=rootGraph) mapMagic = null; UI.current.styles.Resize(0.9f); //shrinking all font sizes Draw.Element(UI.current.styles.toolbar); //undefined graph if (graph==null) { using (Cell.RowPx(200)) Draw.Label("No graph selected to display. Select:"); using (Cell.RowPx(100)) Draw.ObjectField(ref graph); return; } //if graph loaded corrupted if (graph.generators==null) { using (Cell.RowPx(300)) Draw.Label("Graph is null. Check the console for the error on load."); using (Cell.RowPx(100)) if (Draw.Button("Reload", style:UI.current.styles.toolbarButton)) graph.OnAfterDeserialize(); using (Cell.RowPx(100)) { if (Draw.Button("Reset", style:UI.current.styles.toolbarButton)) graph.generators = new Generator[0]; } Cell.EmptyRowRel(1); return; } //root graph Graph rootGraph = null; if (parentGraphs != null && parentGraphs.Count != 0) rootGraph = parentGraphs[0]; //this has nothing to do with currently assigned mm graph - we can view subGraphs with no mm in scene at all if (rootGraph != null) { Vector2 rootBtnSize = UnityEngine.GUI.skin.label.CalcSize( new GUIContent(rootGraph.name) ); using (Cell.RowPx(rootBtnSize.x)) { //Draw.Button(graph.name, style:UI.current.styles.toolbarButton, cell:rootBtnCell); Draw.Label(rootGraph.name); if (Draw.Button("", visible:false)) EditorGUIUtility.PingObject(rootGraph); } using (Cell.RowPx(20)) Draw.Label(">>"); } //this graph Vector2 graphBtnSize = UnityEngine.GUI.skin.label.CalcSize( new GUIContent(graph.name) ); using (Cell.RowPx(graphBtnSize.x)) { Draw.Label(graph.name); if (Draw.Button("", visible:false)) EditorGUIUtility.PingObject(graph); } //up-level and tree using (Cell.RowPx(20)) { if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/FolderTree"), iconScale:0.5f, visible:false)) GraphTreePopup.DrawGraphTree(rootGraph!=null ? rootGraph : graph); } using (Cell.RowPx(20)) { if (parentGraphs != null && parentGraphs.Count != 0 && Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/FolderUp"), iconScale:0.5f, visible:false)) { graph = parentGraphs[parentGraphs.Count-1]; parentGraphs.RemoveAt(parentGraphs.Count-1); ScrollZoomOnOpen(); Repaint(); } } Cell.EmptyRowRel(1); //switching to right corner //seed Cell.EmptyRowPx(5); using (Cell.RowPx(1)) Draw.ToolbarSeparator(); using (Cell.RowPx(90)) // using (Cell.LinePx(toolbarSize-1)) //-1 just to place it nicely { #if UNITY_2019_1_OR_NEWER int newSeed; using (Cell.RowRel(0.4f)) Draw.Label("Seed:"); using (Cell.RowRel(0.6f)) using (Cell.Padded(1)) newSeed = (int)Draw.Field(graph.random.Seed, style:UI.current.styles.toolbarField); #else Cell.current.fieldWidth = 0.6f; int newSeed = Draw.Field(graph.random.Seed, "Seed:"); #endif if (newSeed != graph.random.Seed) { GraphWindow.RecordCompleteUndo(); graph.random.Seed = newSeed; GraphWindow.RefreshMapMagic(); } } Cell.EmptyRowPx(2); //gauge using (Cell.RowPx(1)) Draw.ToolbarSeparator(); using (Cell.RowPx(200)) using (Cell.LinePx(toolbarSize-1)) //-1 to leave underscore under gauge { if (mapMagic != null) { float progress = mapMagic.GetProgress(); if (progress < 1 && progress != 0) { Texture2D backgroundTex = UI.current.textures.GetTexture("DPUI/ProgressBar/BackgroundBorderless"); mapMagic.GetProgress(); Draw.Texture(backgroundTex); Texture2D fillTex = UI.current.textures.GetBlankTexture(StylesCache.isPro ? Color.grey : Color.white); Color color = StylesCache.isPro ? new Color(0.24f, 0.37f, 0.58f) : new Color(0.44f, 0.574f, 0.773f); Draw.ProgressBarGauge(progress, fillTex, color); } using (Cell.RowPx(20)) if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/RefreshAll"), iconScale:0.5f, visible:false)) { //graphUI.undo.Record(completeUndo:true); //won't record changed terrain data foreach (Terrain terrain in mapMagic.tiles.AllActiveTerrains()) UnityEditor.Undo.RegisterFullObjectHierarchyUndo(terrain.terrainData, "RefreshAll"); EditorUtility.SetDirty(mapMagic); GraphWindow.current.mapMagic.ClearAll(); GraphWindow.current.mapMagic.StartGenerate(); } using (Cell.RowPx(20)) if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/Refresh"), iconScale:0.5f, visible:false)) { GraphWindow.current.mapMagic.StartGenerate(); } if (progress > 0.9999f) { Cell.EmptyRow(); using (Cell.RowPx(40)) Draw.Label("Ready"); } //else Repaint(); //doing it in OnInspectorUpdate } else Draw.Label("Not Assigned to MapMagic Object"); } using (Cell.RowPx(1)) Draw.ToolbarSeparator(); //focus using (Cell.RowPx(20)) if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/FocusSmall"), iconScale:0.5f, visible:false)) { graphUI.scrollZoom.FocusWindowOn(GetNodesCenter(graph), position.size); } using (Cell.RowPx(20)) { if (graphUI.scrollZoom.zoom < 0.999f) { if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/ZoomSmallPlus"), iconScale:0.5f, visible:false)) graphUI.scrollZoom.Zoom(1f, position.size/2); } else { if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/ZoomSmallMinus"), iconScale:0.5f, visible:false)) graphUI.scrollZoom.Zoom(0.5f, position.size/2); } } } }
public static Item AppendItems(Vector2 mousePos, Graph graph, IOutlet <object> clickedOutlet, int priority = 4) /// Item set appeared on node or outlet click { Item addItems = null; if (clickedOutlet != null) { Type genericLinkType = Generator.GetGenericType(clickedOutlet); if (genericLinkType == null) { throw new Exception("Could not find category " + clickedOutlet.GetType().ToString()); } Item createItems = CreateItems(mousePos, graph); addItems = createItems.Find(GetCategoryByType(genericLinkType)); } if (addItems != null && addItems.subItems != null) { Item initial = addItems.Find("Initial"); if (initial != null) { initial.disabled = true; } //adding link to all create actions foreach (Item item in addItems.All(true)) { if (item.onClick != null) { Action baseOnClick = item.onClick; item.onClick = () => { baseOnClick(); Generator createdGen = graph.generators[graph.generators.Length - 1]; //the last on is the one that's just created. Hacky Vector2 pos = clickedOutlet.Gen.guiPosition + new Vector2(200, 0); GeneratorDraw.FindPlace(ref pos, new Vector2(100, 200), GraphWindow.current.graph); createdGen.guiPosition = pos; graph.AutoLink(createdGen, clickedOutlet); GraphWindow.RefreshMapMagic(createdGen); }; } } } else { addItems = new Item("Add"); addItems.onDraw = RightClick.DrawItem; addItems.disabled = true; } addItems.name = "Add (Append)"; addItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Create"); addItems.color = Color.gray; addItems.priority = priority; return(addItems); }
public static Item GeneratorItems(Generator gen, Graph graph, int priority = 3) { Item genItems = new Item("Generator"); genItems.onDraw = RightClick.DrawItem; genItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Generator"); genItems.color = Color.gray; genItems.subItems = new List <Item>(); genItems.priority = priority; genItems.disabled = gen == null; Item enableItem = new Item(gen == null || gen.enabled ? "Disable" : "Enable", onDraw: RightClick.DrawItem, priority: 11) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Eye"), color = Color.gray }; enableItem.onClick = () => { gen.enabled = !gen.enabled; GraphWindow.RefreshMapMagic(gen); }; genItems.subItems.Add(enableItem); //genItems.subItems.Add( new Item("Export", onDraw:RightClick.DrawItem, priority:10) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"), color = Color.gray } ); //genItems.subItems.Add( new Item("Import", onDraw:RightClick.DrawItem, priority:9) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Import"), color = Color.gray } ); Item duplicateItem = new Item("Duplicate", onDraw: RightClick.DrawItem, priority: 8); duplicateItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Duplicate"); duplicateItem.color = Color.gray; duplicateItem.onClick = () => GraphEditorActions.DuplicateGenerator(graph, gen, ref GraphWindow.current.selected); genItems.subItems.Add(duplicateItem); genItems.subItems.Add(new Item("Update", onDraw: RightClick.DrawItem, priority: 7) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Update"), color = Color.gray }); genItems.subItems.Add(new Item("Reset", onDraw: RightClick.DrawItem, priority: 4) { icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Reset"), color = Color.gray }); /*Item testItem = new Item("Create Test", onDraw:RightClick.DrawItem, priority:5); * testItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Export"); * testItem.color = Color.gray; * testItem.onClick = ()=> GeneratorsTester.CreateTestCase(gen, GraphWindow.current.mapMagic.PreviewData); * genItems.subItems.Add(testItem);*/ Item removeItem = new Item("Remove", onDraw: RightClick.DrawItem, priority: 5); removeItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Remove"); removeItem.color = Color.gray; removeItem.onClick = () => GraphEditorActions.RemoveGenerator(graph, gen, GraphWindow.current.selected); genItems.subItems.Add(removeItem); Item unlinkItem = new Item("Unlink", onDraw: RightClick.DrawItem, priority: 6); unlinkItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Unlink"); unlinkItem.color = Color.gray; unlinkItem.onClick = () => { graph.UnlinkGenerator(gen); GraphWindow.RefreshMapMagic(gen); //undo }; genItems.subItems.Add(unlinkItem); return(genItems); }
public void DrawGUI() { using (Cell.LinePx(32)) Draw.Label("WARNING: Keeping this asset selected in \nInspector can slow down editor GUI performance.", style: UI.current.styles.helpBox); Cell.EmptyLinePx(5); using (Cell.LinePx(24)) if (Draw.Button("Open Editor")) { GraphWindow.Show(graph); } using (Cell.LinePx(20)) if (Draw.Button("Open in New Tab")) { GraphWindow.ShowInNewTab(graph); } //seed Cell.EmptyLinePx(5); using (Cell.LineStd) { int newSeed = Draw.Field(graph.random.Seed, "Seed"); // if (newSeed != graph.random.Seed) { graph.random.Seed = newSeed; //Graph.OnChange.Raise(graph); } } using (Cell.LineStd) Draw.DualLabel("Nodes", graph.generators.Length.ToString()); using (Cell.LineStd) Draw.DualLabel("MapMagic ver", graph.serializedVersion.ToString()); Cell.EmptyLinePx(5); //global values /*using (Cell.LineStd) * using (new Draw.FoldoutGroup (ref showShared, "Global Values")) * if (showShared) * { * List<string> changedNames = new List<string>(); * List<object> changedVals = new List<object>(); * * (Type type, string name)[] typeNames = graph.sharedVals.GetTypeNames(); * for (int i=0; i<typeNames.Length; i++) * using (Cell.LineStd) GeneratorDraw.DrawGlobalVar(typeNames[i].type, typeNames[i].name); * * if (Cell.current.valChanged) * { * GraphWindow.current.mapMagic.ClearAllNodes(); * GraphWindow.current.mapMagic.StartGenerate(); * } * }*/ //exposed values using (Cell.LineStd) using (new Draw.FoldoutGroup(ref showExposed, "Exposed Values")) if (showExposed) { graph.exposed.ClearObsoleteEntries(graph); if (graph.exposed.entries != null) { for (int e = 0; e < graph.exposed.entries.Length; e++) { Exposed.Entry entry = graph.exposed.entries[e]; IExposedGuid gen = graph.FindGenByGuid(entry.guid); FieldInfo field = gen.GetType().GetField(entry.fieldName); using (Cell.LineStd) { if (field == null) { Draw.DualLabel(entry.guiName, "unknown"); } else { Draw.ClassField( field: field, type: entry.type, obj: gen, name: entry.guiName); } } if (Cell.current.valChanged) { GraphWindow.RefreshMapMagic(); } } } } //dependent graphs using (Cell.LineStd) using (new Draw.FoldoutGroup(ref showDependent, "Dependent Graphs")) if (showDependent) { using (Cell.LinePx(0)) DrawDependentGraphs(graph); } }