Пример #1
0
 void Condition(out ICondition cond)
 {
     cond = null; ICondition other = null;
     SimpleCondition(out cond);
     while (la.kind == 25 || la.kind == 26)
     {
         if (la.kind == 25)
         {
             Get();
             SimpleCondition(out other);
             cond = cond.Intersection(other);
         }
         else
         {
             Get();
             SimpleCondition(out other);
             cond = cond.Union(other);
         }
     }
     cond.Freeze();
     if (la.kind == 27)
     {
         Get();
         ICondition rcond;
         Condition(out rcond);
         rcond.Freeze();
         cond = new TransitionCondition(cond, rcond);
         cond.Freeze();
     }
 }
Пример #2
0
        private void AddTransitionCondition()
        {
            TransitionCondition        condition = _section.TransitionConditions.Add();
            TransitionConditionBuilder transitionConditionBuilder = new TransitionConditionBuilder(condition);

            transitionConditionBuilder.ShowDialog();
        }
Пример #3
0
        private TransitionCondition GetTransitionCondition()
        {
            //Debug.Log("getting transition conditions :: ");
            TransitionCondition ret = 0;

            if (moveCondition.isGrounded)
            {
                ret |= TransitionCondition.GROUNDED;
                //Debug.Log("getting transition conditions :: grounded");
            }
            else
            {
                ret |= TransitionCondition.AERIAL;
            }

            //ret |= (TransitionCondition)input.buttons;

            if (this.CanJump() > 0)
            {
                ret |= TransitionCondition.CANJUMP;
            }

            //Debug.Log(ret);

            return(ret);
        }
 /// <summary>
 /// Creates a state transition rule, that allows a transition from one state (<paramref name="fromState"/>) to an other state (<paramref name="toState"/>)
 /// when a specific <paramref name="condition"/> is fulfilled.
 /// </summary>
 /// <param name="fromState">Type of the origin state. Type must be a subclass of <see cref="WuProcessState"/>.</param>
 /// <param name="toState">Type of the target state. Type must be a subclass of <see cref="WuProcessState"/>.</param>
 /// <param name="condition">Condition which must be fulfilled, before the state transition is valid.</param>
 public StateTransition(Type fromState, Type toState, TransitionCondition condition) : this(fromState, toState)
 {
     if (condition != null)
     {
         Condition = condition;
     }
 }
Пример #5
0
 public MachineTransition(string from, string to, TransitionCondition condition, int interval = -1)
 {
     From      = from;
     To        = to;
     Condition = condition;
     Interval  = interval;
 }
Пример #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="nextState">The state to transition to when the condition satisfied</param>
        /// <param name="condition">The callback used to determine when a transition should occur</param>
        public StateLink(State nextState, TransitionCondition condition)
        {
            Assert.IsNotNull(nextState, "StateLink: nextState is null");
            Assert.IsNotNull(condition, "StateLink: condition is null");

            m_nextState = nextState;
            m_condition = condition;
        }
Пример #7
0
 /// <summary>
 /// [Draft] Initialized constructor
 /// </summary>
 /// <param name="item">Layout item.</param>
 /// <param name="condition">Condition for the position values.</param>
 /// <param name="left">Left position.</param>
 /// <param name="top">Top position.</param>
 /// <param name="right">Right position.</param>
 /// <param name="bottom">Bottom position.</param>
 public LayoutData(LayoutItem item, TransitionCondition condition, float left, float top, float right, float bottom)
 {
     Item = item;
     ConditionForAnimation = condition;
     Left   = left;
     Top    = top;
     Right  = right;
     Bottom = bottom;
 }
Пример #8
0
 /// <summary>
 /// LayoutTransition constructor.
 /// </summary>
 /// <param name="condition">The animatable condition.</param>
 /// <param name="animatableProperty">the property to animate.</param>
 /// <param name="targetValue">target value of the property.</param>
 /// <param name="animator">Components to define the animator.</param>
 /// <since_tizen> 6 </since_tizen>
 public LayoutTransition(TransitionCondition condition,
                         AnimatableProperties animatableProperty,
                         object targetValue,
                         TransitionComponents animator)
 {
     Condition          = condition;
     AnimatableProperty = animatableProperty;
     Animator           = animator;
     TargetValue        = targetValue;
 }
