コード例 #1
0
 public IEnumerator ObscureTransition()
 {
     for (var elapsed = 0.0f; elapsed < CurrentTransition.ObscureTime; elapsed += Time.unscaledDeltaTime)
     {
         CurrentTransition.Obscurred(elapsed);
         yield return(null);
     }
 }
コード例 #2
0
        public bool BeginTransition(PlayedCharacter character)
        {
            if (IsEnded())
            {
                return(true);
            }

            CurrentTransition.TransitionEnded += CurrentTransitionOnTransitionEnded;
            return(CurrentTransition.BeginTransition(character.SubMap, SubMaps[Index + 1], character));
        }
コード例 #3
0
        public IEnumerator FinishTransition()
        {
            for (var elapsed = 0.0f; elapsed < CurrentTransition.DurationIn; elapsed += Time.unscaledDeltaTime)
            {
                CurrentTransition.TransitionIn(elapsed);
                yield return(null);
            }

            TransitionObject.SetActive(false);
            CurrentTransition.End();
            CurrentTransition = null;
        }
コード例 #4
0
        public void SaveSettings()
        {
            if (_transitionSetting == null)
            {
                SettingsManager.Current.AddSetting(SettingsConstants.TRANSITION_ASSEMBLY_NAME, CurrentTransition.GetType().AssemblyQualifiedName);
                return;
            }


            _transitionSetting.Value = CurrentTransition.GetType().AssemblyQualifiedName;
            SettingsManager.Current.Save(_transitionSetting);
        }
コード例 #5
0
        private StateMachine InvokeTransition()
        {
            //Mark nextParameters as current
            _currentParameters = _nextParameters;
            _nextParameters    = null;

            //Mark nextTransition as current
            CurrentTransition = _nextTransition;
            _nextTransition   = null;

            //Mark currentState as previous
            PreviousState = CurrentState;
            CurrentState  = null;


            CurrentTransition.Invoking(_currentParameters);
            CurrentState      = CurrentTransition.StateTo;
            CurrentTransition = null;

            return(this);
        }
コード例 #6
0
        /// <summary>
        /// 判断 状态过渡 是否进行
        /// </summary>
        /// <returns>true: 本帧不再执行当前状态的 OnStateUpdate 的方法 false:本帧执行当前状态的 OnStateUpdate 的方法 </returns>
        private bool DoTransition()
        {
            bool result = false;

            if (CurrentState == null)
            {
                if (DefaultState == null)
                {
                    throw new Exception("默认状态不能为空");
                }
                CurrentState = DefaultState;
            }
            #region 另一种处理方式
            //// todo 1、多个状态同时触发,不好处理
            //// todo 2、CurrentTransition.TransitionCallBack() 需要回复到初始状态
            //// todo 3、最好不要在进行状态过渡时,中止当前过渡
            //// todo 4、所以本状态模式最后采用,当前过渡没有完成时,没有中止当前状态过渡,以及无法进入其他的状态过渡
            //// 判断是否正在进行状态过渡
            //if (IsTransition)
            //{
            //    if (!CurrentTransition.Check()) // 只有当前过渡中止,才能切换,其他的状态过渡,在当前过渡执行中是不会触发的
            //    {
            //        result = false;
            //        IsTransition = false;
            //    }
            //    else
            //    {
            //        result = true;
            //        // 判断状态过渡的回调是否执行完毕
            //        if (CurrentTransition.TransitionCallBack())
            //        {
            //            // 执行状态过渡(就是状态的退出 和 进入方法)
            //            CurrentState.OnStateExit();
            //            CurrentState = CurrentTransition.ToState;
            //            CurrentState.OnStateEnter();
            //            IsTransition = false;
            //            if (CurrentState.IsRunContineStartAndUpdate)
            //                result = false;
            //        }
            //        return result;
            //    }
            //}
            #endregion
            // 判断是否正在进行状态过渡
            if (IsTransition)
            {
                result = true;
                // 判断状态过渡的回调是否执行完毕
                if (CurrentTransition.TransitionCallBack())
                {
                    // 执行状态过渡(就是状态的退出 和 进入方法)
                    CurrentState.OnStateExit();
                    CurrentState = CurrentTransition.ToState;
                    CurrentState.OnStateEnter();
                    IsTransition = false;
                    if (CurrentState.IsRunContineStartAndUpdate)
                    {
                        result = false;
                    }
                }
                return(result);
            }
            // 当多个转换条件都满足,则只执行第一个转换
            foreach (Transition transition in CurrentState.Transitions.Values)
            {
                if (transition.Check())
                {
                    result            = true;
                    IsTransition      = true;
                    CurrentTransition = transition;

                    /*
                     *  执行状态过渡
                     *  true :过渡动作完成,    本帧继续执行 旧状态的 OnStateExit 和 新状态的 OnStateEnter 方法
                     *  false:过渡动作正在进行, 本帧不执行 当前状态(旧状态)的 OnStateUpdate/OnStateLateUpdate/OnStateFixedUpdate 方法
                     *                          只执行当前的过渡动作
                     */
                    if (CurrentTransition.TransitionCallBack())// true:过渡动作完成  false:正在进行过渡动作
                    {
                        CurrentState.OnStateExit();
                        CurrentState = CurrentTransition.ToState;
                        CurrentState.OnStateEnter();
                        IsTransition = false;

                        /*
                         *  此时刚刚进入了新状态,IsRunContineStartAndUpdate 属性
                         *      1、true  :本帧 执行   新状态的 OnStateUpdate/OnStateLateUpdate/OnStateFixedUpdate 方法
                         *      2、false :本帧 不执行 新状态的 OnStateUpdate/OnStateLateUpdate/OnStateFixedUpdate 方法
                         */
                        if (CurrentState.IsRunContineStartAndUpdate)
                        {
                            result = false;
                        }
                    }
                    return(result); // true 本帧不再执行当前状态的 OnStateUpdate 的方法,false 本帧执行当前状态的 OnStateUpdate 的方法
                }
            }
            return(result);
        }
