public static bool Toggle (Rect rect, GUIContent content, bool value, GUIStyle style) { int controlID = GUIUtility.GetControlID (rect.GetHashCode (), FocusType.Passive, new Rect (GUItoWindowPosition (rect.position), rect.size)); Event current = Event.current; switch (current.GetTypeForControl (controlID)) { case EventType.MouseDown: if (allowControl && HasFocus (rect) && current.button == 0) { GUIUtility.hotControl = controlID; DialogueEditorGUI.Repaint (); } break; case EventType.MouseUp: if (allowControl && HasSelection (controlID)) { GUIUtility.hotControl = 0; current.Use (); if (HasFocus (rect)) value = !value; } break; case EventType.Repaint: style.Draw (rect, content, HasFocus (rect), HasSelection (controlID), value, false); break; } return value; }
public static void OnNodeDrag(EditorStates states) { EditorState state = states.curState; if (state.dragNode) { if (states.mousePos.x < CanvasGUI.CanvasRect.xMin || states.mousePos.x > CanvasGUI.CanvasRect.xMax) { states.mousePos.x = state.dragStartPos.x; } if (states.mousePos.y < CanvasGUI.CanvasRect.yMin || states.mousePos.y > CanvasGUI.CanvasRect.yMax) { states.mousePos.y = state.dragStartPos.y; } BaseNode node = state.selectedObject as BaseNode; if (node is OptionNode && (node as OptionNode).MainNode) { EndNodeDrag(states); } state.dragDelta = states.mousePos - state.dragStartPos; node.UpdateAllPosition(state.dragDelta); state.dragStartPos = states.mousePos; DialogueEditorGUI.Repaint(); } }
public static EditorCache SaveCanvas(string filePath, bool createCopy, EditorCache cache) { if (!ValidPath(ref filePath)) { Debug.LogError("the file path: " + filePath + ", does not exist"); return(cache); } Reset(); if (createCopy) { CopyRefs(cache); cache = ReplaceSO(cache) as EditorCache; ReplaceRefs(cache); } SaveAsset(cache, filePath); foreach (ScriptableObject objRef in cache.GetAllReferences(true)) { if (!objRef) { throw new UnityException("' " + objRef.GetType() + "' Database is missing reference. Cannot save the dialogue canvas."); } SaveRefs(objRef, cache, false); } DialogueEditorGUI.Save(); return(cache); }
public void OnGUI() { CanvasGUI.Position = position; if (DateTime.Now - lastCheck >= ResourceManager.CheckRate) { if (!EditorCache.ValidateCanvas(cache)) { Debug.LogWarning("Loading last opened session."); InitCanvas(); cache = EditorCache.LoadCache(); } else { cache.Init(); } lastCheck = DateTime.Now; } InputSystem.EarlyInputEvents(cache.States); DialogueEditorGUI.OnGUI(cache.States); ToolBar(); InputSystem.LateInputEvents(cache.States); cache.States.UpdateEvents(); if (openDebug = CanvasGUI.Toggle(new Rect(5, 5, 130, 20), new GUIContent("Debug Window"), openDebug)) { DebuggerWindow(); } }
public void Init() { States = new EditorStates(this); DialogueEditorGUI.UpdateEnvironment(this); Actors.Init(); Conditions.Init(); Nodes.Init(); }
public void Delete(OptionNode item) { DialogueEditorGUI.UpdateSelection(new EditorStates((GetIndex(item) < Count - 1) ? Get(GetIndex(item) + 1).Position.position.ToString() : mainNode.Position.center.ToString(), DialogueEditorGUI.States)); base.Remove(item); ReCalcAllOptionPos(); }
public void SaveNewObject(CanvasObject subObject, CanvasObject mainObject, bool updateSelection = false) { SaveManager.SaveObjects(subObject, mainObject); if (updateSelection) { DialogueEditorGUI.UpdateSelection(new EditorStates(subObject.Position.center.ToString(), States)); } }
public override void Delete() { while (options.Count > 0) { options.Get(0).Delete(); } base.Delete(); DialogueEditorGUI.UpdateSelection(); }
public static void SaveObjects(ScriptableObject subObj, ScriptableObject mainObj) { if (!subObj || !mainObj) { throw new UnityException("The " + (!subObj ? "sub" : "main") + " object is missing reference. Cannot save the object's references."); } if (!AssetDatabase.Contains(mainObj) || AssetDatabase.Contains(subObj)) { return; } Reset(); SaveRefs(subObj, mainObj, false); DialogueEditorGUI.Save(); }
public static void HandleSelecting(EditorStates states) { EditorState state = states.curState; if (state.focusedObjects[0] != state.selectedObject) { state.selectedObject = state.focusedObjects[0]; unfocusControls = states; if (state.selectedObject != null) { Selection.activeObject = state.selectedObject; } DialogueEditorGUI.Repaint(); } }
public static void OnSelectConnection(EditorStates states) { EditorState state = states.curState; switch (states.curSpace) { case EventSpace.Nodule: int count = (state.selectedObject as BaseNodule).Nodules.Count; state.connectionIndex = (count > 0 && state.connectionIndex < count - 1) ? state.connectionIndex + 1 : (count == 0) ? -1 : 0; break; default: state.connectionIndex = -1; break; } DialogueEditorGUI.Repaint(); }
public static void OnWindowPan(EditorStates states) { EditorState state = states.curState; if (state.panWindow) { if (states.mousePos.x < CanvasGUI.CanvasRect.xMin || states.mousePos.x > CanvasGUI.CanvasRect.xMax) { states.mousePos.x = state.dragStartPos.x; } if (states.mousePos.y < CanvasGUI.CanvasRect.yMin || states.mousePos.y > CanvasGUI.CanvasRect.yMax) { states.mousePos.y = state.dragStartPos.y; } state.panDelta += states.mousePos - state.dragStartPos; if (state.panDelta.x > 0) { state.panDelta.x = 0; } else if ((state.panDelta - CanvasGUI.CanvasRect.size).x < -state.canvasSize.x) { state.panDelta.x = (CanvasGUI.CanvasRect.size - state.canvasSize).x; } if (state.panDelta.y > 0) { state.panDelta.y = 0; } else if ((state.panDelta - CanvasGUI.CanvasRect.size).y < -state.canvasSize.y) { state.panDelta.y = (CanvasGUI.CanvasRect.size - state.canvasSize).y; } state.dragStartPos = states.mousePos; DialogueEditorGUI.Repaint(); } }
public static void EndNodeDrag(EditorStates states) { EditorState state = states.curState; if (state.dragNode) { if (state.selectedObject is OptionNode && (states.mousePos - state.startPos).magnitude > 10) { states.mousePos = CanvasGUI.CanvasToScreenPosition(state, states.mousePos); foreach (MainNode node in DialogueEditorGUI.Cache.Nodes.OfType <MainNode> ()) { if (node.Options.OptionAddRect.Contains(states.mousePos)) { DialogueEditorGUI.Cache.Nodes.Remove(state.selectedObject as OptionNode); node.Options.Add(state.selectedObject as OptionNode); break; } } } state.dragNode = false; DialogueEditorGUI.Repaint(); } }
protected override void OnGUI() { for (int i = 0; i < groupsToDraw.Count; i++) { ItemGroup itemGroup = groupsToDraw[i]; Rect tolerance = new Rect(itemGroup.position); tolerance.xMin -= 20; tolerance.yMin -= 20; tolerance.xMax += 20; tolerance.yMax += 20; bool hasFocus = tolerance.Contains(Event.current.mousePosition); CanvasGUI.BeginGroup(itemGroup.position, GUI.skin.box, hasFocus); foreach (MenuItem item in itemGroup) { if (item.content.text.Equals("Saparator")) { GUI.Label(item.position, "----------"); } else if (item.position.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { if (item.Group) { groupsToDraw.Add(item.subItems); } else { item.Execute(); close = true; } Event.current.Use(); } if (item.Group && groupsToDraw.Exists(j => j == item.subItems)) { item.subItems.forceFocus = true; } CanvasGUI.Box(item.position, item.content); } else { if (item.Group && groupsToDraw.Exists(j => j == item.subItems)) { item.subItems.forceFocus = false; } GUI.Label(item.position, item.content); } if (item.Group) { GUI.Label(new Rect(item.position.position + new Vector2(item.position.size.x - GroupIconSize, 0), new Vector2(GroupIconSize, minHeight)), ">"); } } CanvasGUI.EndGroup(); if (!hasFocus && !itemGroup.forceFocus) { if (i != 0) { groupsToDraw.Remove(itemGroup); } else if (Event.current.type == EventType.MouseUp) { close = true; } } } if (groupsToDraw.Count == 0 || close) { OnClose(); } DialogueEditorGUI.OnRepaint(); }