public override void Perform(LayerStatus[] statuses, Dictionary <int, TransitionInfo> transitionInfos)
        {
            LayerStatus status = statuses [layer];

            if (status.Transition.HasChanged)
            {
                if (OnStarted != null)
                {
                    TransitionInfo currentInfo = GetTransitionInfo(status.Transition.Current, transitionInfos);
                    if (currentInfo != null && GetObservedState(currentInfo) == stateId)
                    {
                        OnStarted(currentInfo, status);
                    }
                }
                if (OnFinished != null)
                {
                    TransitionInfo previousInfo = GetTransitionInfo(status.Transition.Previous, transitionInfos);
                    if (previousInfo != null && GetObservedState(previousInfo) == stateId)
                    {
                        OnFinished(previousInfo, status);
                    }
                }
            }
            if (OnActive != null)
            {
                TransitionInfo currentInfo = GetTransitionInfo(status.Transition.Current, transitionInfos);
                if (currentInfo != null && GetObservedState(currentInfo) == stateId)
                {
                    OnActive(currentInfo, status);
                }
            }
        }
Пример #2
0
        public FromStateTransitionHandler TransitionFrom(int source)
        {
            TransitionInfo info = null;

            foreach (TransitionInfo ti in TransitionInfos.Values)
            {
                if (ti.SourceId == source)
                {
                    info = ti;
                    break;
                }
            }
            if (info != null)
            {
                FromStateTransitionHandler handler = new FromStateTransitionHandler(info.Layer, info.SourceId);
                int id = handler.GetHashCode();
                if (!TransitionHandlers.ContainsKey(id))
                {
                    TransitionHandlers [id] = handler;
                }
                return((FromStateTransitionHandler)TransitionHandlers [id]);
            }
            else
            {
                Debug.LogWarning("There seem to be no transitions from state [" + source + "]. Maybe you need to update the corresonding AnimatorAccess component.");
                return(null);
            }
        }
