public void PlayLoopingAnimation()
 {
     if (Clip != null)
     {
         CurrentAnimationState = animancer.Play(Clip);
     }
 }
Esempio n. 2
0
            public static void CrossFadeQueued(AnimancerState state)
            {
                CleanUp();

                var layer = state.Layer;

                // If the layer has no current state, just play the animation immediately.
                if (!layer.CurrentState.IsValid() || layer.CurrentState.Weight == 0)
                {
                    var fadeDuration = state.CalculateEditorFadeDuration(AnimancerPlayable.DefaultFadeDuration);
                    layer.Play(state, fadeDuration);
                    return;
                }

                AnimationQueue queue;

                if (!PlayableToQueue.TryGetValue(layer, out queue))
                {
                    queue = new AnimationQueue();
                    PlayableToQueue.Add(layer, queue);
                }

                queue.Queue.Add(state);

                layer.CurrentState.Events.OnEnd -= queue.PlayNext;
                layer.CurrentState.Events.OnEnd += queue.PlayNext;
            }
Esempio n. 3
0
        /// <summary>
        /// 播放一个动画,默认过渡时间为0.3s,如果在此期间再次播放,则会继续播放
        /// </summary>
        /// <param name="stateTypes"></param>
        /// <param name="fadeDuration">动画过渡时间</param>
        /// <returns></returns>
        public AnimancerState PlayAnim(string stateTypes, float fadeDuration = 0.3f, float speed = 1.0f)
        {
            AnimancerState animancerState = AnimancerComponent.CrossFade(this.AnimationClips[RuntimeAnimationClips[stateTypes]], fadeDuration);

            animancerState.Speed = speed;
            return(animancerState);
        }
            /************************************************************************************************************************/

            /// <summary>
            /// Determines the <see cref="MatchType"/> representing the properties animated by the `state` in
            /// comparison to the properties that actually exist on the target <see cref="GameObject"/> and its
            /// children.
            /// <para></para>
            /// Also compiles a `message` explaining the differences if that paraneter is not null.
            /// </summary>
            public MatchType GetMatchType(AnimancerState state, StringBuilder message)
            {
                var clips = ObjectPool.AcquireSet <AnimationClip>();

                state.GatherAnimationClips(clips);

                var bindings         = message != null ? new Dictionary <EditorCurveBinding, bool>() : null;
                var existingBindings = 0;

                MatchType match = default;

                foreach (var clip in clips)
                {
                    var clipMatch = GetMatchType(clip, message, bindings, ref existingBindings);
                    if (match < clipMatch)
                    {
                        match = clipMatch;
                    }
                }

                AppendBindings(message, bindings, existingBindings);

                ObjectPool.Release(clips);
                return(match);
            }
Esempio n. 5
0
 public void PlayIdle()
 {
     if (!animancer.IsPlaying(enemyData.GetIdleClip()))
     {
         animancerState_layer1 = animancer.Play(enemyData.GetIdleClip());
     }
 }
Esempio n. 6
0
 public void PlayWalking()
 {
     if (!animancer.IsPlaying(enemyData.GetWalkingClip()))
     {
         animancerState_layer1 = animancer.Play(enemyData.GetWalkingClip(), 0.25f);
     }
 }
Esempio n. 7
0
    void Flinch()
    {
        if (isFlinching)
        {
            return;
        }

        if (currentState.Interupptable)
        {
            animancerState_layer1.NormalizedTime = 0;
            animancerState_layer1.IsPlaying      = false;
        }

        animancer.Layers[1].IsAdditive       = true;
        animancerState_layer2                = animancer.Layers[1].Play(enemyData.GetFlinchClip());
        animancerState_layer2.NormalizedTime = 0;
        animancerState_layer2.Speed          = 1.75f;

        animancerState_layer2.Events.Add(0.6f, OnEndFlinching);

        //Spawn Effect
        MessageDispatcher.SendMessageData(GameEvent.SPANW_BLOOD_MIST, transform.position + Vector3.up);

        isFlinching = true;
    }
