Beispiel #1
0
 private void UpdateNodePositionMetadata(StateNode node, Vector2 position)
 {
     DoWithUndoAndDirtyFlag(() =>
     {
         RebuildMetadata();
     });
 }
Beispiel #2
0
        private void DisplayNodeOptionsAtPosition(StateNode node)
        {
            GenericMenu genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent("Set as initial state"), false, () => _window.SetInitialStateNode(node));
            genericMenu.AddItem(new GUIContent("Add transition"), false, () => _window.BeginTransitionPreviewFrom(node));
            genericMenu.AddItem(new GUIContent("Remove node"), false, () => _window.RemoveNode(node));
            genericMenu.ShowAsContext();
        }
Beispiel #3
0
        public void SetInitialStateNode(StateNode node)
        {
            _nodes.ForEach(n => n.AsNormal());

            _initialNode = node;
            _initialNode.AsInitial();

            _builder.SetInitialState(_initialNode.StateId);
        }
Beispiel #4
0
 private void RemoveTransitionsRelatedTo(StateNode node)
 {
     for (int i = 0; i < _transitions.Count; i++)
     {
         if (PlainStateMachineBuilderHelper.AreEquals(node.StateId, _transitions[i].StateFrom) ||
             PlainStateMachineBuilderHelper.AreEquals(node.StateId, _transitions[i].StateTo))
         {
             RemoveTransition(_transitions[i]);
         }
     }
 }
Beispiel #5
0
        private bool ContainsTransitionWithSourceAndTarget(StateNode source, StateNode target)
        {
            for (int i = 0; i < _transitions.Count; i++)
            {
                if (_transitions[i].Source == source && _transitions[i].Target == target)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #6
0
        public void RemoveNode(StateNode node)
        {
            if (_nodes.Remove(node))
            {
                RemoveTransitionsRelatedTo(node);

                if (IsSelected(node))
                {
                    DeselectAll();
                }

                RecordAndRebuild();
            }
        }
        public TransitionConnection(StateNode source, StateNode target, Type triggerType, object trigger = null, ScriptableGuardCondition[] guardConditions = null)
        {
            _source = source;
            _target = target;

            _triggerDrawer  = PlainStateMachineGenericTypeDrawerFactory.Create(triggerType, trigger);
            GuardConditions = guardConditions;

            _controlsAreaStyle         = new GUIStyle();
            _controlsAreaStyle.padding = new RectOffset(ControlPaddingLeft, ControlPaddingRight, ControlPaddingTop, ControlPaddingBottom);

            _simpleLabelStyle          = new GUIStyle();
            _simpleLabelStyle.wordWrap = true;
        }
Beispiel #8
0
        private void InternalAddNode(StateNode node)
        {
            DoWithUndoAndDirtyFlag(() =>
            {
                node.OnStateIdChanged     += (changedNode, previousId, currentId) => RecordAndRebuild();
                node.OnStateObjectChanged += (changedNode, previousStateObj, currentStateObj) => RecordAndRebuild();
                node.OnPositionChanged    += UpdateNodePositionMetadata;

                _nodes.Add(node);

                if (_nodes.Count == 1)
                {
                    SetInitialStateNode(node);
                }
            });
        }
Beispiel #9
0
        public void AddTransition(StateNode source, StateNode target)
        {
            DoWithUndoAndDirtyFlag(() =>
            {
                if (ContainsTransitionWithSourceAndTarget(source, target))
                {
                    return;
                }

                var newTransition = new TransitionConnection(source, target, _builder.TriggerType);

                newTransition.OnTriggerChanged         += (connection, previousTrigger, currentTrigger) => RecordAndRebuild();
                newTransition.OnGuardConditionsChanged += (connection, currentGuardConditions) => RecordAndRebuild();

                _transitions.Add(newTransition);
            });
        }
Beispiel #10
0
        public void SelectNode(StateNode node)
        {
            DeselectAll();

            for (int i = 0; i < _nodes.Count; i++)
            {
                var currentNode = _nodes[i];

                if (currentNode == node)
                {
                    GUI.FocusControl(null);
                    _selectedObject = currentNode;
                    currentNode.Select();
                }
            }

            Repaint();
        }
Beispiel #11
0
        public void HandleEventFor(StateNode node, Event nodeEvent)
        {
            switch (nodeEvent.type)
            {
            case EventType.MouseDown:

                if (IsLeftMouseClick(nodeEvent.button))
                {
                    if (node.IsPointOverNode(nodeEvent.mousePosition))
                    {
                        if (_window.HasTransitionPreview())
                        {
                            _window.AddTransition(_window.GetSourceNodeFromTransitionPreview(), node);
                            _window.EndTransitionPreview();
                        }

                        _window.SelectNode(node);
                        nodeEvent.Use();
                    }
                }
                else if (IsRightMouseClick(nodeEvent.button) && _window.IsSelected(node))
                {
                    DisplayNodeOptionsAtPosition(node);
                    nodeEvent.Use();
                }

                break;

            case EventType.MouseDrag:

                if (IsLeftMouseClick(nodeEvent.button) && _window.IsSelected(node))
                {
                    node.Drag(nodeEvent.delta);
                    nodeEvent.Use();
                }

                break;
            }
        }
Beispiel #12
0
        private void RebuildMetadata()
        {
            _metadata.StateNodesMetadata.Clear();

            _builder.RemoveMetadata(MetadataKey);

            var states = _builder.GetStates();

            if (states == null)
            {
                return;
            }

            for (int i = 0; i < states.Length; i++)
            {
                StateInfo currentState     = states[i];
                StateNode currentStateNode = GetNodeOf(currentState);

                _metadata.StateNodesMetadata.Add(new StateNodeMetadata(currentState.StateId, currentStateNode.Position));
            }

            _builder.SaveMetadata(MetadataKey, _metadata);
        }
Beispiel #13
0
 public TransitionConnectionPreview(StateNode source)
 {
     Source = source;
 }
Beispiel #14
0
 public void BeginTransitionPreviewFrom(StateNode source)
 {
     _transitionPreview = new TransitionConnectionPreview(source);
 }
Beispiel #15
0
 public bool IsInitial(StateNode node)
 {
     return(_initialNode == node);
 }
Beispiel #16
0
 public bool IsSelected(StateNode node)
 {
     return(object.ReferenceEquals(_selectedObject, node));
 }
Beispiel #17
0
        private void AddNodeFrom(StateInfo stateInfo, StateNodeMetadata metadata)
        {
            var newNode = new StateNode(metadata.Position, _builder.StateIdType, GenerateStateNodeId(), stateInfo.StateObject, stateInfo.StateId);

            InternalAddNode(newNode);
        }
Beispiel #18
0
        public void AddNode(Vector2 mousePosition, ScriptableState stateObject = null)
        {
            var newNode = new StateNode(mousePosition, _builder.StateIdType, GenerateStateNodeId(), stateObject);

            InternalAddNode(newNode);
        }