Ejemplo n.º 1
0
        public static void StartWindowPan(EditorStates states)
        {
            if (states.curEvent.type == EventType.Used)
            {
                return;
            }
            EditorState state = states.curState;

            if (states.curEvent.button == 0 && !state.panWindow)
            {
                state.dragStartPos = states.mousePos;
                state.panWindow    = true;
            }
            else if (state.panWindow)
            {
                EndWindowPan(states);
            }
        }
Ejemplo n.º 2
0
        public static void StartNodeDrag(EditorStates states)
        {
            if (states.curEvent.type == EventType.Used)
            {
                return;
            }
            EditorState state = states.curState;

            if (states.curEvent.button == 0 && !state.dragNode && GUIUtility.hotControl == 0)
            {
                state.dragStartPos = state.startPos = states.mousePos;
                state.dragNode     = true;
            }
            else if (state.dragNode)
            {
                EndNodeDrag(states);
            }
        }
Ejemplo n.º 3
0
        public static void OnMakingConnection(EditorStates states)
        {
            EditorState state = states.curState;

            if (state.makeConnection)
            {
                switch (states.curSpace)
                {
                case EventSpace.Node:
                    BaseNode node = state.selectedObject as BaseNode;

                    state.endNodule = node.Nodules.Find(i => i.GetType() == (state.startNodule is OutputNodule ?
                                                                             typeof(InputNodule) : typeof(OutputNodule))) ??
                                      BaseNodule.Create(state.startNodule is OutputNodule ? "InputNodule" : "OutputNodule", node);

                    if (!state.endNodule.MainNode)
                    {
                        goto default;
                    }

                    if (state.startNodule && state.endNodule)
                    {
                        node.Nodules.Add(state.endNodule);
                        state.startNodule.Nodules.Add(state.endNodule);
                    }
                    goto default;

                case EventSpace.Nodule:
                    state.endNodule = state.selectedObject as BaseNodule;

                    if (state.startNodule && state.endNodule)
                    {
                        state.startNodule.Nodules.Add(state.endNodule);
                    }
                    goto default;

                default:
                    state.startNodule    = null;
                    state.endNodule      = null;
                    state.makeConnection = false;
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public static void HandleEventSpace(EditorStates states)
        {
            EditorState state = states.curState;

            if (CanvasGUI.OptionRect.Contains(states.mousePos))
            {
                states.curSpace = EventSpace.Actor;

                if (!(state.focusedObjects[0] is Actor))
                {
                    state.focusedObjects = new ScriptableObject[] { null }
                }
                ;
            }
            else if (CanvasGUI.ToolBarRect.Contains(states.mousePos))
            {
                states.curSpace = EventSpace.Toolbar;

                if (state.focusedObjects.Length > 0)
                {
                    state.focusedObjects = new ScriptableObject[] { null }
                }
                ;
            }
            else if (state.focusedObjects[0] is BaseNodule)
            {
                states.curSpace = EventSpace.Nodule;
            }
            else if (state.focusedObjects[0] is BaseNode)
            {
                states.curSpace = EventSpace.Node;
            }
            else if (CanvasGUI.CanvasRect.Contains(states.mousePos))
            {
                states.curSpace = EventSpace.Canvas;
            }
            else
            {
                states.curSpace = EventSpace.Everything;
            }
        }
Ejemplo n.º 5
0
        public void Update()
        {
            EditorState oldES = curState;

            if (curIndex != 0)
            {
                states.RemoveRange(curIndex - 1, curIndex);
            }

            if (states.Count >= capacity)
            {
                curState = states[states.Count - 1];
                states.Remove(curState);
            }
            else
            {
                curState = new EditorState(this);
            }
            curState.UpdateParams(oldES);
            states.Insert(0, oldES);
            curIndex = 0;
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
0
 public static Vector2 CanvasToScreenPosition (EditorState state, Vector2 objectPos) {
     return objectPos - state.panDelta;
 }
Ejemplo n.º 9
0
 public static Vector2 ScreenToCanvasPosition (EditorState state, Vector2 screenPos) {
     return screenPos + state.panDelta;
 }
Ejemplo n.º 10
0
 public bool EntrySwitch(EditorState state)
 {
     return(false);
 }
Ejemplo n.º 11
0
        public static void ConnectionCallBack(object callBackObj)
        {
            EditorStates states = callBackObj as EditorStates;

            if (states == null)
            {
                throw new UnityException();
            }
            EditorState state = states.curState;

            switch (states.curSpace)
            {
            case EventSpace.Nodule:
                if (!state.makeConnection)
                {
                    state.startNodule    = state.selectedObject as BaseNodule;
                    state.makeConnection = true;
                }
                else
                {
                    goto default;
                }
                break;

            case EventSpace.Node:
                if (!state.makeConnection)
                {
                    BaseNode node = (state.selectedObject as BaseNode);
                    state.startNodule = node.Nodules.Find(i => i.GetType().ToString().Contains(states.info))
                                        ?? BaseNodule.Create(states.info, node.Nodules.NextItemName(states.info), node);

                    if (state.startNodule.MainNode)
                    {
                        node.Nodules.Add(state.startNodule);
                    }
                    else
                    {
                        state.startNodule.Delete();
                    }


                    if (state.startNodule)
                    {
                        state.makeConnection = true;
                    }
                    else
                    {
                        goto default;
                    }
                }
                else
                {
                    goto default;
                }
                break;

            default:
                state.startNodule    = null;
                state.endNodule      = null;
                state.makeConnection = false;
                break;
            }
        }
Ejemplo n.º 12
0
        static void AddCallBack(object callBackObj)
        {
            EditorStates states = callBackObj as EditorStates;

            if (states == null)
            {
                throw new UnityException();
            }
            EditorState state = states.curState;

            if (states.info.Contains("Node"))
            {
                switch (states.curSpace)
                {
                case EventSpace.Node:
                    if (states.info == "OptionNode")
                    {
                        if (state.selectedObject is MainNode)
                        {
                            MainNode main = state.selectedObject as MainNode;
                            main.Options.Add(OptionNode.Create(main.Options.NextItemName("Option"), main));
                        }
                        else
                        {
                            goto default;
                        }
                    }
                    else if (states.info == "MainNode")
                    {
                        goto default;
                    }
                    else
                    {
                        Debug.LogError("Cannot recognise name of 'Node'. Add More Error here");
                        return;
                    }
                    break;

                default:
                    EditorCache cache = DialogueEditorGUI.Cache;
                    cache.Nodes.Add(DialogueNode.Create(states.info,
                                                        cache.Nodes.NextItemName(states.info),
                                                        CanvasGUI.CanvasToScreenPosition(state, states.mousePos),
                                                        cache.Actors.DefaultActor));
                    break;
                }
            }
            else if (states.info.Contains("Nodule"))
            {
                BaseNode node = (states.curSpace == EventSpace.Node) ? state.selectedObject as BaseNode :
                                (states.curSpace == EventSpace.Nodule) ? (state.selectedObject as BaseNodule).MainNode :
                                null;

                if (node)
                {
                    node.Nodules.Add(BaseNodule.Create(states.info, node.Nodules.NextItemName(states.info), node));
                }
            }
            else
            {
                throw new UnityException();
            }
        }