Beispiel #1
0
        ///blend out all animations on a single layer
        public void BlendOutLayer(int layer, float speed) // Fade out all animations on a layer at a certain speed
        {
            for (int i = 0; i < stateData.Count; i++)
            {
                AnimationStateData sData = stateData[i];

                if (sData.State.layer == layer)
                {
                    sData.targetWeight = 0;
                    sData.blendSpeed   = speed;
                }
            }
        }
Beispiel #2
0
        public float GetNormalizedTime(AnimationNode d)
        {
            if (d == null)
            {
                return(0);
            }
            if (!animationLookup.ContainsKey(d))
            {
                AddAnimation(d);
            }
            AnimationStateData sData = animationLookup[d];

            return(sData.State.normalizedTime);
        }
Beispiel #3
0
        public float Weight(AnimationNode d)
        {
            if (d != null)
            {
                if (!animationLookup.ContainsKey(d))
                {
                    AddAnimation(d);
                }
                AnimationStateData sData = animationLookup[d];
                return(sData.State.weight);
            }

            //Debug.LogWarning("AnimationNode is null, Equipment is probably misconfigured");
            return(0);
        }
Beispiel #4
0
        public bool IsPlaying(AnimationNode d)
        {
            if (d != null)
            {
                if (!animationLookup.ContainsKey(d))
                {
                    AddAnimation(d);
                }
                AnimationStateData sData = animationLookup[d];
                return(sData.State.enabled);
            }

            //Debug.LogWarning("AnimationNode is null, Equipment is probably misconfigured");
            return(false);
        }
Beispiel #5
0
        public void StopAnimationsByLayer(int layer)    // immediately stop all animations on a layer
        {
            for (int i = 0; i < stateData.Count; i++)
            {
                AnimationStateData sData = stateData[i];

                if (sData.State.layer == layer)
                {
                    sData.targetWeight  = 0;
                    sData.State.enabled = false;
                    sData.State.weight  = 0;
                    sData.State.time    = 0.0f;
                }
            }
        }
Beispiel #6
0
        public void SetNormalizedTime(AnimationNode d, float normalizedTime)
        {
            if (d == null)
            {
                return;
            }
            if (!animationLookup.ContainsKey(d))
            {
                AddAnimation(d);
            }
            AnimationStateData sData = animationLookup[d];

            sData.State.normalizedTime = normalizedTime;
            sData.State.enabled        = true;
        }
Beispiel #7
0
        public void SetPlaybackSpeed(AnimationNode d, float targetSpeed)
        {
            if (d != null)
            {
                if (!animationLookup.ContainsKey(d))
                {
                    AddAnimation(d);
                }
                AnimationStateData sData = animationLookup[d];

                sData.State.speed = sData.DefaultSpeed * targetSpeed;
                //		Debug.Log(sData.State.weight);
            }
            else
            {
                //Debug.LogWarning("AnimationNode is null, Equipment is probably misconfigured");
            }
        }
Beispiel #8
0
        public void SetBlendWeight(AnimationNode d, float targetWeight)
        {
            if (d != null)
            {
                if (!animationLookup.ContainsKey(d))
                {
                    AddAnimation(d);
                }
                AnimationStateData sData = animationLookup[d];

                sData.targetWeight  = targetWeight;
                sData.State.enabled = true;
                sData.State.weight  = sData.targetWeight;
                //		Debug.Log(sData.State.weight);
            }
            else
            {
                //Debug.LogWarning("AnimationNode is null, Equipment is probably misconfigured");
            }
        }
Beispiel #9
0
        public void StopAnimation(AnimationNode d)
        {
            if (d != null)
            {
                if (!animationLookup.ContainsKey(d))
                {
                    AddAnimation(d);
                }

                AnimationStateData sData = animationLookup[d];
                sData.targetWeight = 0;         //set target weight to 0

                sData.State.time    = 0.0f;     //Set the time to 0
                sData.State.weight  = 0;        //turn the clip weight to 0
                sData.State.enabled = false;    //turn the animation on
                //			desc.autoFade = false;
            }
            else
            {
                //Debug.LogWarning("AnimationNode is null, Equipment is probably misconfigured");
            }
        }
Beispiel #10
0
        private void Update()
        {
            for (int i = 0; i < stateData.Count; i++)
            {
                AnimationStateData sData = stateData[i];

                if (sData.State.weight == 0 && sData.State.wrapMode == WrapMode.Once)
                {
                    // A hack for 'Once' mode, prevents a "once" animation from continually blending in
                    sData.targetWeight = 0;
                }

                //If a state has not reached its target weight
                if (sData.State.weight != sData.targetWeight)
                {
                    float deltaWeight      = (sData.targetWeight - sData.State.weight);
                    float maxBlendDistance = sData.blendSpeed * Time.deltaTime; //maximum allowed distance

                    if (Mathf.Abs(deltaWeight) > maxBlendDistance)              //If weight greater than max, clamp for linear blend
                    {
                        sData.State.weight = sData.State.weight + Mathf.Sign(deltaWeight) * maxBlendDistance;
//					Debug.Log(sData.State.weight + " : " + sData.State + ": "+ sData.targetWeight);
                    }
                    else
                    {
                        //You've reached the end of the blend - assign the value directly
                        sData.State.weight = sData.targetWeight;
//					Debug.Log(sData.State.weight + " done: " + sData.State + ": "+ sData.targetWeight);
                    }
                }
                if (sData.State.weight == 0 && sData.targetWeight == 0)
                {
                    sData.State.enabled = false;
                    //Debug.Log(sData.State.name);
                }
            }
        }
Beispiel #11
0
        public void BlendAnimation(AnimationNode d, float targetWeight, float blendSpeed)
        {
            if (d != null)
            {
                if (!animationLookup.ContainsKey(d))
                {
                    AddAnimation(d);
                }
                AnimationStateData sData = animationLookup[d];

                //		desc.autoFade = false;
                //		sData.State.speed = sData.DefaultSpeed;
                if (sData.targetWeight != targetWeight)          //also check blendSpeed?
                //This is a hack to get their once mode to work//
                {
                    if (sData.State.weight == 0 && sData.State.wrapMode == WrapMode.Once)
                    {
                        sData.State.weight = 0.01f;
                    }

                    //We want all other animations that are playing to fade out at the speed this one fades in//
                    //				KillTargetWeightsByLayer(desc.state.layer, blendSpeed);

                    sData.targetWeight  = targetWeight;
                    sData.blendSpeed    = blendSpeed;
                    sData.State.enabled = true;
                }
                else if (sData.targetWeight > 0)
                {
                    sData.State.enabled = true;
                }
            }
            else
            {
                //Debug.LogWarning("AnimationNode is null, Equipment is probably misconfigured");
            }
        }