Пример #9
0
		public void RegisterTransition(string fromStateName, string toStateName, TransitionCondition condition)
		{
			IState fromState;
			
			if( !(states.TryGetValue(fromStateName, out fromState) && states.ContainsKey(toStateName) ) )
				return;

			if(!transitions.ContainsKey(fromState))
				transitions.Add(fromState, new List<StateTransition>());

			transitions[fromState].Add(new StateTransition(toStateName, condition));
		}
            public TransitionCondition GetConditions()
            {
                int len = Conditions.Count;
                TransitionCondition ret = 0;

                for (int i = 0; i < len; i++)
                {
                    ret |= Conditions[i];
                }

                return(ret);
            }
Пример #11
0
        /// <summary>
        /// 添加状态切换条件,from 不指定时表示任意状态, to 不指定时表示堆栈中的上一次的状态
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="condition"></param>
        public void AddTransition(string from, string to, TransitionCondition condition)
        {
            if (condition == null)
            {
                return;
            }
            Transition trans = new Transition();

            trans.m_FromState = from;
            trans.m_ToState   = to;
            trans.m_Condition = condition;
            m_Transitions.Add(trans);
        }
Пример #12
0
        /// <summary>
        /// Advance the machine to the next state(s).
        /// </summary>
        /// <seealso cref="StateMachine{S, A}.Step(A)"/>
        /// <param name="letter">The letter used for transitioning.</param>
        protected override void Step(A letter)
        {
            // Perform exit action(s)
            foreach (S state in cursors)
            {
                try {
                    foreach (S nextState in deltaFunction.Evaluate(state, letter))
                    {
                        TransitionCondition condition = nextState.Equals(state) ? TransitionCondition.Self : TransitionCondition.NotSelf;

                        // Perform exit action(s)
                        foreach (ActionInfo actionInfo in stateActions.GetEnumerator(state, TransitionDirection.Exit, condition))
                        {
                            actionInfo.action.Invoke();
                        }
                        foreach (ActionInfo actionInfo in transitionActions.GetEnumerator(state, letter, TransitionDirection.Exit, condition))
                        {
                            actionInfo.action.Invoke();
                        }

                        // Perform enter action(s)
                        foreach (ActionInfo actionInfo in stateActions.GetEnumerator(nextState, TransitionDirection.Enter, condition))
                        {
                            actionInfo.action.Invoke();
                        }
                        foreach (ActionInfo actionInfo in transitionActions.GetEnumerator(nextState, letter, TransitionDirection.Enter, condition))
                        {
                            actionInfo.action.Invoke();
                        }
                    }
                }
                catch (UndefinedTransitionException) {
                    if (!retainCursorOnDeadTransitions)
                    {
                        // Perform exit action(s) on dead transitions
                        foreach (ActionInfo actionInfo in stateActions.GetEnumerator(state, TransitionDirection.Exit, TransitionCondition.NotSelf))
                        {
                            actionInfo.action.Invoke();
                        }

                        foreach (ActionInfo actionInfo in transitionActions.GetEnumerator(state, letter, TransitionDirection.Exit, TransitionCondition.NotSelf))
                        {
                            actionInfo.action.Invoke();
                        }
                    }
                }
            }

            // Update the machine
            base.Step(letter);
        }
Пример #13
0
        /// <summary>
        /// Adds the given transition and condition to a transition list.
        /// </summary>
        /// <param name="targetTransitionList">The list to add the transition to.</param>
        /// <param name="condition">Condition for the transition.</param>
        /// <param name="transition">The transition to add.</param>
        /// <param name="explicitlySet">True is set explicitly, false if inherited.</param>
        static public void AddTransitionForCondition(
            Dictionary <TransitionCondition, TransitionList> targetTransitionList,
            TransitionCondition condition,
            LayoutTransition transition,
            bool explicitlySet)
        {
            bool           replaced = false;
            bool           conditionNotInDictionary = false;
            TransitionList transitionListMatchingCondition;

            if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition))
            {
                if (transitionListMatchingCondition != null)
                {
                    for (var index = 0; index < transitionListMatchingCondition.Count; index++)
                    {
                        if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty)
                        {
                            if (explicitlySet)
                            {
                                transitionListMatchingCondition[index] = transition;
                                replaced = true;
                                continue;
                            }
                        }
                    }
                }
            }
            else
            {
                conditionNotInDictionary = true;
            }

            if (replaced == false)
            {
                if (transitionListMatchingCondition == null)
                {
                    transitionListMatchingCondition = new TransitionList();
                }
                transitionListMatchingCondition.Add(transition);
                // Update dictionary with new or replaced entry.
                if (conditionNotInDictionary)
                {
                    targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry
                }
                else
                {
                    targetTransitionList[condition] = transitionListMatchingCondition; // replaced
                }
            }
        }
