Exemplo n.º 1
0
    public override void ClearAnimation(string key = "", bool rebind = true)
    {
        if (rebind == true)
        {
            if (m_anim != null)
            {
                m_anim.Rebind();
            }
        }

        int count = _animStateQueue.Count;

        for (int i = 0; i < count; ++i)
        {
            if (_animStateQueue.Count > 0)
            {
                AnimStateBase state = _animStateQueue.Peek();

                if (state.key.Equals(key) || string.IsNullOrEmpty(key))
                {
                    _animStateQueue.Dequeue();
                }
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// change animation state
    /// </summary>
    /// <param name="animParam"></param>
    protected override void ChangeAnim(AnimStateBase state)
    {
        List <PlayAnimParam> animParam = ((AnimState)state).playAnimParams;

        string aniTemp = "";

        for (int i = 0; i < animParam.Count; i++)
        {
            PlayAnimParam param = (PlayAnimParam)animParam[i];

            string aniName = param.aniName;

            if (m_anim[aniName] != null)
            {
                m_anim[aniName].wrapMode = param.warpMode;

                if (param.isForcePlay)
                {
                    m_anim.CrossFade(aniName, param.fadeLength);
                }
                else
                {
                    m_anim.CrossFadeQueued(aniName, param.fadeLength);
                }

                aniTemp += "/" + aniName;
            }
        }

        Debug.Log("#Animation# Play Anim : " + aniTemp);
    }
Exemplo n.º 3
0
    /// <summary>
    /// change animation state
    /// </summary>
    /// <param name="animParam"></param>
    protected override void ChangeAnim(AnimStateBase state)
    {
        if (m_anim == null)
        {
            return;
        }

        List <PlayAnimParam> animParam = ((AnimState)state).playAnimParams;

        string aniTemp = "";

        for (int i = 0; i < animParam.Count; i++)
        {
            string             aniName = ((PlayAnimParam)animParam[i]).aniName;
            int                value   = ((PlayAnimParam)animParam[i]).value;
            PlayAnimParam.Type type    = ((PlayAnimParam)animParam[i]).type;

            if (type == PlayAnimParam.Type.Trigger)
            {
                m_anim.SetTrigger(((PlayAnimParam)animParam[i]).paramId);
                aniTemp += "/" + aniName;
                continue;
            }

            m_anim.SetInteger(((PlayAnimParam)animParam[i]).paramId, value);
            aniTemp += "/" + aniName + ":" + value;
        }

        Debug.Log(gameObject.name + " # Play Anim # " + aniTemp);
    }
Exemplo n.º 4
0
    private void Update()
    {
        // Ensure current state is not null
        Debug.Assert(currentAnimState != null, "Current animation state is null", gameObject);

        CurrentState = animation[currentAnimState.AnimationName];

        // Update current state and check if the current state  needs to transition to a new state
        var result = currentAnimState?.OnStateUpdate(this, CurrentState == null ? false : CurrentState.enabled);

        if (result != null)
        {
            currentAnimState = result.Target;
            currentAnimState.OnStateEnter(this);

            Debug.Assert(!string.IsNullOrEmpty(currentAnimState.AnimationName), "Animation name can not be null or empty.");

            CurrentState = animation[currentAnimState.AnimationName];

            // Set the time of the state to the EnterTime if specified
            if (animation[currentAnimState.AnimationName] != null)
            {
                animation.Play(currentAnimState.AnimationName);
                CurrentState.normalizedTime = result.HasExitTime ? result.EnterTime : CurrentState.normalizedTime;
            }
        }

        if (CurrentState != null)
        {
            LastUpdateTime = CurrentState.normalizedTime;
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// animState push
    /// </summary>
    public void PushAnimation(string key)
    {
        AnimStateBase state = GetAnimState(key);

        if (state != null)
        {
            _animStateQueue.Enqueue(state);
        }
    }
Exemplo n.º 6
0
    /// <summary>
    ///  animation state find
    /// </summary>
    /// <param name="_key"></param>
    /// <returns></returns>
    public AnimStateBase GetAnimState(string _key)
    {
        int key = CRC32.GetHashForAnsi(_key);

        AnimStateBase state = null;

        dic_animStates.TryGetValue(key, out state);

        return(state);
    }
Exemplo n.º 7
0
    /// <summary>
    ///
    /// </summary>
    private void ProcessActionState()
    {
        if (_animStateQueue.Count > 0)
        {
            AnimStateBase state = _animStateQueue.Peek();

            ChangeAnim(state);

            _animStateQueue.Dequeue();
        }
    }
Exemplo n.º 8
0
    private void Start()
    {
        currentAnimState = AnimationManager.Instance.IdleState;
        currentAnimState.OnStateEnter(this);

        Debug.Assert(!string.IsNullOrEmpty(currentAnimState.AnimationName), "Animation name can not be null or empty.");
        animation.Play(currentAnimState.AnimationName);

        rootBone = transform.Find("Bip01");
        if (rootBone == null)
        {
            rootBone = transform.Find("Root Bone");
        }

        // Set some values
        previousRootPosition = rootBone.position;
        rootOffset           = rootBone.localPosition;
        CalculateMovementSpeed();
    }
Exemplo n.º 9
0
    /// <summary>
    /// Change animations and events
    /// </summary>
    protected void ResetAnimState(AnimStateBase[] animStates)
    {
        dic_animStates.Clear();

        for (int i = 0; i < animStates.Length; ++i)
        {
            animStates[i].Init();

            int key = CRC32.GetHashForAnsi(animStates[i].key);

            AnimStateBase state = null;

            if (!dic_animStates.TryGetValue(key, out state))
            {
                dic_animStates.Add(key, animStates[i]);
            }
            else
            {
                dic_animStates[key] = animStates[i];
            }
        }
    }
Exemplo n.º 10
0
 /// <summary>
 /// change animation state
 /// </summary>
 /// <param name="animParam"></param>
 protected abstract void ChangeAnim(AnimStateBase state);