コード例 #7
0
 /// <summary>
 /// Selects the transition based on the last navigation action that occurred.
 /// </summary>
 /// <param name="oldContent">The old content.</param>
 /// <param name="newContent">The new content.</param>
 public override Transition SelectTransition(object oldContent, object newContent)
 {
     return(CurrentTransition != null?CurrentTransition.CreateTransition() : null);
 }
コード例 #8
0
        /// <summary>
        /// Creates and connects all places and transitions to a complete petri net
        /// </summary>
        /// <author>Christopher Licht</author>
        public void BuildTheNet()
        {
            Place Place;
            int   PlaceCounter = 0;

            //Create one place for all startActvities and one place for all endActvities
            Place StartPlace = _petriNet.AddPlace("start", 0);
            Place EndPlace   = _petriNet.AddPlace("end", 1);

            PlaceCounter = 1;

            //Create the transitions with the detected activities of step 1
            foreach (String CurrentActivity in _listOfActivities)
            {
                _petriNet.AddTransition(CurrentActivity);
            }

            //Connects all startActvities with the startPlace
            foreach (String CurrentStartActivity in _listOfStartActivities)
            {
                foreach (Transition CurrentTransition in _petriNet.Transitions)
                {
                    if (CurrentTransition.Name.Equals(CurrentStartActivity))
                    {
                        CurrentTransition.AddIncomingPlace(StartPlace);
                    }
                }
            }

            //Connects all endActvities with the endPlace
            foreach (String CurrentEndActivity in _listOfEndActivities)
            {
                foreach (Transition CurrentTransition in _petriNet.Transitions)
                {
                    if (CurrentTransition.Name.Equals(CurrentEndActivity))
                    {
                        CurrentTransition.AddOutgoingPlace(EndPlace);
                    }
                }
            }

            //All transitions get their incoming and outgoing places
            foreach (AlphaMinerPlaces CurrentAlphaMinerPlaces in _listOfAlphaPlaces)
            {
                PlaceCounter++;
                Place = _petriNet.AddPlace("", PlaceCounter);

                //Splits the predecessor and followers of the current place
                HashSet <String> _ListOfPredecessor = CurrentAlphaMinerPlaces.PredecessorHashSet;
                HashSet <String> _ListOfFollower    = CurrentAlphaMinerPlaces.FollowerHashSet;

                //The current predecessor-transition will be connected to the current place
                for (int i = 0; i < _ListOfPredecessor.Count; i++)
                {
                    foreach (Transition CurrentTransition in _petriNet.Transitions)
                    {
                        if (CurrentTransition.Name.Equals(_ListOfPredecessor.ElementAt(i)))
                        {
                            CurrentTransition.AddOutgoingPlace(Place);
                        }
                    }
                }

                //The current follower-transition will be connected to the current place
                for (int i = 0; i < _ListOfFollower.Count; i++)
                {
                    foreach (Transition CurrentTransition in _petriNet.Transitions)
                    {
                        if (CurrentTransition.Name.Equals(_ListOfFollower.ElementAt(i)))
                        {
                            CurrentTransition.AddIncomingPlace(Place);
                        }
                    }
                }
            }
        }