Esempio n. 8
0
 /// <summary>
 /// 处理播放动画
 /// </summary>
 /// <param name="stateTypes">动画对应StateType</param>
 private void HandlePlayAnim(string stateTypes, float fadeDuration = 0.3f)
 {
     //在播放完成后,每帧都会调用OnEnd委托,由于行为树中的FixedUpdate与Unity的Update频率不一致,所以需要作特殊处理
     m_AnimancerState = this.TheUnitBelongTo.GetComponent <AnimationComponent>()
                        .PlayAnim(stateTypes, fadeDuration);
     m_AnimancerState.OnEnd = this.m_OnAnimFinished;
 }
 public void PlaySingleAnimation(AnimationClip clip)
 {
     if (clip != null)
     {
         AnimancerState a_state = animancer.Play(clip);
         a_state.Events.OnEnd += ReturnToCurrentStateFromSingleAnimation;
     }
 }
Esempio n. 10
0
        /// <summary>
        /// 播放一个动画,默认过渡时间为0.3s,如果在此期间再次播放,则会从头开始
        /// </summary>
        /// <param name="stateTypes"></param>
        /// <param name="fadeDuration">动画过渡时间</param>
        /// <returns></returns>
        public AnimancerState PlayAnimFromStart(StateTypes stateTypes, float fadeDuration = 0.3f, float speed = 1.0f)
        {
            AnimancerState animancerState =
                AnimancerComponent.CrossFadeFromStart(this.AnimationClips[RuntimeAnimationClips[stateTypes.GetStateTypeMapedString()]],
                                                      fadeDuration);

            animancerState.Speed = speed;
            return(animancerState);
        }
