コード例 #1
0
        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;
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
 public void Init()
 {
     States = new EditorStates(this);
     DialogueEditorGUI.UpdateEnvironment(this);
     Actors.Init();
     Conditions.Init();
     Nodes.Init();
 }
コード例 #6
0
 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();
 }
コード例 #7
0
        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));
            }
        }
コード例 #8
0
 public override void Delete()
 {
     while (options.Count > 0)
     {
         options.Get(0).Delete();
     }
     base.Delete();
     DialogueEditorGUI.UpdateSelection();
 }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        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();
            }
        }
コード例 #14
0
        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();
        }