/// <summary> /// Adds or removes a module from the selection /// </summary> public void MultiSelectModule(CGModule mod) { if (mod == null) return; if (SelectedModules.Contains(mod)) SelectedModules.Remove(mod); else SelectedModules.Add(mod); }
public void ViewPortRegisterWindow(CGModule module) { Rect winRect = module.Properties.Dimensions; EnlargeCanvasFor(winRect); if (!IsMouseOverModule && EV.type != EventType.Layout) { IsMouseOverModule = winRect.Contains(EV.mousePosition); MouseOverModule = (IsMouseOverModule) ? module:null; } }
public static void DestroyResource(CGModule module, string resName, Component obj, string context, bool kill) { if (Loader.Count == 0) getLoaders(); if (Loader.ContainsKey(resName)) { var loader = Loader[resName]; loader.Destroy(module, obj, context, kill); } else Debug.LogError("CGResourceHandler: Missing Loader for resource '" + resName + "'"); }
/// <summary> /// Adds or removes a module from the selection /// </summary> public void MultiSelectModule(CGModule mod) { if (mod == null) { return; } if (SelectedModules.Contains(mod)) { SelectedModules.Remove(mod); } else { SelectedModules.Add(mod); } }
public static Component CreateResource(CGModule module, string resName, string context) { if (Loader.Count == 0) getLoaders(); if (Loader.ContainsKey(resName)) { var loader = Loader[resName]; return loader.Create(module,context); } else { Debug.LogError("CGResourceHandler: Missing Loader for resource '" + resName + "'"); return null; } }
internal CGModuleEditorBase GetModuleEditor(CGModule module) { CGModuleEditorBase ed; if (!ModuleEditors.TryGetValue(module, out ed)) { ed = Editor.CreateEditor(module) as CGModuleEditorBase; if (ed) { ed.Graph = this; ModuleEditors.Add(module, ed); } else { DTLog.LogError("[Curvy] Curvy Generator: Missing editor script for module '" + module.GetType().Name + "' !"); } } return(ed); }
void OnGUI() { mDoRepaint = false; if (!Generator) { return; } if (!Generator.IsInitialized) { Generator.Initialize(); } Modules = new List <CGModule>(Generator.Modules.ToArray()); mModuleCount = Modules.Count; // store count to be checked in window GUI if (!Application.isPlaying && !Generator.IsInitialized) { Repaint(); } DrawToolbar(); Canvas.SetClientRect(0, GUILayoutUtility.GetLastRect().yMax, 0, mStatusbarHeight); // Scrollable Canvas if (Canvas.Scroll.isAnimating) { GUI.BeginScrollView(Canvas.ClientRect, Canvas.Scroll.value, Canvas.CanvasRect); } else { Canvas.Scroll.value = GUI.BeginScrollView(Canvas.ClientRect, Canvas.Scroll.value, Canvas.CanvasRect); } // render background DTGUI.PushColor(Color.black.SkinAwareColor(true)); GUI.Box(Canvas.ViewPort, ""); DTGUI.PopColor(); #if CURVY_DEBUG GUILayout.BeginArea(Canvas.ViewPort); GUILayout.Label("Canvas ClientRect: " + Canvas.ClientRect); GUILayout.Label("Canvas Rect: " + Canvas.CanvasRect); GUILayout.Label("Canvas Scroll: " + Canvas.Scroll); GUILayout.Label("Canvas ViewPort: " + Canvas.ViewPort); GUILayout.Label("Mouse: " + EV.mousePosition); GUILayout.Label("IsWindowDrag: " + Canvas.IsWindowDrag); GUILayout.Label("IsSelectionDrag: " + Canvas.IsSelectionRectDrag); GUILayout.Label("IsLinkDrag: " + Canvas.IsLinkDrag); GUILayout.Label("IsCanvasDrag: " + Canvas.IsCanvasDrag); GUILayout.Label("IsModuleDrag: " + Canvas.IsModuleDrag); GUILayout.Label("MouseOverModule: " + Canvas.MouseOverModule); GUILayout.Label("MouseOverCanvas: " + Canvas.IsMouseOverCanvas); GUILayout.Label("SelectedLink: " + Sel.SelectedLink); GUILayout.Label("Selected Module: " + Sel.SelectedModule); GUILayout.EndArea(); #endif if (CurvyProject.Instance.CGShowHelp) { var r = new Rect(Canvas.ViewPort); r.x = r.width - 210; r.y = 10; r.width = 200; r.height = 190; GUILayout.BeginArea(r, GUI.skin.box); GUI.Label(new Rect(10, 5, 200, 20), "<i><b>General</b></i>", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 25, 50, 20), "<b>RMB</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 25, 150, 20), "Context Menu", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 40, 150, 40), "<b>MMB/\nSpace</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 40, 150, 20), "Drag Canvas", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 70, 150, 20), "<b>Alt</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 70, 150, 20), "Hold to snap to grid", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 85, 150, 20), "<b>Del</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 85, 150, 20), "Delete selection", DTStyles.HtmlLabel); GUI.Label(new Rect(10, 110, 200, 20), "<i><b>Add Modules</b></i>", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 130, 180, 40), "Hold <b>Ctrl</b> while releasing a\nlink to create & connect", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 160, 180, 40), "Drag & Drop splines to create\nPath module", DTStyles.HtmlLabel); GUILayout.EndArea(); } DrawLinks(); // Init and early catch some events Canvas.BeginGUI(); DrawModules(); Canvas.EndGUI(); // Draw Selection DTGUI.PushBackgroundColor(Color.white);//.SkinAwareColor()); foreach (var mod in Sel.SelectedModules) { GUI.Box(mod.Properties.Dimensions.ScaleBy(2), "", CurvyStyles.RoundRectangle); } DTGUI.PopBackgroundColor(); // Keep dragged Module in view and handle multiselection move if (Canvas.IsModuleDrag && !DTGUI.IsLayout) { Vector2 delta = EV.delta; deltaAccu += EV.delta; if (EV.alt) { delta = deltaAccu.Snap(CurvyProject.Instance.CGGraphSnapping); if (delta == deltaAccu) { delta = Vector2.zero; } } if (Sel.SelectedModules.Count > 1) { foreach (CGModule mod in Sel.SelectedModules) { mod.Properties.Dimensions.position += delta; } if (!EV.alt || delta != Vector2.zero) { deltaAccu = Vector2.zero; } } var m = (Canvas.MouseOverModule) ? Canvas.MouseOverModule : Sel.SelectedModule; if (m) { GUI.ScrollTowards(m.Properties.Dimensions, 0.8f); } } // Linking in progress? if (Canvas.IsLinkDrag) { var linkstyle = (Canvas.LinkDragFrom.OnRequestModule != null) ? CurvyStyles.RequestLineTexture : CurvyStyles.LineTexture; Handles.DrawBezier(Canvas.LinkDragFrom.Origin, EV.mousePosition, Canvas.LinkDragFrom.Origin + new Vector2(40, 0), EV.mousePosition + new Vector2(-40, 0), Color.white, linkstyle, 2); } GUI.EndScrollView(true); // Selection if (Canvas.IsSelectionRectDrag) { DrawSelectionRect(); } // Statusbar DrawStatusbar(); // IPE SyncIPE(); mDoRepaint = mDoRepaint || Canvas.IsCanvasDrag || Canvas.IsLinkDrag || Canvas.IsSelectionRectDrag || EV.type == EventType.MouseMove || mShowDebug.isAnimating || Canvas.Scroll.isAnimating; // Disable Title edit mode? if (editTitleModule != null) { if ((EV.isKey && (EV.keyCode == KeyCode.Escape || EV.keyCode == KeyCode.Return)) || Sel.SelectedModule != editTitleModule ) { editTitleModule = null; //GUI.FocusControl(""); mDoRepaint = true; } } if (mDoRepaint) { Repaint(); } }
void OnModuleWindowCB(int id) { // something happened in the meantime? if (id >= Modules.Count || mModuleCount!=Modules.Count) return; CGModule mod = Modules[id]; //if (LMB && Sel.SelectedModules.Count<=1) if (EV.type==EventType.MouseUp && !Sel.SelectedModules.Contains(mod)) Sel.Select(Modules[id]); Rect winRect = mod.Properties.Dimensions; // Draw Title Buttons // Enabled EditorGUI.BeginChangeCheck(); mod.Active=GUI.Toggle(new Rect(2, 2, 16, 16),mod.Active,""); if (EditorGUI.EndChangeCheck()) EditorUtility.SetDirty(Generator); //Edit Title & Color if (editTitleModule == mod) { GUI.SetNextControlName("editTitle" + id); mod.ModuleName = GUI.TextField(new Rect(30, 5, winRect.width - 120, 16), mod.ModuleName); mod.Properties.BackgroundColor = EditorGUI.ColorField(new Rect(winRect.width-70,5,32,16), mod.Properties.BackgroundColor); } if (GUI.Button (new Rect (winRect.width - 32, 6, 16, 16), new GUIContent (CurvyStyles.EditTexture, "Rename"), CurvyStyles.BorderlessButton)) { editTitleModule = mod; Sel.Select(mod); EditorGUI.FocusTextInControl("editTitle" + id); } // Help if (GUI.Button (new Rect (winRect.width - 16, 6, 16, 16), new GUIContent (CurvyStyles.HelpTexture, "Help"), CurvyStyles.BorderlessButton)) { var url = DTUtility.GetHelpUrl(mod); if (!string.IsNullOrEmpty(url)) Application.OpenURL(url); } // Check errors if (mod.CircularReferenceError) EditorGUILayout.HelpBox("Circular Reference", MessageType.Error); // Draw Slots DTGUI.PushColor(mod.Properties.BackgroundColor.SkinAwareColor(true)); EditorGUILayout.BeginVertical(CurvyStyles.ModuleWindowSlotBackground); DTGUI.PopColor(); OnModuleWindowSlotGUI(mod); EditorGUILayout.EndVertical(); var ed = GetModuleEditor(mod); if (ed && ed.target != null) { if (EditorGUILayout.BeginFadeGroup(mShowDebug.faded)) ed.OnInspectorDebugGUIINTERNAL(Repaint); EditorGUILayout.EndFadeGroup(); // Draw Module Options mod.Properties.Expanded.valueChanged.RemoveListener(Repaint); mod.Properties.Expanded.valueChanged.AddListener(Repaint); if (!CurvyProject.Instance.CGAutoModuleDetails) mod.Properties.Expanded.target = GUILayout.Toggle (mod.Properties.Expanded.target, new GUIContent (mod.Properties.Expanded.target ? CurvyStyles.CollapseTexture : CurvyStyles.ExpandTexture, "Show Details"), EditorStyles.toolbarButton); // === Module Details === // Handle Auto-Folding if (DTGUI.IsLayout && CurvyProject.Instance.CGAutoModuleDetails) mod.Properties.Expanded.target = (mod == Sel.SelectedModule); if (EditorGUILayout.BeginFadeGroup(mod.Properties.Expanded.faded)) { EditorGUIUtility.labelWidth = (mod.Properties.LabelWidth); // Draw Inspectors using Modules Background color DTGUI.PushColor(ed.Target.Properties.BackgroundColor.SkinAwareColor(true)); EditorGUILayout.BeginVertical(CurvyStyles.ModuleWindowBackground); DTGUI.PopColor(); ed.RenderGUI(true); if (ed.NeedRepaint) mDoRepaint = true; GUILayout.Space(2); EditorGUILayout.EndVertical(); } EditorGUILayout.EndFadeGroup(); } // Make it dragable GUI.DragWindow(new Rect(0, 0, winRect.width, CurvyStyles.ModuleWindowTitleHeight)); }
public Component Create(CGModule module, string context) { var spl = CurvySpline.Create(); spl.transform.position = Vector3.zero; spl.Closed = true; spl.Add(new Vector3(0, 0, 0), new Vector3(5, 0, 10), new Vector3(-5, 0, 10)); return spl; }
public void Destroy(CGModule module, Component obj, string context, bool kill) { if (obj != null) { if (kill) { if (Application.isPlaying) GameObject.Destroy(obj.gameObject); else GameObject.DestroyImmediate(obj.gameObject); } else { module.Generator.PoolManager.GetPrefabPool(context).Push(obj.gameObject); } } }
void OnModuleWindowSlotGUI(CGModule module) { int i = 0; float h = 18; while (module.Input.Count > i || module.Output.Count > i) { float y = CurvyStyles.ModuleWindowTitleHeight + h * i; GUILayout.BeginHorizontal(); if (module.Input.Count > i) { CGModuleInputSlot slot = module.Input[i]; Color slotColor=getTypeColor(slot.Info.DataTypes); if (Canvas.IsLinkDrag && !slot.IsValidTarget(Canvas.LinkDragFrom)) slotColor = new Color(0.2f, 0.2f, 0.2f).SkinAwareColor(true); DTGUI.PushColor(slotColor); GUILayout.Box("<", CurvyStyles.Slot); DTGUI.PopColor(); string postfix = ""; if (slot.Info.Array) postfix = (slot.LastDataCountINTERNAL>0) ? "[" + slot.LastDataCountINTERNAL.ToString() + "]" : "[]"; GUILayout.Label(new GUIContent(ObjectNames.NicifyVariableName(slot.Info.Name)+postfix, slot.Info.Tooltip), CurvyStyles.GetSlotLabelStyle(slot)); slot.DropZone = new Rect(0, y, module.Properties.Dimensions.width / 2, h); slot.Origin = new Vector2(module.Properties.Dimensions.xMin, module.Properties.Dimensions.yMin + y + h / 2); // LinkDrag? if (Canvas.IsLinkDrag) { // If ending drag over dropzone, create static link if (EV.type == EventType.MouseUp && slot.DropZone.Contains(EV.mousePosition) && slot.IsValidTarget(Canvas.LinkDragFrom)) finishLink(slot); } // Clicking on Dropzone to pick existing link else if (LMB && slot.Count==1 && slot.DropZone.Contains(EV.mousePosition)) { var linkedOutSlot = slot.SourceSlot(); linkedOutSlot.UnlinkFrom(slot); EditorUtility.SetDirty(slot.Module); startLinkDrag(linkedOutSlot); GUIUtility.ExitGUI(); } } if (module.Output.Count > i) { CGModuleOutputSlot slot = module.Output[i]; string postfix = ""; if (slot.Info.Array) postfix = (slot.Data != null && slot.Data.Length>1) ? "[" + slot.Data.Length.ToString() + "]" : ""; GUILayout.Label(new GUIContent(ObjectNames.NicifyVariableName(slot.Info.Name)+postfix, slot.Info.Tooltip), CurvyStyles.GetSlotLabelStyle(slot)); DTGUI.PushColor(getTypeColor(slot.Info.DataTypes)); GUILayout.Box(">", CurvyStyles.Slot); DTGUI.PopColor(); // Debug /* if (Generator.ShowDebug) { GUI.enabled = slot.Data != null && slot.Data.Length>0; if (GUILayout.Button(new GUIContent(CurvyStyles.DebugTexture, "Show Dump"), CurvyStyles.SmallButton, GUILayout.Width(16), GUILayout.Height(16))) DTDebugWindow.Open(slot.Data[0].GetType().Name + ":", slot.Data[0].ToDumpString()); GUI.enabled = true; } */ slot.DropZone = new Rect(module.Properties.Dimensions.width / 2, y, module.Properties.Dimensions.width / 2, h); slot.Origin = new Vector2(module.Properties.Dimensions.xMax, module.Properties.Dimensions.yMin+y + h / 2); // Start Linking? if (LMB && !Canvas.IsSelectionRectDrag && slot.DropZone.Contains(EV.mousePosition)) { startLinkDrag(slot); } } GUILayout.EndHorizontal(); i++; } }
public void Destroy(CGModule module, Component obj, string context, bool kill) { if (obj != null) { if (kill) { if (Application.isPlaying) GameObject.Destroy(obj.gameObject); else GameObject.DestroyImmediate(obj.gameObject); } else { obj.StripComponents(typeof(CGMeshResource), typeof(MeshFilter), typeof(MeshRenderer)); module.Generator.PoolManager.GetComponentPool<CGMeshResource>().Push(obj); } } }
public Component Create(CGModule module, string context) { var go=module.Generator.PoolManager.GetPrefabPool(context).Pop(); return go.transform; }
void OnGUI() { mDoRepaint = false; if (!Generator) return; if (!Generator.IsInitialized) { Generator.Initialize(); } Modules = new List<CGModule>(Generator.Modules.ToArray()); mModuleCount = Modules.Count; // store count to be checked in window GUI if (!Application.isPlaying && !Generator.IsInitialized) Repaint(); DrawToolbar(); Canvas.SetClientRect(0, GUILayoutUtility.GetLastRect().yMax,0,mStatusbarHeight); // Scrollable Canvas if (Canvas.Scroll.isAnimating) GUI.BeginScrollView(Canvas.ClientRect, Canvas.Scroll.value, Canvas.CanvasRect); else Canvas.Scroll.value = GUI.BeginScrollView(Canvas.ClientRect, Canvas.Scroll.value,Canvas.CanvasRect); // render background DTGUI.PushColor(Color.black.SkinAwareColor(true)); GUI.Box(Canvas.ViewPort, ""); DTGUI.PopColor(); #if CURVY_DEBUG GUILayout.BeginArea(Canvas.ViewPort); GUILayout.Label("Canvas ClientRect: " + Canvas.ClientRect); GUILayout.Label("Canvas Rect: " + Canvas.CanvasRect); GUILayout.Label("Canvas Scroll: " + Canvas.Scroll); GUILayout.Label("Canvas ViewPort: " + Canvas.ViewPort); GUILayout.Label("Mouse: " + EV.mousePosition); GUILayout.Label("IsWindowDrag: " + Canvas.IsWindowDrag); GUILayout.Label("IsSelectionDrag: " + Canvas.IsSelectionRectDrag); GUILayout.Label("IsLinkDrag: " + Canvas.IsLinkDrag); GUILayout.Label("IsCanvasDrag: " + Canvas.IsCanvasDrag); GUILayout.Label("IsModuleDrag: " + Canvas.IsModuleDrag); GUILayout.Label("MouseOverModule: " + Canvas.MouseOverModule); GUILayout.Label("MouseOverCanvas: " + Canvas.IsMouseOverCanvas); GUILayout.Label("SelectedLink: " + Sel.SelectedLink); GUILayout.Label("Selected Module: " + Sel.SelectedModule); GUILayout.EndArea(); #endif if (CurvyProject.Instance.CGShowHelp) { var r = new Rect(Canvas.ViewPort); r.x = r.width - 210; r.y = 10; r.width = 200; r.height = 190; GUILayout.BeginArea(r,GUI.skin.box); GUI.Label(new Rect(10,5,200,20),"<i><b>General</b></i>", DTStyles.HtmlLabel); GUI.Label(new Rect(20,25,50,20),"<b>RMB</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70,25,150,20),"Context Menu", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 40, 150, 40), "<b>MMB/\nSpace</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 40, 150, 20), "Drag Canvas", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 70, 150, 20), "<b>Alt</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 70, 150, 20), "Hold to snap to grid", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 85, 150, 20), "<b>Del</b>", DTStyles.HtmlLabel); GUI.Label(new Rect(70, 85, 150, 20), "Delete selection", DTStyles.HtmlLabel); GUI.Label(new Rect(10,110,200,20),"<i><b>Add Modules</b></i>", DTStyles.HtmlLabel); GUI.Label(new Rect(20,130,180,40),"Hold <b>Ctrl</b> while releasing a\nlink to create & connect", DTStyles.HtmlLabel); GUI.Label(new Rect(20, 160, 180, 40), "Drag & Drop splines to create\nPath module", DTStyles.HtmlLabel); GUILayout.EndArea(); } DrawLinks(); // Init and early catch some events Canvas.BeginGUI(); DrawModules(); Canvas.EndGUI(); // Draw Selection DTGUI.PushBackgroundColor(Color.white);//.SkinAwareColor()); foreach (var mod in Sel.SelectedModules) GUI.Box(mod.Properties.Dimensions.ScaleBy(2), "", CurvyStyles.RoundRectangle); DTGUI.PopBackgroundColor(); // Keep dragged Module in view and handle multiselection move if (Canvas.IsModuleDrag && !DTGUI.IsLayout) { Vector2 delta=EV.delta; deltaAccu += EV.delta; if (EV.alt) { delta = deltaAccu.Snap(CurvyProject.Instance.CGGraphSnapping); if (delta == deltaAccu) delta = Vector2.zero; } if (Sel.SelectedModules.Count > 1) { foreach (CGModule mod in Sel.SelectedModules) { mod.Properties.Dimensions.position += delta; } if (!EV.alt || delta!=Vector2.zero) deltaAccu = Vector2.zero; } var m = (Canvas.MouseOverModule) ? Canvas.MouseOverModule : Sel.SelectedModule; if (m) GUI.ScrollTowards(m.Properties.Dimensions, 0.8f); } // Linking in progress? if (Canvas.IsLinkDrag) { var linkstyle = (Canvas.LinkDragFrom.OnRequestModule != null) ? CurvyStyles.RequestLineTexture : CurvyStyles.LineTexture; Handles.DrawBezier(Canvas.LinkDragFrom.Origin, EV.mousePosition, Canvas.LinkDragFrom.Origin + new Vector2(40, 0), EV.mousePosition + new Vector2(-40, 0), Color.white, linkstyle, 2); } GUI.EndScrollView(true); // Selection if (Canvas.IsSelectionRectDrag) DrawSelectionRect(); // Statusbar DrawStatusbar(); // IPE SyncIPE(); mDoRepaint=mDoRepaint || Canvas.IsCanvasDrag || Canvas.IsLinkDrag || Canvas.IsSelectionRectDrag || EV.type==EventType.MouseMove || mShowDebug.isAnimating || Canvas.Scroll.isAnimating; // Disable Title edit mode? if (editTitleModule != null) { if ((EV.isKey && (EV.keyCode == KeyCode.Escape || EV.keyCode == KeyCode.Return)) || Sel.SelectedModule != editTitleModule ) { editTitleModule = null; //GUI.FocusControl(""); mDoRepaint = true; } } if (mDoRepaint) Repaint(); }
public Component Create(CGModule module, string context) { var cmp=module.Generator.PoolManager.GetComponentPool<CGMeshResource>().Pop(); return cmp; }
void DrawModules() { CGModule curSel = Sel.SelectedModule; // Begin drawing Module Windows BeginWindows(); for (int i = 0; i < Modules.Count; i++) { var mod = Modules[i]; if (mod != null) { mod.Properties.Dimensions.width = Mathf.Max(mod.Properties.Dimensions.width, mod.Properties.MinWidth); mod.Properties.Dimensions.height = 0; // will be set by GUILayout.Window // Render title string title = mod.ModuleName; if (!mod.IsConfigured) { title = string.Format("<color={0}>{1}</color>", new Color(1, 0.2f, 0.2f).SkinAwareColor().ToHtml(), mod.ModuleName); } //"<color=#ff3333>" + mod.ModuleName + "</color>"; else if (mod is IOnRequestProcessing) { title = string.Format("<color={0}>{1}</color>", CurvyStyles.IOnRequestProcessingTitleColor.SkinAwareColor().ToHtml(), mod.ModuleName); } #if CURVY_DEBUG title = mod.UniqueID + ":" + title; #endif // the actual window Vector2 oldPos = mod.Properties.Dimensions.position; Rect newWindowRect = GUILayout.Window(i, mod.Properties.Dimensions, OnModuleWindowCB, title, CurvyStyles.ModuleWindow); if (!Application.isPlaying && oldPos != newWindowRect.position) #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 { EditorApplication.MarkSceneDirty(); } #else { UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); } #endif if (Sel.SelectedModules.Count > 1) // Multi-Module move in OnGUI() { mod.Properties.Dimensions = newWindowRect.SetPosition(oldPos); } else { if (EV.alt && Canvas.IsModuleDrag && Sel.SelectedModule == mod) { newWindowRect.position = newWindowRect.position.Snap(CurvyProject.Instance.CGGraphSnapping); } mod.Properties.Dimensions = newWindowRect; } // Debugging var lastUpdateDelta = (System.DateTime.Now - mod.DEBUG_LastUpdateTime).TotalMilliseconds; if (lastUpdateDelta < 1500) { float alpha = Mathf.SmoothStep(1, 0, (float)lastUpdateDelta / 1500f); DTGUI.PushBackgroundColor(new Color(0, 1, 0, alpha)); GUI.Box(mod.Properties.Dimensions.ScaleBy(9), "", CurvyStyles.GlowBox); DTGUI.PopBackgroundColor(); Repaint(); } // Track Window Movement for Viewport calculation Canvas.ViewPortRegisterWindow(mod); } } EndWindows(); if (Sel.SelectedModule != curSel) { Canvas.FocusSelection(); } }
void OnModuleWindowSlotGUI(CGModule module) { int i = 0; float h = 18; while (module.Input.Count > i || module.Output.Count > i) { float y = CurvyStyles.ModuleWindowTitleHeight + h * i; GUILayout.BeginHorizontal(); if (module.Input.Count > i) { CGModuleInputSlot slot = module.Input[i]; Color slotColor = getTypeColor(slot.Info.DataTypes); if (Canvas.IsLinkDrag && !slot.IsValidTarget(Canvas.LinkDragFrom)) { slotColor = new Color(0.2f, 0.2f, 0.2f).SkinAwareColor(true); } DTGUI.PushColor(slotColor); GUILayout.Box("<", CurvyStyles.Slot); DTGUI.PopColor(); string postfix = ""; if (slot.Info.Array) { postfix = (slot.LastDataCountINTERNAL > 0) ? "[" + slot.LastDataCountINTERNAL.ToString() + "]" : "[]"; } GUILayout.Label(new GUIContent(ObjectNames.NicifyVariableName(slot.Info.Name) + postfix, slot.Info.Tooltip), CurvyStyles.GetSlotLabelStyle(slot)); slot.DropZone = new Rect(0, y, module.Properties.Dimensions.width / 2, h); slot.Origin = new Vector2(module.Properties.Dimensions.xMin, module.Properties.Dimensions.yMin + y + h / 2); // LinkDrag? if (Canvas.IsLinkDrag) { // If ending drag over dropzone, create static link if (EV.type == EventType.MouseUp && slot.DropZone.Contains(EV.mousePosition) && slot.IsValidTarget(Canvas.LinkDragFrom)) { finishLink(slot); } } // Clicking on Dropzone to pick existing link else if (LMB && slot.Count == 1 && slot.DropZone.Contains(EV.mousePosition)) { var linkedOutSlot = slot.SourceSlot(); linkedOutSlot.UnlinkFrom(slot); EditorUtility.SetDirty(slot.Module); startLinkDrag(linkedOutSlot); GUIUtility.ExitGUI(); } } if (module.Output.Count > i) { CGModuleOutputSlot slot = module.Output[i]; string postfix = ""; if (slot.Info.Array) { postfix = (slot.Data != null && slot.Data.Length > 1) ? "[" + slot.Data.Length.ToString() + "]" : ""; } GUILayout.Label(new GUIContent(ObjectNames.NicifyVariableName(slot.Info.Name) + postfix, slot.Info.Tooltip), CurvyStyles.GetSlotLabelStyle(slot)); DTGUI.PushColor(getTypeColor(slot.Info.DataTypes)); GUILayout.Box(">", CurvyStyles.Slot); DTGUI.PopColor(); // Debug /* * if (Generator.ShowDebug) * { * GUI.enabled = slot.Data != null && slot.Data.Length>0; * if (GUILayout.Button(new GUIContent(CurvyStyles.DebugTexture, "Show Dump"), CurvyStyles.SmallButton, GUILayout.Width(16), GUILayout.Height(16))) * DTDebugWindow.Open(slot.Data[0].GetType().Name + ":", slot.Data[0].ToDumpString()); * GUI.enabled = true; * } */ slot.DropZone = new Rect(module.Properties.Dimensions.width / 2, y, module.Properties.Dimensions.width / 2, h); slot.Origin = new Vector2(module.Properties.Dimensions.xMax, module.Properties.Dimensions.yMin + y + h / 2); // Start Linking? if (LMB && !Canvas.IsSelectionRectDrag && slot.DropZone.Contains(EV.mousePosition)) { startLinkDrag(slot); } } GUILayout.EndHorizontal(); i++; } }
internal CGModuleEditorBase GetModuleEditor(CGModule module) { CGModuleEditorBase ed; if (!ModuleEditors.TryGetValue(module, out ed)) { ed = Editor.CreateEditor(module) as CGModuleEditorBase; if (ed) { ed.Graph = this; ModuleEditors.Add(module, ed); } else Debug.LogError("Curvy Generator: Missing editor script for module '" + module.GetType().Name + "' !"); } return ed; }
public CurvyCGEventArgs(CGModule module) { Sender = module; Generator = module.Generator; Module = module; }
public bool IsUsing(CGModule module) { return (ModuleID == module.UniqueID || TargetModuleID == module.UniqueID); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var mControlRect = position; label = EditorGUI.BeginProperty(position, label, property); CGResourceManagerAttribute A = (CGResourceManagerAttribute)attribute; CGModule module = (CGModule)property.serializedObject.targetObject; Component res = (Component)property.objectReferenceValue; if (res) { Transform parent = res.transform.parent; bool managed = (parent != null && parent.transform == module.transform); if (managed) { EditorGUI.PrefixLabel(mControlRect, label); mControlRect.x = (A.ReadOnly) ? mControlRect.xMax - 60 : mControlRect.xMax - 82; mControlRect.width = 60; if (GUI.Button(mControlRect, new GUIContent("Select", CurvyStyles.SelectTexture, "Select"), CurvyStyles.SmallButton)) { Selection.activeObject = property.objectReferenceValue; } if (!A.ReadOnly) { mControlRect.x += mControlRect.width + 2; mControlRect.width = 20; if (GUI.Button(mControlRect, new GUIContent(CurvyStyles.DeleteSmallTexture, "Delete resource"), CurvyStyles.SmallButton)) { if (EditorUtility.DisplayDialog("Delete resource", "This will permanently delete the resource! Proceed?", "Yes", "No")) { module.DeleteManagedResource(A.ResourceName, res); property.objectReferenceValue = null; ResourceEditor = null; } } } if (property.objectReferenceValue != null) { //if (!ResourceEditor) ResourceEditor = CGResourceEditorHandler.GetEditor(A.ResourceName, res); if (ResourceEditor && ResourceEditor.OnGUI()) { // TODO: Refresh using new value not always working! module.Invoke("OnValidate", 0); module.Dirty = true; module.Generator.Invoke("Update", 1f); } } } else { mControlRect.width -= 20; EditorGUI.PropertyField(mControlRect, property, label); mControlRect.x += mControlRect.width + 2; mControlRect.width = 20; if (GUI.Button(mControlRect, new GUIContent(CurvyStyles.ClearSmallTexture, "Unset"))) { property.objectReferenceValue = null; ResourceEditor = null; } } } else { mControlRect.width -= 20; EditorGUI.PropertyField(mControlRect, property, label); mControlRect.x = mControlRect.xMax + 2; mControlRect.width = 20; if (GUI.Button(mControlRect, new GUIContent(CurvyStyles.AddSmallTexture, "Add Managed"))) { // Call AddResource to create and name the resource property.objectReferenceValue = module.AddManagedResource(A.ResourceName); } } EditorGUI.EndProperty(); }
public CurvyCGEventArgs(CurvyGenerator generator, CGModule module) { Sender = generator; Generator = generator; Module = module; }
void OnModuleWindowCB(int id) { // something happened in the meantime? if (id >= Modules.Count || mModuleCount != Modules.Count) { return; } CGModule mod = Modules[id]; //if (LMB && Sel.SelectedModules.Count<=1) if (EV.type == EventType.MouseUp && !Sel.SelectedModules.Contains(mod)) { Sel.Select(Modules[id]); } Rect winRect = mod.Properties.Dimensions; // Draw Title Buttons // Enabled EditorGUI.BeginChangeCheck(); mod.Active = GUI.Toggle(new Rect(2, 2, 16, 16), mod.Active, ""); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(Generator); } //Edit Title & Color if (editTitleModule == mod) { GUI.SetNextControlName("editTitle" + id); mod.ModuleName = GUI.TextField(new Rect(30, 5, winRect.width - 120, 16), mod.ModuleName); mod.Properties.BackgroundColor = EditorGUI.ColorField(new Rect(winRect.width - 70, 5, 32, 16), mod.Properties.BackgroundColor); } if (GUI.Button(new Rect(winRect.width - 32, 6, 16, 16), new GUIContent(CurvyStyles.EditTexture, "Rename"), CurvyStyles.BorderlessButton)) { editTitleModule = mod; Sel.Select(mod); EditorGUI.FocusTextInControl("editTitle" + id); } // Help if (GUI.Button(new Rect(winRect.width - 16, 6, 16, 16), new GUIContent(CurvyStyles.HelpTexture, "Help"), CurvyStyles.BorderlessButton)) { var url = DTUtility.GetHelpUrl(mod); if (!string.IsNullOrEmpty(url)) { Application.OpenURL(url); } } // Check errors if (mod.CircularReferenceError) { EditorGUILayout.HelpBox("Circular Reference", MessageType.Error); } // Draw Slots DTGUI.PushColor(mod.Properties.BackgroundColor.SkinAwareColor(true)); EditorGUILayout.BeginVertical(CurvyStyles.ModuleWindowSlotBackground); DTGUI.PopColor(); OnModuleWindowSlotGUI(mod); EditorGUILayout.EndVertical(); var ed = GetModuleEditor(mod); if (ed && ed.target != null) { if (EditorGUILayout.BeginFadeGroup(mShowDebug.faded)) { ed.OnInspectorDebugGUIINTERNAL(Repaint); } EditorGUILayout.EndFadeGroup(); // Draw Module Options mod.Properties.Expanded.valueChanged.RemoveListener(Repaint); mod.Properties.Expanded.valueChanged.AddListener(Repaint); if (!CurvyProject.Instance.CGAutoModuleDetails) { mod.Properties.Expanded.target = GUILayout.Toggle(mod.Properties.Expanded.target, new GUIContent(mod.Properties.Expanded.target ? CurvyStyles.CollapseTexture : CurvyStyles.ExpandTexture, "Show Details"), EditorStyles.toolbarButton); } // === Module Details === // Handle Auto-Folding if (DTGUI.IsLayout && CurvyProject.Instance.CGAutoModuleDetails) { mod.Properties.Expanded.target = (mod == Sel.SelectedModule); } if (EditorGUILayout.BeginFadeGroup(mod.Properties.Expanded.faded)) { EditorGUIUtility.labelWidth = (mod.Properties.LabelWidth); // Draw Inspectors using Modules Background color DTGUI.PushColor(ed.Target.Properties.BackgroundColor.SkinAwareColor(true)); EditorGUILayout.BeginVertical(CurvyStyles.ModuleWindowBackground); DTGUI.PopColor(); ed.RenderGUI(true); if (ed.NeedRepaint) { mDoRepaint = true; } GUILayout.Space(2); EditorGUILayout.EndVertical(); } EditorGUILayout.EndFadeGroup(); } // Make it dragable GUI.DragWindow(new Rect(0, 0, winRect.width, CurvyStyles.ModuleWindowTitleHeight)); }
public Component Create(CGModule module, string context) { var spl = CurvySpline.Create(); spl.transform.position = Vector3.zero; spl.RestrictTo2D = true; spl.Closed = true; spl.Orientation = CurvyOrientation.None; spl.gameObject.AddComponent<CSCircle>().Refresh(); return spl; }
public void Destroy(CGModule module, Component obj, string context, bool kill) { if (obj != null) { #if UNITY_EDITOR if (!Application.isPlaying) Undo.DestroyObjectImmediate(obj.gameObject); else #endif GameObject.Destroy(obj); } }
public void ViewPortRegisterWindow(CGModule module) { Rect winRect = module.Properties.Dimensions; EnlargeCanvasFor(winRect); if (!IsMouseOverModule && EV.type != EventType.Layout) { IsMouseOverModule = winRect.Contains(EV.mousePosition); MouseOverModule=(IsMouseOverModule) ? module:null; } }