Beispiel #1
0
    /// <summary>从Animator获取当前动画信息 </summary>
    public static AnimatorFrameInfo GetAnimatorFrameInfo(this Animator animator)
    {
        int               stateHashName     = animator.GetCurrentAnimatorStateInfo(0).fullPathHash;
        float             normalizedTime    = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
        AnimatorFrameInfo animatorFrameInfo = new AnimatorFrameInfo(stateHashName, normalizedTime);

        Array.ForEach(animator.parameters, (animatorParameter) => {
            //特殊的状态不进行倒流
            if (animatorParameter.name == "AnimatorSpeed" || animatorParameter.name == "TimeBacking")
            {
                return;
            }
            switch (animatorParameter.type)
            {
            case AnimatorControllerParameterType.Bool:
                animatorFrameInfo.AddBool(animatorParameter.name, animator.GetBool(animatorParameter.name));
                break;

            case AnimatorControllerParameterType.Int:
                animatorFrameInfo.AddInt(animatorParameter.name, animator.GetInteger(animatorParameter.name));
                break;

            case AnimatorControllerParameterType.Float:
                animatorFrameInfo.AddFloat(animatorParameter.name, animator.GetFloat(animatorParameter.name));
                break;

            default:
                break;
            }
        });
        return(animatorFrameInfo);
    }
Beispiel #2
0
    public void B_Update()
    {
        AnimatorFrameInfo animatorFrameInfo = animatorFrameInfos.Last.Value;

        animatorFrameInfos.RemoveLast();
        if (animator.GetCurrentAnimatorStateInfo(0).fullPathHash != animatorFrameInfo.StateNameHash)
        {
            animator.Play(animatorFrameInfo.StateNameHash, animatorFrameInfo.LayerIndex, animatorFrameInfo.NormalizedTime);
        }
        animator.SetAnimatorInfo(animatorFrameInfo);
    }
Beispiel #3
0
 /// <summary>设置Animator的信息 </summary>
 public static void SetAnimatorInfo(this Animator animator, AnimatorFrameInfo animatorFrameInfo)
 {
     animatorFrameInfo.boolParameters.ForEach((kvp) => {
         animator.SetBool(kvp.Key, kvp.Value);
     });
     animatorFrameInfo.intParameters.ForEach((kvp) => {
         animator.SetInteger(kvp.Key, kvp.Value);
     });
     animatorFrameInfo.floatParameters.ForEach((kvp) => {
         animator.SetFloat(kvp.Key, kvp.Value);
     });
 }
Beispiel #4
0
    private void Update()
    {
        if (TimeBackManager.Instance.IsBacking)
        {
            return;
        }
        if (animatorFrameInfos.Count == TimeBackManager.MaxFrameCount)
        {
            animatorFrameInfos.RemoveFirst();
        }
        AnimatorFrameInfo animatorFrameInfo = animator.GetAnimatorFrameInfo();

        animatorFrameInfos.AddLast(animatorFrameInfo);
    }