コード例 #1
0
        /// <summary>
        /// Creates a StateAsset and adds it to the state machine's list of states.
        /// </summary>
        /// <remarks>
        /// This will save any unsaved changes with the state machine.
        /// </remarks>
        /// <param name="name">the name of the state</param>
        /// <returns>the created state asset</returns>
        public T CreateState <T>(string name) where T : BaseStateAsset
        {
            Initialize();
            var state = BaseStateAsset.Create <T>(this);

            _states.Add(state);
#if UNITY_EDITOR
            AppendSubAsset(state);
#endif
            return(state);
        }
コード例 #2
0
        /// <summary>
        /// Creates a StateTransitionAsset and adds it to the state machine's set of transitions.
        /// </summary>
        /// <remarks>
        /// This will save any unsaved changes with the state machine to disk.
        /// </remarks>
        /// <param name="dst">the target state for the transition</param>
        /// <returns>the created transition asset</returns>
        public StateTransitionAsset CreateTransition(BaseStateAsset dst)
        {
            Initialize();
            var transition = StateTransitionAsset.Create(this, dst);

            _transitions.Add(transition);
#if UNITY_EDITOR
            StateMachine.AppendSubAsset(transition);
#endif
            return(transition);
        }
コード例 #3
0
        internal static StateTransitionAsset Create(BaseStateAsset src, BaseStateAsset dst)
        {
            Argument.NotNull(src);
            Argument.NotNull(dst);
            var transition = ScriptableObject.CreateInstance <StateTransitionAsset>();

            transition.hideFlags         = HideFlags.HideInHierarchy;
            transition._sourceState      = src;
            transition._destinationState = dst;
            transition._conditions       = new List <StateTransitionCondition>();
            return(transition);
        }
コード例 #4
0
        /// <summary>
        /// Removes a state from the state machine.
        /// </summary>
        /// <remarks>
        /// This will also destroy all transitions related to the state (i.e. transitions starting from or ending
        /// with the state).
        ///
        /// Does nothing if the state is null.
        /// This will save any unsaved changes with the state machine to disk.
        /// </remarks>
        /// <param name="state">the state to remove</param>
        public void RemoveState(BaseStateAsset state)
        {
            Initialize();
            if (state == null || !_states.Contains(state))
            {
                return;
            }
            _states.RemoveAll(s => s == state);

            foreach (var src in _states)
            {
                src.RemoveTransitionsTo(state);
            }

            state.Destroy();
#if UNITY_EDITOR
            SaveAsset();
#endif
        }
コード例 #5
0
 /// <summary>
 /// Removes and destroys a transition from the state.
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public bool RemoveTransitionsTo(BaseStateAsset target) => RemoveTransition(t => t.DestinationState == target);