コード例 #1
0
 public void ChangeState(EditorNodeState to)
 {
     Debug.Log("Changing state");
     this.nextState        = to;
     transitionToNextState = true;
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (transitionToNextState)
        {
            state = nextState;
            transitionToNextState = false;
        }

        switch (state)
        {
        case EditorNodeState.DraggingStarted: {
            Debug.Log("DraggingStarted state moving to DraggingState");
            ChangeState(EditorNodeState.Dragging);
            break;
        }

        case EditorNodeState.Dragging: {
            DoDragging();
            break;
        }

        case EditorNodeState.DraggingEnded: {
            ChangeState(EditorNodeState.None);
            break;
        }

        case EditorNodeState.EditingStarted: {
            ChangeState(EditorNodeState.Editing);
            break;
        }

        case EditorNodeState.Editing: {
            // DoEditing()
            break;
        }

        case EditorNodeState.EditingEnded: {
            ChangeState(EditorNodeState.None);
            break;
        }

        case EditorNodeState.DraggingConnectionStarted: {
            ChangeState(EditorNodeState.DraggingConnection);
            break;
        }

        case EditorNodeState.DraggingConnection: {
            DoConnectionDragging();
            break;
        }

        case EditorNodeState.DraggingConnectionEnded: {
            ChangeState(EditorNodeState.None);
            break;
        }
        }

        // Ghetto event handling
        if (Input.GetMouseButtonDown(0))
        {
            clickStarted = true;
            clickBegan   = Time.realtimeSinceStartup;
            //Debug.Log("Click started");
        }
        else if (Input.GetMouseButtonUp(0) && clickStarted)
        {
            float now  = Time.realtimeSinceStartup;
            float diff = now - clickBegan;
            //Debug.Log("Mouse up after " + diff + " seconds");
            if (diff > .08)
            {
                if (state == EditorNodeState.Dragging)
                {
                    Debug.Log("Dragging ending");
                    ChangeState(EditorNodeState.DraggingEnded);
                }
            }

            clickBegan   = 0;
            clickStarted = false;
        }
    }