Пример #3
0
        public ToStateTransitionHandler TransitionTo(int destination)
        {
            TransitionInfo info = null;

            foreach (TransitionInfo ti in TransitionInfos.Values)
            {
                if (ti.DestId == destination)
                {
                    info = ti;
                    break;
                }
            }
            if (info != null)
            {
                ToStateTransitionHandler handler = new ToStateTransitionHandler(info.Layer, info.DestId);
                int id = handler.GetHashCode();
                if (!TransitionHandlers.ContainsKey(id))
                {
                    TransitionHandlers [id] = handler;
                }
                return((ToStateTransitionHandler)TransitionHandlers [id]);
            }
            else
            {
                Debug.LogWarning("There seem to be no transitions to state [" + destination + "]. Maybe you need to update the corresonding AnimatorAccess component.");
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the TransitionInfo for the speicifed transition ID or null if it is 0 or non-existing.
        /// </summary>
        /// <returns>The transition info.</returns>
        /// <param name="transitionId">Transition identifier to look up.</param>
        /// <param name="transitionInfos">Transition infos to use.</param>
        protected TransitionInfo GetTransitionInfo(int transitionId, Dictionary <int, TransitionInfo> transitionInfos)
        {
            TransitionInfo info = null;

            if (transitionId != 0)
            {
                if (transitionInfos.ContainsKey(transitionId))
                {
                    info = transitionInfos [transitionId];
                }
                else
                {
                    Debug.LogWarning("No transition info found for transition [" + transitionId + "]! Seems like the AnimatorAccess component needs to be updated.");
                }
            }
            return(info);
        }
		public override void Perform (LayerStatus[] statuses, Dictionary<int, TransitionInfo> transitionInfos)
		{
			LayerStatus status = statuses [layer];
			int currentTransitionId = status.Transition.Current;
			if (status.Transition.HasChanged) {
				if (currentTransitionId == transitionId && OnStarted != null) {
					TransitionInfo currentInfo = GetTransitionInfo (currentTransitionId, transitionInfos);
					if (currentInfo != null) {
						OnStarted (currentInfo, status);
					}
				}
				int previousTransitionId = status.Transition.Previous;
				if (OnFinished != null && previousTransitionId == transitionId) {
					TransitionInfo previousInfo = GetTransitionInfo (previousTransitionId, transitionInfos);
					if (previousInfo != null) {
						OnFinished (previousInfo, status);
					}
				}
			} else if (OnStay != null && currentTransitionId == transitionId) {
				// OnStay starts firing one cycle after OnStarted
				TransitionInfo info = GetTransitionInfo (currentTransitionId, transitionInfos);
				OnStay (info, status);
			}
		}
 void CheckTransitionStatus(LayerStatus status, Dictionary <int, TransitionInfo> transitionInfos)
 {
     if (status.Transition.HasChanged)
     {
         int currentTransitionId = status.Transition.Current;
         if (currentTransitionId != 0 && OnStarted != null)
         {
             TransitionInfo currentInfo = GetTransitionInfo(currentTransitionId, transitionInfos);
             if (currentInfo != null)
             {
                 OnStarted(currentInfo, status);
             }
         }
         int previousTransitionId = status.Transition.Previous;
         if (previousTransitionId != 0 && OnFinished != null)
         {
             TransitionInfo previousInfo = GetTransitionInfo(previousTransitionId, transitionInfos);
             if (previousInfo != null)
             {
                 OnFinished(previousInfo, status);
             }
         }
     }
 }
		protected override int GetObservedState (TransitionInfo info) {
			return info.SourceId;
		}
		public static void ProcessAllTransitions (Animator animator, ProcessAnimatorTransition callback) {
			AnimatorController controller = GetInternalAnimatorController (animator);
			int layerCount = controller.layerCount;
			for (int layer = 0; layer < layerCount; layer++) {
				string layerName = controller.GetLayer (layer).name;
				UnityEditorInternal.StateMachine sm = controller.GetLayer (layer).stateMachine;
                		//Handle anyState cases. see UnityEditorInternal.StateMachine.transitions
				{
					Transition[] anyTransitions = sm.GetTransitionsFromState(null);
					foreach (var t in anyTransitions) {
						TransitionInfo info = new TransitionInfo (t.uniqueNameHash, t.uniqueName, layer, layerName, 
							0, t.dstState.uniqueNameHash, t.atomic, t.duration, t.mute, t.offset, t.solo);
						callback (info);
					}
				}
				for (int i = 0; i < sm.stateCount; i++) {
					UnityEditorInternal.State state = sm.GetState (i);
					Transition[] transitions = sm.GetTransitionsFromState(state);
					foreach (var t in transitions) {
//						Debug.Log (state.uniqueName +  ", transition: " + t.uniqueName + " ---" + " dest = " + t.dstState + " (" + (Animator.StringToHash (state.uniqueName) == Animator.StringToHash (layerName + "." + t.dstState)) + ") " + " src = " + t.srcState);
						TransitionInfo info = new TransitionInfo (t.uniqueNameHash, t.uniqueName, layer, layerName, 
	                        t.srcState.uniqueNameHash, t.dstState.uniqueNameHash, t.atomic, t.duration, t.mute, t.offset, t.solo);
						callback (info);
					}
				}
			}
		}
		protected abstract int GetObservedState (TransitionInfo info);
 protected abstract int GetObservedState(TransitionInfo info);
		void ProcessTransition (TransitionInfo info) {
			TransitionInfos.Add (info.Id, info);
			object [] parameters = new object[] {info.Id,
				info.Name, 
				info.Layer, 
				info.LayerName, 
				info.SourceId, 
				info.DestId, 
				info.Atomic, 
				info.Duration, 
				info.Mute,
				info.Offset,
				info.Solo,
			};
			string parameterList = CodeElementUtils.GetCallParameterString (parameters);
			EventManagerInitialiser.Code.Add (TransitionInfoDict + ".Add (" + info.Id + ", new TransitionInfo (" + parameterList + "));");
		}
Пример #12
0
 protected override int GetObservedState(TransitionInfo info)
 {
     return(info.DestId);
 }