Пример #14
0
            public void RegisterTransition(string fromStateName, string toStateName, TransitionCondition condition, TransitionType transition = TransitionType.ReplacePreviousState)
            {
                IState fromState;

                if (!(states.TryGetValue(fromStateName, out fromState) && (transition == TransitionType.RemoveCurrentState || states.ContainsKey(toStateName))))
                {
                    return;
                }

                if (!transitions.ContainsKey(fromState))
                {
                    transitions.Add(fromState, new List <StateTransition>());
                }

                transitions[fromState].Add(new StateTransition(toStateName, condition, transition));
            }
        public void UpdateTest()
        {
            TransitionCondition condition = Substitute.For <TransitionCondition>();

            stateMachine.AddTransition(Color.Red, Color.Blue, condition);

            stateMachine.Update();
            handler.Received().HandleState(Color.Red);
            handler.DidNotReceiveWithAnyArgs().OnStateEnter(Color.Red);
            handler.DidNotReceiveWithAnyArgs().OnStateExit(Color.Red);

            condition.IsFulfilled.Returns(true);
            stateMachine.Update();
            handler.Received().HandleState(Color.Red);
            handler.Received().OnStateExit(Color.Red);
            handler.Received().OnStateEnter(Color.Blue);
        }
Пример #16
0
        /// <summary>
        /// Set all children in a LayoutGroup to the supplied condition.
        /// Children with Add or Remove conditions should not be changed.
        /// </summary>
        private void SetConditionsForAnimationOnLayoutGroup(TransitionCondition conditionToSet)
        {
            foreach (LayoutItem childLayout in _children)
            {
                switch (conditionToSet)
                {
                case TransitionCondition.ChangeOnAdd:
                {
                    // If other children also being added (TransitionCondition.Add) then do not change their
                    // conditions, Continue to use their Add transitions.
                    if (childLayout.ConditionForAnimation.HasFlag(TransitionCondition.Add))
                    {
                        break;  // Child being Added so don't update it's condition
                    }
                    else
                    {
                        // Set siblings for the child being added to use the ChangeOnAdd transition.
                        childLayout.ConditionForAnimation = TransitionCondition.ChangeOnAdd;
                    }
                    break;
                }

                case TransitionCondition.ChangeOnRemove:
                {
                    if (childLayout.ConditionForAnimation.HasFlag(TransitionCondition.Remove))
                    {
                        break; // Child being Removed so don't update it's condition
                    }
                    else
                    {
                        childLayout.ConditionForAnimation = TransitionCondition.ChangeOnRemove;
                    }
                    break;
                }

                case TransitionCondition.LayoutChanged:
                {
                    childLayout.ConditionForAnimation = TransitionCondition.LayoutChanged;
                    break;
                }
                }
            }
        }
Пример #17
0
        protected override void GenerateMember(Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMember(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            if (transition.Opl != null)
            {
                RightValueCsExporter.GenerateClassMember(transition.Opl, stream, indent, "opl");
            }

            if (transition.Opr2 != null)
            {
                RightValueCsExporter.GenerateClassMember(transition.Opr2, stream, indent, "opr2");
            }
        }
Пример #18
0
        /// <summary>
        /// Retreive the transition list for the given condition.
        /// </summary>
        /// <param name="sourceTransitionCollection">The source collection of transition lists to retrieve.</param>
        /// <param name="condition">Condition for the transition.</param>
        /// <param name="transitionsForCondition">transition list to return as out parameter.</param>
        /// <returns>True if a transition list found for the given condition></returns>
        static public bool GetTransitionsListForCondition(
                              Dictionary<TransitionCondition, TransitionList> sourceTransitionCollection,
                              TransitionCondition condition,
                              TransitionList transitionsForCondition )
        {
            TransitionCondition resolvedCondition = condition;
            bool matched = false;
            // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
            // reposition to the new layout not to the insertion/removal of a sibling.
            if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged)
            {
                resolvedCondition = TransitionCondition.LayoutChanged;
            }

            if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition))
            {
                matched = true;
            }

            return matched;
        }
