Update() public method

public Update ( ) : void
return void
    public static bool Play(Animator anim, string name, float speed = 1.0f, float time = 0.0f)
    {
        if (!anim)
        {
            return false;
        }

        // Enable animator
        if (!anim.enabled)
        {
            anim.enabled = true;
        }

        anim.speed = speed;
        anim.Play(name, -1, time);
        anim.Update(0.0f); // Update for the latest state

        return true;
    }
Example #2
0
    void TestAnis()
    {
        ani = sellast.GetComponentInChildren<Animator>();
        Animation aniold = sellast.GetComponentInChildren<Animation>();
        SkinnedMeshRenderer[] skins = sellast.GetComponentsInChildren<SkinnedMeshRenderer>();

        GUILayout.Label("Find Ani:" + (ani != null) + ", skinmesh count=" + skins.Length);
        if (ani == null)
        {
            GUILayout.Label("Need Animator Component");
            if(aniold!=null)
            {
                GUILayout.Label("You have a old Animation Component.But we only support Animator.");

            }
            return;
        }
        List<AnimationClip> anis = new List<AnimationClip>();

        var ac = ani.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
        FindAllAniInControl(ac, anis);

        foreach (var a in anis)
        {
            if (GUILayout.Button("haveani:" + a.name, GUILayout.MinWidth(1)))
            {
                _selectClip = a;
                anistart = 0;
                aniend = a.length;
                bPlay = false;
                //ani.Play(a.name, 0, 0);
            }
        }
        if(_selectClip)
        {
            var an = ani.GetCurrentAnimatorStateInfo(0);
            anistart = GUILayout.HorizontalSlider(anistart, 0, _selectClip.length, GUILayout.MinHeight(1));
            if (anistart >= aniend) anistart = aniend;
            aniend = GUILayout.HorizontalSlider(aniend, 0, _selectClip.length, GUILayout.MinHeight(1));
            if (aniend <= anistart) aniend = anistart;
            aninow = GUILayout.HorizontalSlider(aninow, anistart, aniend, GUILayout.MinHeight(1));
            if (!bPlay)
            {
                ani.Play(_selectClip.name, 0, 0);
                ani.speed = 1.0f;
                ani.Update(aninow);
            }
            bPlay = GUILayout.Toggle(bPlay, "Play", GUILayout.MaxWidth(100));
        }
    }
 private void SyncAnimation(Animator animator, float normalizedTime)
 {
     animator.Play(0, -1, normalizedTime);
     animator.Update(Time.deltaTime);
 }