Esempio n. 11
0
            /************************************************************************************************************************/

            /// <summary>
            /// Logs a description of the issues found when comparing the properties animated by the `state` to the
            /// properties that actually exist on the target <see cref="GameObject"/> and its children.
            /// </summary>
            public void LogIssues(AnimancerState state, MatchType match)
            {
                var animator = state.Root?.Component.Animator;
                var newMatch = match;
                var message  = ObjectPool.AcquireStringBuilder();

                switch (match)
                {
                default:
                case MatchType.Unknown:
                    message.Append("The animation bindings are still being checked.");
                    Debug.Log(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Correct:
                    message.Append("No issues were found when comparing the properties animated by '")
                    .Append(state)
                    .Append("' to the Rig of '")
                    .Append(animator.name)
                    .Append("'.");
                    Debug.Log(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Empty:
                    message.Append("'")
                    .Append(state)
                    .Append("' does not animate any properties so it will not do anything.");
                    Debug.Log(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Warning:
                    message.Append("Possible Bug Detected: some of the details of '")
                    .Append(state)
                    .Append("' do not match the Rig of '")
                    .Append(animator.name)
                    .Append("' so the animation might not work correctly.");
                    newMatch = GetMatchType(animator, state, message);
                    Debug.LogWarning(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Error:
                    message.Append("Possible Bug Detected: the details of '")
                    .Append(state)
                    .Append("' do not match the Rig of '")
                    .Append(animator.name)
                    .Append("' so the animation might not work correctly.");
                    newMatch = GetMatchType(animator, state, message);
                    Debug.LogError(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;
                }

                if (newMatch != match)
                {
                    Debug.LogWarning($"{nameof(MatchType)} changed from {match} to {newMatch}" +
                                     " between the initial check and the button press.");
                }
            }
Esempio n. 12
0
 public override void OnPrePerform()
 {
     Agent.Memory.TryGetData(targetMemoryKey, out target);
     startTime = Time.time;
     navMeshAgent.stoppingDistance = stopDistance;
     navMeshAgent.updateRotation   = true;
     navMeshAgent.isStopped        = false;
     onPrePerform?.Invoke();
     Debug.Log("追逐");
     state = anim.Play(animationClip, 0.1f);
 }
Esempio n. 13
0
        /// <summary>Draws the Inspector for the given `state`.</summary>
        private void DoStateGUI(AnimancerState state)
        {
            if (!StateInspectors.TryGetValue(state, out var inspector))
            {
                inspector = state.CreateDrawer();
                StateInspectors.Add(state, inspector);
            }

            inspector.DoGUI();
            DoChildStatesGUI(state);
        }
Esempio n. 14
0
 /// <summary>
 /// 一个动画播放完成后的回调
 /// </summary>
 private void OnAnimFinished()
 {
     if (++m_Flag <= NodeDataForPlayAnims.Count - 1)
     {
         HandlePlayAnim(NodeDataForPlayAnims[m_Flag].StateTypes, NodeDataForPlayAnims[m_Flag].FadeOutTime);
     }
     else //说明所有动画都已经播放完毕
     {
         m_AnimancerState.OnEnd = null;
         m_AnimancerState       = null;
     }
 }
            /************************************************************************************************************************/

            /// <summary>
            /// Logs a description of the issues found when comparing the properties animated by the `state` to the
            /// properties that actually exist on the target <see cref="GameObject"/> and its children.
            /// </summary>
            public void LogIssues(AnimancerState state, MatchType match)
            {
                var animator = state.Root?.Component.Animator;
                var newMatch = match;
                var message  = ObjectPool.AcquireStringBuilder();

                switch (match)
                {
                default:
                case MatchType.Correct:
                    message.Append("No issues were found when comparing the properties animated by '")
                    .Append(state)
                    .Append("' to the Rig of '")
                    .Append(animator.name)
                    .Append("'.");
                    Debug.Log(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Empty:
                    message.Append("'")
                    .Append(state)
                    .Append("' does not animate any properties so it will not do anything.");
                    Debug.Log(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Warning:
                    message.Append("Some of the properties animated by '")
                    .Append(state)
                    .Append("' do not exist in the Rig of '")
                    .Append(animator.name)
                    .Append("' so they will have no effect.");
                    newMatch = GetMatchType(state, message);
                    Debug.LogWarning(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;

                case MatchType.Error:
                    message.Append("None of the properties animated by '")
                    .Append(state)
                    .Append("' exist in the Rig of '")
                    .Append(animator.name)
                    .Append("' so they will have no effect.");
                    newMatch = GetMatchType(state, message);
                    Debug.LogError(EditorGUIUtility.systemCopyBuffer = message.ReleaseToString(), animator);
                    break;
                }

                if (newMatch != match)
                {
                    Debug.LogWarning($"{nameof(MatchType)} changed from {match} to {newMatch}" +
                                     " between the initial check and the button press.");
                }
            }
        /// <summary>Draws the Inspector for the given `state`.</summary>
        private void DoStateGUI(AnimancerState state, IAnimancerComponent owner)
        {
            IAnimancerNodeDrawer Inspector;

            if (!StateInspectors.TryGetValue(state, out Inspector))
            {
                Inspector = state.GetDrawer();
                StateInspectors.Add(state, Inspector);
            }

            Inspector.DoGUI(owner);
            DoChildStatesGUI(state, owner);
        }
Esempio n. 17
0
 /// <summary>
 /// 一个动画播放完成后的回调
 /// </summary>
 private void OnAnimFinished()
 {
     if (++m_Flag <= NodeDataForPlayAnims.Count - 1)
     {
         HandlePlayAnim(NodeDataForPlayAnims[m_Flag].StateTypes, NodeDataForPlayAnims[m_Flag].FadeOutTime);
     }
     else //说明所有动画都已经播放完毕
     {
         this.TheUnitBelongTo.GetComponent <AnimationComponent>().PlayAnimByStackFsmCurrent();
         //Log.Info("栈式状态机已刷新,应该会衔接切换到正确的动画");
         this.m_Flag            = 0;
         m_AnimancerState.OnEnd = null;
         m_AnimancerState       = null;
     }
 }
Esempio n. 18
0
        /************************************************************************************************************************/

        /// <summary>Draws all child states of the `state`.</summary>
        private void DoChildStatesGUI(AnimancerState state)
        {
            EditorGUI.indentLevel++;

            foreach (var child in state)
            {
                if (child == null)
                {
                    continue;
                }

                DoStateGUI(child);
            }

            EditorGUI.indentLevel--;
        }
Esempio n. 19
0
            /************************************************************************************************************************/

            /// <summary>
            /// Called by <see cref="AnimancerPlayable.Transition"/> to apply the <see cref="Speed"/> and
            /// <see cref="StartTime"/>.
            /// </summary>
            public override void Apply(AnimancerState state)
            {
                state.OnEnd = OnEnd;
                state.Speed = _Speed;

                if (!float.IsNaN(_StartTime))
                {
                    if (_StartTimeIsNormalized)
                    {
                        state.NormalizedTime = _StartTime;
                    }
                    else
                    {
                        state.Time = _StartTime;
                    }
                }
            }
Esempio n. 20
0
            /************************************************************************************************************************/

            /// <summary>
            /// Called by <see cref="AnimancerPlayable.Play(ITransition)"/> to apply the <see cref="Speed"/>
            /// and <see cref="NormalizedStartTime"/>.
            /// </summary>
            public override void Apply(AnimancerState state)
            {
                base.Apply(state);

                if (!float.IsNaN(_Speed))
                {
                    state.Speed = _Speed;
                }

                if (!float.IsNaN(_NormalizedStartTime))
                {
                    state.NormalizedTime = _NormalizedStartTime;
                }
                else if (state.Weight == 0)
                {
                    state.NormalizedTime = AnimancerEvent.Sequence.GetDefaultNormalizedStartTime(_Speed);
                }
            }
Esempio n. 21
0
            /************************************************************************************************************************/

            /// <summary>
            /// Determines the <see cref="MatchType"/> representing the properties animated by the `state` in
            /// comparison to the properties that actually exist on the target <see cref="GameObject"/> and its
            /// children.
            /// <para></para>
            /// Also compiles a `message` explaining the differences if that paraneter is not null.
            /// </summary>
            public MatchType GetMatchType(Animator animator, AnimancerState state, StringBuilder message, bool forceGather = true)
            {
                using (ObjectPool.Disposable.AcquireSet <AnimationClip>(out var clips))
                {
                    state.GatherAnimationClips(clips);

                    var bindings         = message != null ? new Dictionary <EditorCurveBinding, bool>() : null;
                    var existingBindings = 0;

                    var match = default(MatchType);

                    if (animator.avatar == null)
                    {
                        message?.AppendLine()
                        .Append($"{LinePrefix}The {nameof(Animator)} has no {nameof(Avatar)}.");

                        if (animator.isHuman)
                        {
                            match = MatchType.Error;
                        }
                    }

                    foreach (var clip in clips)
                    {
                        var clipMatch = GetMatchType(clip, message, bindings, ref existingBindings, forceGather);
                        if (match < clipMatch)
                        {
                            match = clipMatch;
                        }
                    }

                    AppendBindings(message, bindings, existingBindings);

                    return(match);
                }
            }
Esempio n. 22
0
 public void Apply(AnimancerState state)
 {
 }
 void OnDisable()
 {
     CurrentAnimationState = null;
 }
Esempio n. 24
0
 public void PlayAttack()
 {
     animancerState_layer1 = animancer.Play(enemyData.GetAttackClip(), 0.25f);
 }
Esempio n. 25
0
        /************************************************************************************************************************/

        private void OnEnable()
        {
            Creature.Rigidbody.velocity += new Vector2(0, _Force);

            _AnimancerState = Creature.Animancer.Play(_Animation);
        }
Esempio n. 26
0
        /************************************************************************************************************************/

        protected virtual void OnEnable()
        {
            Creature.Rigidbody.velocity += new Vector2(0, CalculateJumpSpeed(_Height));

            AnimancerState = Creature.Animancer.Play(_Animation);
        }
Esempio n. 27
0
            /************************************************************************************************************************/

            public override void Apply(AnimancerState state)
            {
                base.Apply(state);
                state.Root.Component.Animator.applyRootMotion = _ApplyRootMotion;
            }