Пример #19
0
        public void InputtingExistentValidFile_SetsUpTransitionsCorrectly()
        {
            Story           story           = new Story();
            SpeechNode      speechNode      = story.CreateNode("Node1");
            SpeechNode      destinationNode = story.CreateNode("Node2");
            Transition      transition      = speechNode.CreateTransition(destinationNode);
            IntentCondition condition       = transition.CreateCondition <IntentCondition>();

            condition.IntentName = "TestIntent";

            string filePath = Path.Combine(Resources.TempDir, "Test.txt");

            SaveStoryBinary(story, filePath);

            FileAssert.FileExists(filePath);
            Story loadedStory = Story.Load(filePath);

            Assert.IsNotNull(loadedStory);
            Assert.AreEqual(2, loadedStory.NodeCount);

            SpeechNode loadedNode            = loadedStory.GetNodeAt(0);
            SpeechNode loadedDestinationNode = loadedStory.GetNodeAt(1);

            Assert.IsNotNull(loadedNode);
            Assert.IsNotNull(loadedDestinationNode);
            Assert.AreEqual(1, loadedNode.TransitionCount);

            Transition loadedTransition = loadedNode.GetTransitionAt(0);

            Assert.AreSame(loadedNode, loadedTransition.Source);
            Assert.AreSame(loadedDestinationNode, loadedTransition.Destination);
            Assert.AreEqual(1, loadedTransition.ConditionCount);

            TransitionCondition loadedCondition = loadedTransition.GetConditionAt(0);

            Assert.IsInstanceOfType(loadedCondition, typeof(IntentCondition));
            Assert.AreEqual("TestIntent", (loadedCondition as IntentCondition).IntentName);
            Assert.AreSame(loadedTransition, loadedCondition.Transition);
        }
Пример #20
0
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\t\tthis.TargetStateId = {1};", indent, transition.TargetFSMNodeId);

            if (transition.Opl != null)
            {
                RightValueCsExporter.GenerateClassConstructor(attachment, transition.Opl, stream, indent, "opl");
            }

            if (transition.Opr2 != null)
            {
                RightValueCsExporter.GenerateClassConstructor(attachment, transition.Opr2, stream, indent, "opr2");
            }
        }
Пример #21
0
 public FSMTransition(FSMState _toState, TransitionCondition _condition)
 {
     toState   = _toState;
     condition = _condition;
 }
Пример #22
0
        /// <summary>
        /// Registers an action to a state.
        /// </summary>
        /// <param name="state">The target state.</param>
        /// <param name="action">The action to be invoked.</param>
        /// <param name="direction">The directional constraint.</param>
        /// <param name="condition">The conditional constraint.</param>
        public void AddStateAction(S state, Action action, TransitionDirection direction = TransitionDirection.Enter, TransitionCondition condition = TransitionCondition.Always)
        {
            ActionInfo actionInfo = new ActionInfo(action);

            stateActions.Add(state, actionInfo, direction, condition);
        }
Пример #23
0
        /// <summary>
        /// Registers an action to a transition.
        /// </summary>
        /// <param name="state">The target state.</param>
        /// <param name="letter">The target transitioning letter.</param>
        /// <param name="action">The action to be invoked.</param>
        /// <param name="direction">The directional constraint.</param>
        /// <param name="condition">The conditional constraint.</param>
        public void AddTransitionAction(S state, A letter, Action action, TransitionDirection direction = TransitionDirection.Exit, TransitionCondition condition = TransitionCondition.Always)
        {
            ActionInfo actionInfo = new ActionInfo(action);

            transitionActions.Add(state, letter, actionInfo, direction, condition);
        }
Пример #24
0
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            {
                string typeName = Plugin.GetNativeTypeName(transition.Opl.ValueType);
                typeName = typeName.Replace("::", ".");

                RightValueCsExporter.GenerateCode(attachment, transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                RightValueCsExporter.GenerateCode(attachment, transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");

                if (transition.Opl != null && transition.Opl.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                }

                if (transition.Opr2 != null && transition.Opr2.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");
                }

                switch (transition.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = (opl == opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl != opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = (opl > opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl >= opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = (opl < opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl <= opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
            }

            stream.WriteLine("{0}\t\t\tif (!op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = EBTStatus.BT_FAILURE;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Пример #25
0
        //this transition algorithm feels very bad, rewrite and organize
        private StateFrameData CheckTransitionState(bool timerIsDone, SpaxInput input, StateFrameData srcState)
        {
            int len = srcState._transitions.Count;

            //gets current transition conditions
            TransitionCondition curConditions = GetTransitionCondition();

            //if the timer is done
            if (timerIsDone)
            {
                curConditions |= TransitionCondition.ON_END;
            }

            for (int i = 0; i < len; i++)
            {
                StateFrameData      potenState = srcState._transitions[i].Target;
                TransitionCondition compare    = srcState._transitions[i].GetConditions();
                InputCodeFlags      inputCond  = srcState._transitions[i].inputConditions;
                CancelCondition     cancelCond = srcState._transitions[i].cancelCondition;
                if ((compare & (TransitionCondition.FULL_METER | TransitionCondition.HALF_METER | TransitionCondition.QUART_METER)) == 0)
                {
                    //if all the conditions are met
                    if ((compare & curConditions) == compare && (cancelCond & this.cancelCondition) == cancelCond)
                    {
                        //get the last input change
                        int fromInput = (int)inputRecorder.GetLatestCode();
                        //flip 6 and 4 direction, if needed
                        if (!moveCondition.facingRight)
                        {
                            fromInput = InputCode.FlipBackForth(fromInput);
                        }

                        bool initialCheck = ((inputCond & (InputCodeFlags)fromInput) == inputCond);
                        bool freePass     = false;

                        if (!initialCheck && (inputCond & InputCodeFlags.CURRENTLY_HELD) > 0)
                        {
                            inputCond ^= InputCodeFlags.CURRENTLY_HELD;
                            int codeFromInput   = (((int)input.direction & 510) << 2) | ((int)input.buttons << 11);
                            int inputCondSimple = ((int)inputCond >> 3) << 3;
                            if (!moveCondition.facingRight)
                            {
                                codeFromInput = InputCode.FlipBackForth(codeFromInput);
                            }

                            freePass = ((codeFromInput & inputCondSimple) == inputCondSimple);
                        }



                        //check it
                        if (inputCond == 0 || initialCheck || freePass)
                        {
                            //Debug.Log(compare);
                            return(AssignNewCurState(potenState));
                        }
                    }
                }
            }

            //only really reached if state to transition to isn't found
            if (((srcState.stateConditions & StateConditions.NO_PARENT_TRANS) == 0) && (srcState.parentState != null))
            {
                return(CheckTransitionState(timerIsDone, input, srcState.parentState));
            }

            return(null);
        }
 public void AddTransition(TState from, TState to, TransitionCondition condition)
 {
     transitions[from].Add((to, condition));
 }
        private void SaveStateMachine()
        {
            var stateMachine = new StateMachineNode();

            NodeUI.StateMachineNodeAsset = new StateMachineNodeAsset {
                Data = stateMachine
            };

            var parameterMap  = new Dictionary <ParameterNodeUI, Parameter>();
            var stateMap      = new Dictionary <StateNodeUI, State>();
            var anyStateMap   = new Dictionary <AnyStateNodeUI, AnyState>();
            var transitionMap = new Dictionary <TransitionInfo, Transition>();

            Parameters.Items.Values.ForEach(p =>
            {
                var parameter  = stateMachine.AddParameter(p.Name);
                parameter.Type = (ValueProviderType)p.ParameterTypeField.value;
                NodeUI.StateMachineNodeAsset.ParameterMap.Add(parameter.Id, new NodeVisualInfo(p.GetPosition().position, p.expanded));

                switch (parameter.ValueProvider)
                {
                case BoolProvider boolProvider:
                    boolProvider.Value = p.BoolField.value;
                    break;

                case IntProvider intProvider:
                    intProvider.Value = p.IntField.value;
                    break;

                case FloatProvider floatProvider:
                    floatProvider.Value = p.FloatField.value;
                    break;

                default:
                    break;
                }

                parameterMap.Add(p, parameter);
            });

            TransitionConnections.ForEach(transitionConnection =>
            {
                transitionConnection.Transitions.ForEach(transitionInfo =>
                {
                    Transition transition = new Transition()
                    {
                        DurationType            = transitionInfo.DurationType,
                        Duration                = transitionInfo.Duration,
                        OffsetType              = transitionInfo.OffsetType,
                        Offset                  = transitionInfo.Offset,
                        InterruptionSource      = transitionInfo.InterruptionSource,
                        OrderedInterruption     = transitionInfo.OrderedInterruption,
                        InterruptableByAnyState = transitionInfo.InterruptableByAnyState,
                        PlayAfterTransition     = transitionInfo.PlayAfterTransition
                    };

                    stateMachine.Transitions.Add(transition);
                    transitionMap.Add(transitionInfo, transition);
                });
            });

            States.Items.Values.ForEach(stateNode =>
            {
                var state = stateMachine.AddState(stateNode.Name);

                stateNode.ExitConnections.ForEach(connection =>
                {
                    ((TransitionConnectionUI)connection).Transitions.ForEach(transitionInfo =>
                    {
                        Transition transition  = transitionMap[transitionInfo];
                        transition.SourceState = state;
                        state.ExitTransitions.Add(transition);
                    });
                });

                stateNode.EntryConnections.ForEach(connection =>
                {
                    if (!(connection is TransitionConnectionUI transitionConnection))
                    {
                        return;
                    }

                    transitionConnection.Transitions.ForEach(transitionInfo =>
                    {
                        Transition transition       = transitionMap[transitionInfo];
                        transition.DestinationState = state;
                        state.EntryTransitions.Add(transition);
                    });
                });

                NodeUI.StateMachineNodeAsset.StateMap.Add(state.Id, new NodeVisualInfo(stateNode.GetPosition().position, stateNode.expanded));
                stateMap.Add(stateNode, state);
            });

            HashSet <AnyStateNodeUI> alreadyAddedAnyStates = new HashSet <AnyStateNodeUI>();

            if (GraphView.AnyStatePriorityManager == null)
            {
                NodeUI.StateMachineNodeAsset.AnyStatePriorityManager = null;
            }
            else
            {
                NodeUI.StateMachineNodeAsset.AnyStatePriorityManager = new NodeVisualInfo(GraphView.AnyStatePriorityManager.GetPosition().position, GraphView.AnyStatePriorityManager.expanded);

                foreach (var anyStateNode in GraphView.AnyStatePriorityManager.AnyStates)
                {
                    if (anyStateNode == null)
                    {
                        continue;
                    }

                    AnyState anyState = anyStateNode.GenerateData(stateMap);

                    anyStateNode.ExitConnections.ForEach(connection =>
                    {
                        ((TransitionConnectionUI)connection).Transitions.ForEach(transitionInfo =>
                        {
                            Transition transition  = transitionMap[transitionInfo];
                            transition.SourceState = anyState;
                            anyState.ExitTransitions.Add(transition);
                        });
                    });

                    stateMachine.AnyStates.AddItem(anyState);
                    NodeUI.StateMachineNodeAsset.AnyStateMap.Add(anyState.Id, new NodeVisualInfo(anyStateNode.GetPosition().position, anyStateNode.expanded));
                    alreadyAddedAnyStates.Add(anyStateNode);
                    anyStateMap.Add(anyStateNode, anyState);
                }
            }

            AnyStates.Items.Values.ForEach(anyStateNode =>
            {
                if (alreadyAddedAnyStates.Contains(anyStateNode))
                {
                    return;
                }

                AnyState anyState = anyStateNode.GenerateData(stateMap);

                anyStateNode.ExitConnections.ForEach(connection =>
                {
                    ((TransitionConnectionUI)connection).Transitions.ForEach(transitionInfo =>
                    {
                        Transition transition  = transitionMap[transitionInfo];
                        transition.SourceState = anyState;
                        anyState.ExitTransitions.Add(transition);
                    });
                });

                stateMachine.AnyStates.AddItem(anyState);
                NodeUI.StateMachineNodeAsset.AnyStateMap.Add(anyState.Id, new NodeVisualInfo(anyStateNode.GetPosition().position, anyStateNode.expanded));
                anyStateMap.Add(anyStateNode, anyState);
            });

            TransitionConnections.ForEach(transitionConnection =>
            {
                transitionConnection.Transitions.ForEach(transitionInfo =>
                {
                    Transition transition          = transitionMap[transitionInfo];
                    transition.Conditions.Capacity = transitionInfo.Conditions.Count;

                    transitionInfo.Conditions.ForEach(infoCondition =>
                    {
                        TransitionCondition condition = new TransitionCondition();

                        if (infoCondition.ProviderSourceType == ValueProviderSourceType.State)
                        {
                            if (infoCondition.State != null)
                            {
                                State state = stateMap[infoCondition.State];

                                switch (infoCondition.StateValueProvider)
                                {
                                case StateValueProviders.PreviousTime:
                                    condition.SetValueProvider(state.PreviousTime);
                                    break;

                                case StateValueProviders.Time:
                                    condition.SetValueProvider(state.Time);
                                    break;

                                case StateValueProviders.PreviousNormalizedTime:
                                    condition.SetValueProvider(state.PreviousNormalizedTime);
                                    break;

                                case StateValueProviders.NormalizedTime:
                                    condition.SetValueProvider(state.NormalizedTime);
                                    break;
                                }

                                FloatConditionEvaluator floatEvaluator = (FloatConditionEvaluator)condition.Evaluator;
                                floatEvaluator.Comparison      = infoCondition.FloatComparison;
                                floatEvaluator.ComparisonValue = infoCondition.FloatComparisonValue;
                            }
                        }
                        else if (infoCondition.Parameter != null)
                        {
                            condition.SetValueProvider(parameterMap[infoCondition.Parameter].ValueProvider);

                            switch (condition.Evaluator)
                            {
                            case BoolConditionEvaluator boolEvaluator:
                                boolEvaluator.ComparisonValue = infoCondition.BoolComparisonValue ? Bool.True : Bool.False;
                                break;

                            case IntConditionEvaluator intEvaluator:
                                intEvaluator.Comparison      = infoCondition.IntComparison;
                                intEvaluator.ComparisonValue = infoCondition.IntComparisonValue;
                                break;

                            case FloatConditionEvaluator floatEvaluator:
                                floatEvaluator.Comparison      = infoCondition.FloatComparison;
                                floatEvaluator.ComparisonValue = infoCondition.FloatComparisonValue;
                                break;

                            default:
                                break;
                            }
                        }

                        transition.Conditions.Add(condition);
                    });
                });
            });

            GraphView.EntryNode.GenerateData(stateMachine, stateMap);
            NodeUI.StateMachineNodeAsset.EntryState = new NodeVisualInfo(GraphView.EntryNode.GetPosition().position, GraphView.EntryNode.expanded);

            NodeUI.UpdateStatePorts();
        }
Пример #28
0
		public StateTransition(string desiredState, TransitionCondition condition)
		{
			this.desiredState = desiredState;
			this.condition = condition;
		}
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = BT_SUCCESS;", indent);

            {
                string typeName = Plugin.GetNativeTypeName(transition.Opl.ValueType);

                RightValueCppExporter.GenerateCode(attachment, transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                RightValueCppExporter.GenerateCode(attachment, transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");

                if (transition.Opl != null && transition.Opl.IsMethod)
                {
                    RightValueCppExporter.PostGenerateCode(transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                }

                if (transition.Opr2 != null && transition.Opr2.IsMethod)
                {
                    RightValueCppExporter.PostGenerateCode(transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");
                }

                switch (transition.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = Details::Equal(opl, opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = !Details::Equal(opl, opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = Details::Greater(opl, opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = Details::GreaterEqual(opl, opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = Details::Less(opl, opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = Details::LessEqual(opl, opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
            }

            stream.WriteLine("{0}\t\t\tif (!op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = BT_FAILURE;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Пример #30
0
			public void RegisterTransition(string fromStateName, string toStateName, TransitionCondition condition, TransitionType transition = TransitionType.ReplacePreviousState)
			{
				IState fromState;

				if( !(states.TryGetValue(fromStateName, out fromState) && (transition == TransitionType.RemoveCurrentState || states.ContainsKey(toStateName)) ) )
					return;

				if(!transitions.ContainsKey(fromState))
					transitions.Add(fromState, new List<StateTransition>());

				transitions[fromState].Add(new StateTransition(toStateName, condition, transition));
			}
Пример #31
0
 public Entry(V value, TransitionDirection direction, TransitionCondition condition)
 {
     this.value     = value;
     this.direction = direction;
     this.condition = condition;
 }
Пример #32
0
 public FSMTransition(FSMState _toState, TransitionCondition _condition)
 {
     toState = _toState;
     condition = _condition;
 }
Пример #33
0
 public StateTransition(States source, States target, TransitionCondition condition)
 {
     this.source    = source;
     this.target    = target;
     this.Condition = condition;
 }
Пример #34
0
        /// <summary>
        /// Sets up the main animation with the animators for each item (each layoutPositionData structure)
        /// </summary>
        private void AddAnimatorsToAnimation(LayoutData layoutPositionData)
        {
            LayoutTransition    positionTransition    = new LayoutTransition();
            LayoutTransition    sizeTransition        = new LayoutTransition();
            TransitionCondition conditionForAnimators = layoutPositionData.ConditionForAnimation;

            // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
            // reposition to the new layout not to the insertion/removal of a sibling.
            if (layoutPositionData.ConditionForAnimation.HasFlag(TransitionCondition.LayoutChanged))
            {
                conditionForAnimators = TransitionCondition.LayoutChanged;
            }

            // Set up a default transitions, will be overwritten if inherited from parent or set explicitly.
            TransitionComponents positionTransitionComponents = CreateDefaultTransitionComponent(0, 300);
            TransitionComponents sizeTransitionComponents     = CreateDefaultTransitionComponent(0, 300);

            bool matchedCustomTransitions = false;


            TransitionList transitionsForCurrentCondition = new TransitionList();

            // Note, Transitions set on View rather than LayoutItem so if the Layout changes the transition persist.

            // Check if item to animate has it's own Transitions for this condition.
            // If a key exists then a List of at least 1 transition exists.
            if (layoutPositionData.Item.Owner.LayoutTransitions.ContainsKey(conditionForAnimators))
            {
                // Child has transitions for the condition
                matchedCustomTransitions = layoutPositionData.Item.Owner.LayoutTransitions.TryGetValue(conditionForAnimators, out transitionsForCurrentCondition);
            }

            if (!matchedCustomTransitions)
            {
                // Inherit parent transitions as none already set on View for the condition.
                ILayoutParent layoutParent = layoutPositionData.Item.GetParent();
                if (layoutParent != null)
                {
                    // Item doesn't have it's own transitions for this condition so copy parents if
                    // has a parent with transitions.
                    LayoutGroup    layoutGroup = layoutParent as LayoutGroup;
                    TransitionList parentTransitionList;
                    // Note TryGetValue returns null if key not matched.
                    if (layoutGroup != null && layoutGroup.Owner.LayoutTransitions.TryGetValue(conditionForAnimators, out parentTransitionList))
                    {
                        // Copy parent transitions to temporary TransitionList. List contains transitions for the current condition.
                        LayoutTransitionsHelper.CopyTransitions(parentTransitionList,
                                                                transitionsForCurrentCondition);
                    }
                }
            }


            // Position/Size transitions can be displayed for a layout changing to another layout or an item being added or removed.

            // There can only be one position transition and one size position, they will be replaced if set multiple times.
            // transitionsForCurrentCondition represent all non position (custom) properties that should be animated.

            // Search for Position property in the transitionsForCurrentCondition list of custom transitions,
            // and only use the particular parts of the animator as custom transitions should not effect all parameters of Position.
            // Typically Delay, Duration and Alphafunction can be custom.
            FindAndReplaceAnimatorComponentsForProperty(transitionsForCurrentCondition,
                                                        AnimatableProperties.Position,
                                                        ref positionTransitionComponents);

            // Size
            FindAndReplaceAnimatorComponentsForProperty(transitionsForCurrentCondition,
                                                        AnimatableProperties.Size,
                                                        ref sizeTransitionComponents);

            // Add animators to the core Animation,

            SetupAnimationForCustomTransitions(transitionsForCurrentCondition, layoutPositionData.Item.Owner);

            SetupAnimationForPosition(layoutPositionData, positionTransitionComponents);

            SetupAnimationForSize(layoutPositionData, sizeTransitionComponents);

            // Dispose components
            positionTransitionComponents.Dispose();
            sizeTransitionComponents.Dispose();
        }
Пример #35
0
			public void RegisterTransitionToPrevious(string stateName, TransitionCondition condition)
			{
				RegisterTransition(stateName, "previous", condition, TransitionType.RemoveCurrentState);
			}