Пример #1
0
    // BLEND PLAY

    public void PlayAnimationBlend(
        string type, float weight, float time,
        AnimationBlendMode blendMode = AnimationBlendMode.Additive)
    {
        string currentAnimation = GetAnimation(type);

        if (isLegacy)
        {
            if (actor == null)
            {
                return;
            }

            Animation actorAnimation = actor.GetComponent <Animation>();

            if (actorAnimation == null)
            {
                return;
            }

            if (actorAnimation[currentAnimation] == null)
            {
                return;
            }

            if (isRunningClampAnimation)
            {
                return;
            }

            actorAnimation[currentAnimation].blendMode = blendMode;
            actorAnimation.Blend(currentAnimation, weight, time);
        }
    }
        internal void Init(SpriteAnimationClip clip, SpriteAnimation animation, string name)
        {
            ClearState();


            //set playing curve
            if (curve == null)
            {
                curve = new AnimationLinearCurve(
                    clip.playingCurve.startTime,
                    clip.playingCurve.startValue,
                    clip.playingCurve.endTime,
                    clip.playingCurve.endValue);
            }
            else
            {
                curve.SetTime(clip.playingCurve.startTime,
                              clip.playingCurve.startValue,
                              clip.playingCurve.endTime,
                              clip.playingCurve.endValue);
            }

            blendMode = AnimationBlendMode.Blend;

            wrapMode = clip.wrapMode;

            _clip      = clip;
            _animation = animation;


            if (clip.length <= 0f)
            {
                normalizedSpeed = 1f;
            }
            else
            {
                normalizedSpeed = 1f / length;
            }


            if (componentEnable == null)
            {
                componentEnable = new byte[clip.subComponents.Length + 1];
            }

            else if (componentEnable.Length < clip.subComponents.Length + 1)
            {
                componentEnable = new byte[clip.subComponents.Length + 1];
            }


            for (int i = 0, e = componentEnable.Length; i < e; i++)
            {
                componentEnable[i] = 1;
            }


            this.name = name;
        }
    private static int IntToEnum(IntPtr L)
    {
        int num = (int)LuaDLL.lua_tonumber(L, 1);
        AnimationBlendMode animationBlendMode = (AnimationBlendMode)num;

        ToLua.Push(L, animationBlendMode);
        return(1);
    }
Пример #4
0
    static int IntToEnum(IntPtr L)
    {
        int arg0             = (int)LuaDLL.lua_tonumber(L, 1);
        AnimationBlendMode o = (AnimationBlendMode)arg0;

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Пример #5
0
 public override void Reset()
 {
     this.gameObject = null;
     this.animName   = null;
     this.wrapMode   = WrapMode.Loop;
     this.blendMode  = AnimationBlendMode.Blend;
     this.speed      = 1f;
     this.layer      = 0;
 }
Пример #6
0
 public override void Reset()
 {
     gameObject = null;
     animName   = null;
     wrapMode   = WrapMode.Loop;
     blendMode  = AnimationBlendMode.Blend;
     speed      = 1.0f;
     layer      = 0;
 }
Пример #7
0
 public override void Reset()
 {
     this.gameObject = null;
     this.animName = null;
     this.wrapMode = WrapMode.Loop;
     this.blendMode = AnimationBlendMode.Blend;
     this.speed = 1f;
     this.layer = 0;
 }
		public override void Reset()
		{
			gameObject = null;
			animName = null;
			wrapMode = WrapMode.Loop;
			blendMode = AnimationBlendMode.Blend;
			speed = 1.0f;
			layer = 0;
		}
Пример #9
0
        } // WrapMode

        #endregion

        #region Constructor

        /// <summary>
        /// The AnimationState gives full control over animation blending.
        /// </summary>
        /// <remarks>
        /// In most cases the Animation interface is sufficient and easier to use. 
        /// Use the AnimationState if you need full control over the animation blending any playback process.
        /// The AnimationState interface allows you to modify speed, weight, time and layers while any animation is playing.
        /// You can also setup animation mixing and wrapMode.
        /// </remarks>
        public AnimationState(ModelAnimation modelAnimation)
        {
            this.modelAnimation = modelAnimation;
            enabled = true;
            weight = 1;
            time = 0;
            speed = 1;
            layer = 0;
            animationBlendMode = AnimationBlendMode.Blend;
            wrapMode = WrapMode.Default;
        } // AnimationState
Пример #10
0
        public bool SetBlendMode(string name, AnimationBlendMode mode)
        {
            AnimationState state = GetAnimationState(name);

            if (!state)
            {
                return(false);
            }

            state.SetBlendMode(mode);

            return(true);
        }
    private static int set_blendMode(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            AnimationState     animationState = (AnimationState)obj;
            AnimationBlendMode blendMode      = (AnimationBlendMode)((int)ToLua.CheckObject(L, 2, typeof(AnimationBlendMode)));
            animationState.blendMode = blendMode;
            result = 0;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index blendMode on a nil value");
        }
        return(result);
    }
    private static int get_blendMode(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            AnimationState     animationState = (AnimationState)obj;
            AnimationBlendMode blendMode      = animationState.blendMode;
            ToLua.Push(L, blendMode);
            result = 1;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index blendMode on a nil value");
        }
        return(result);
    }
Пример #13
0
    override public void ShowGUI()
    {
        method = (AnimMethodChar)EditorGUILayout.EnumPopup("Method:", method);

        isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer);
        if (!isPlayer)
        {
            animChar = (Char)EditorGUILayout.ObjectField("Character:", animChar, typeof(Char), true);
        }

        if (method == AnimMethodChar.PlayCustom || method == AnimMethodChar.StopCustom)
        {
            clip = (AnimationClip)EditorGUILayout.ObjectField("Clip:", clip, typeof(AnimationClip), true);

            if (method == AnimMethodChar.PlayCustom)
            {
                layer = (AnimLayer)EditorGUILayout.EnumPopup("Layer:", layer);

                if (layer == AnimLayer.Base)
                {
                    EditorGUILayout.LabelField("Blend mode:", "Blend");
                    playModeBase = (AnimPlayModeBase)EditorGUILayout.EnumPopup("Play mode:", playModeBase);
                }
                else
                {
                    blendMode = (AnimationBlendMode)EditorGUILayout.EnumPopup("Blend mode:", blendMode);
                    playMode  = (AnimPlayMode)EditorGUILayout.EnumPopup("Play mode:", playMode);
                }
            }

            fadeTime = EditorGUILayout.Slider("Transition time:", fadeTime, 0f, 1f);
            willWait = EditorGUILayout.Toggle("Pause until finish?", willWait);
        }

        else if (method == AnimMethodChar.SetStandard)
        {
            clip     = (AnimationClip)EditorGUILayout.ObjectField("Clip:", clip, typeof(AnimationClip), true);
            standard = (AnimStandard)EditorGUILayout.EnumPopup("Change:", standard);
        }

        AfterRunningOption();
    }
Пример #14
0
    override public void ShowGUI()
    {
        method = (AnimMethod)EditorGUILayout.EnumPopup("Method:", method);

        _anim = (Animation)EditorGUILayout.ObjectField("Object:", _anim, typeof(Animation), true);

        clip = (AnimationClip)EditorGUILayout.ObjectField("Clip:", clip, typeof(AnimationClip), true);

        if (method == AnimMethod.PlayCustom)
        {
            playMode  = (AnimPlayMode)EditorGUILayout.EnumPopup("Play mode:", playMode);
            blendMode = (AnimationBlendMode)EditorGUILayout.EnumPopup("Blend mode:", blendMode);
        }

        fadeTime = EditorGUILayout.Slider("Transition time:", fadeTime, 0f, 1f);

        willWait = EditorGUILayout.Toggle("Pause until finish?", willWait);

        AfterRunningOption();
    }
        internal void Clone(SpriteAnimationState other, string name)
        {
            ClearState();

            if (curve == null)
            {
                curve = new AnimationLinearCurve(
                    other.curve.startTime,
                    other.curve.startValue,
                    other.curve.endTime,
                    other.curve.endValue);
            }
            else
            {
                curve.SetTime(other.curve.startTime,
                              other.curve.startValue,
                              other.curve.endTime,
                              other.curve.endValue);
            }

            wrapMode = other.wrapMode;

            _clip      = other.clip;
            _animation = other._animation;

            normalizedSpeed = other.normalizedSpeed;

            componentEnable = new byte[clip.subComponents.Length + 1];
            for (int i = 0, e = componentEnable.Length; i < e; i++)
            {
                componentEnable[i] = 1;
            }

            _name   = name;
            _layer  = other._layer;
            _weight = other._weight;

            blendMode = AnimationBlendMode.Blend;

            isRemoving = false;
        }
        public void Dispose()
        {
            _controller = null;
            _clipId     = null;
            _weight     = 1f;
            _speed      = 1f;
            _layer      = 0;
            _wrapMode   = UnityEngine.WrapMode.Default;
            _blendMode  = AnimationBlendMode.Blend;
            _mask       = null;
            this.UnregisterTimeScaleChangedEvent();
            _timeSupplier = null;

            _state = null;
            if (_scheduler != null)
            {
                _scheduler.Clear();
            }

            _pool.Release(this);
        }
Пример #17
0
        private static void AddAnimClip(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, Transform mixingBone)
        {
            if (clip != null)
            {
                // Initialises a clip
                _animation.AddClip (clip, clip.name);

                if (mixingBone != null)
                {
                    _animation [clip.name].AddMixingTransform (mixingBone);
                }

                // Set up the state
                _animation [clip.name].layer = layer;
                _animation [clip.name].normalizedTime = 0f;
                _animation [clip.name].blendMode = blendMode;
                _animation [clip.name].wrapMode = wrapMode;
                _animation [clip.name].enabled = true;
            }
        }
Пример #18
0
 /**
  * <summary>Initialises and plays a legacy AnimationClip on an Animation component, starting from a set point.</summary>
  * <param name = "_animation">The Animation component</param>
  * <param name = "layer">The layer to play the animation on</param>
  * <param name = "clip">The AnimatonClip to play</param>
  * <param name = "blendMode">The animation's AnimationBlendMode</param>
  * <param name = "wrapMode">The animation's WrapMode</param>
  * <param name = "fadeTime">The transition time to the new animation</param>
  * <param name = "mixingBone">The transform to set as the animation's mixing transform</param>
  * <param name = "normalisedFrame">How far along the timeline the animation should start from (0 to 1)</param>
  */
 public static void PlayAnimClipFrame(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, float fadeTime, Transform mixingBone, float normalisedFrame)
 {
     if (clip != null)
     {
         AddAnimClip (_animation, layer, clip, blendMode, wrapMode, mixingBone);
         _animation [clip.name].normalizedTime = normalisedFrame;
         _animation [clip.name].speed *= 1f;
         _animation.Play (clip.name);
         CleanUnusedClips (_animation);
     }
 }
Пример #19
0
 /**
  * <summary>Initialises and plays a legacy AnimationClip on an Animation component.</summary>
  * <param name = "_animation">The Animation component</param>
  * <param name = "layer">The layer to play the animation on</param>
  * <param name = "clip">The AnimatonClip to play</param>
  * <param name = "blendMode">The animation's AnimationBlendMode</param>
  * <param name = "wrapMode">The animation's WrapMode</param>
  * <param name = "fadeTime">The transition time to the new animation</param>
  * <param name = "mixingBone">The transform to set as the animation's mixing transform</param>
  * <param name = "reverse">True if the animation should be reversed</param>
  */
 public static void PlayAnimClip(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode = AnimationBlendMode.Blend, WrapMode wrapMode = WrapMode.ClampForever, float fadeTime = 0f, Transform mixingBone = null, bool reverse = false)
 {
     if (clip != null)
     {
         AddAnimClip (_animation, layer, clip, blendMode, wrapMode, mixingBone);
         if (reverse)
         {
             _animation[clip.name].speed *= -1f;
         }
         _animation.CrossFade (clip.name, fadeTime);
         CleanUnusedClips (_animation);
     }
 }
Пример #20
0
    public static void PlayAnimClip(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, float fadeTime, Transform mixingBone)
    {
        // Initialises and crossfades a clip

        AddAnimClip(_animation, layer, clip, blendMode, wrapMode, mixingBone);

        _animation.CrossFade(clip.name, fadeTime);

        CleanUnusedClips(_animation);
    }
Пример #21
0
 public void SetAnimationState(string animName, int layer, float weight, float speed, AnimationBlendMode mode)
 {
     this.animation[animName].layer     = layer;
     this.animation[animName].weight    = weight;
     this.animation[animName].speed     = speed;
     this.animation[animName].blendMode = mode;
 }
Пример #22
0
        public static void AddAnimClip(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, Transform mixingBone)
        {
            if (clip != null)
            {
                // Initialises a clip
                _animation.AddClip(clip, clip.name);

                if (mixingBone != null)
                {
                    _animation [clip.name].AddMixingTransform(mixingBone);
                }

                // Set up the state
                _animation [clip.name].layer          = layer;
                _animation [clip.name].normalizedTime = 0f;
                _animation [clip.name].blendMode      = blendMode;
                _animation [clip.name].wrapMode       = wrapMode;
                _animation [clip.name].enabled        = true;
            }
        }
Пример #23
0
 /// <summary>
 /// Set blending mode.
 /// </summary>
 private void SetBlendMode(AnimationBlendMode mode)
 {
     Runtime.ValidateRefCounted(this);
     AnimationState_SetBlendMode(handle, mode);
 }
Пример #24
0
 internal static extern void AnimationState_SetBlendMode(IntPtr handle, AnimationBlendMode mode);
Пример #25
0
		public static void PlayAnimClip (Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, float fadeTime, Transform mixingBone, bool reverse)
		{
			// Initialises and crossfades a clip
			
			if (clip != null)
			{
				AddAnimClip (_animation, layer, clip, blendMode, wrapMode, mixingBone);
				if (reverse)
				{
					_animation[clip.name].speed *= -1f;
				}
				_animation.CrossFade (clip.name, fadeTime);
				CleanUnusedClips (_animation);
			}
		}
Пример #26
0
 internal static extern bool AnimationController_SetBlendMode(IntPtr handle, string name, AnimationBlendMode mode);
Пример #27
0
        public static void PlayAnimClip(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, float fadeTime, Transform mixingBone, bool reverse)
        {
            // Initialises and crossfades a clip

            if (clip != null)
            {
                AddAnimClip(_animation, layer, clip, blendMode, wrapMode, mixingBone);
                if (reverse)
                {
                    _animation[clip.name].speed *= -1f;
                }
                _animation.CrossFade(clip.name, fadeTime);
                CleanUnusedClips(_animation);
            }
        }
Пример #28
0
    override public float Run()
    {
        if (isPlayer)
        {
            animChar = GameObject.FindWithTag(Tags.player).GetComponent <Char>();
        }

        if (!isRunning)
        {
            isRunning = true;


            if (animChar)
            {
                if (method == AnimMethodChar.PlayCustom && clip)
                {
                    AdvGame.CleanUnusedClips(animChar.animation);

                    WrapMode  wrap            = WrapMode.Once;
                    Transform mixingTransform = null;

                    if (layer == AnimLayer.Base)
                    {
                        animChar.charState = CharState.Custom;
                        blendMode          = AnimationBlendMode.Blend;
                        playMode           = (AnimPlayMode)playModeBase;
                    }
                    else if (layer == AnimLayer.UpperBody)
                    {
                        mixingTransform = animChar.upperBodyBone;
                    }
                    else if (layer == AnimLayer.LeftArm)
                    {
                        mixingTransform = animChar.leftArmBone;
                    }
                    else if (layer == AnimLayer.RightArm)
                    {
                        mixingTransform = animChar.rightArmBone;
                    }
                    else if (layer == AnimLayer.Neck || layer == AnimLayer.Head || layer == AnimLayer.Face || layer == AnimLayer.Mouth)
                    {
                        mixingTransform = animChar.neckBone;
                    }

                    if (playMode == AnimPlayMode.PlayOnceAndClamp)
                    {
                        wrap = WrapMode.ClampForever;
                    }
                    else if (playMode == AnimPlayMode.Loop)
                    {
                        wrap = WrapMode.Loop;
                    }

                    AdvGame.PlayAnimClip(animChar.GetComponent <Animation>(), (int)layer, clip, blendMode, wrap, fadeTime, mixingTransform);
                }

                else if (method == AnimMethodChar.StopCustom && clip)
                {
                    if (clip != animChar.idleAnim && clip != animChar.walkAnim)
                    {
                        animChar.animation.Blend(clip.name, 0f, fadeTime);
                    }
                }

                else if (method == AnimMethodChar.ResetToIdle)
                {
                    animChar.ResetBaseClips();
                    animChar.charState = CharState.Idle;
                    AdvGame.CleanUnusedClips(animChar.animation);
                }

                else if (method == AnimMethodChar.SetStandard && clip)
                {
                    if (standard == AnimStandard.Idle)
                    {
                        animChar.idleAnim = clip;
                    }

                    else if (standard == AnimStandard.Walk)
                    {
                        animChar.walkAnim = clip;
                    }

                    else if (standard == AnimStandard.Run)
                    {
                        animChar.runAnim = clip;
                    }
                }


                if (willWait && clip)
                {
                    if (method == AnimMethodChar.PlayCustom)
                    {
                        return(defaultPauseTime);
                    }
                    else if (method == AnimMethodChar.StopCustom)
                    {
                        return(fadeTime);
                    }
                }
            }

            return(0f);
        }
        else
        {
            if (animChar.animation[clip.name] && animChar.animation[clip.name].normalizedTime < 1f && animChar.animation.IsPlaying(clip.name))
            {
                return(defaultPauseTime);
            }
            else
            {
                isRunning = false;

                if (playMode == AnimPlayMode.PlayOnce)
                {
                    animChar.animation.Blend(clip.name, 0f, fadeTime);

                    if (layer == AnimLayer.Base && method == AnimMethodChar.PlayCustom)
                    {
                        animChar.charState = CharState.Idle;
                        animChar.ResetBaseClips();
                    }
                }

                AdvGame.CleanUnusedClips(animChar.animation);

                return(0f);
            }
        }
    }
Пример #29
0
 /**
  * <summary>Initialises and plays a legacy AnimationClip on an Animation component.</summary>
  * <param name = "_animation">The Animation component</param>
  * <param name = "layer">The layer to play the animation on</param>
  * <param name = "clip">The AnimatonClip to play</param>
  * <param name = "blendMode">The animation's AnimationBlendMode</param>
  * <param name = "wrapMode">The animation's WrapMode</param>
  * <param name = "fadeTime">The transition time to the new animation</param>
  * <param name = "mixingBone">The transform to set as the animation's mixing transform</param>
  * <param name = "reverse">True if the animation should be reversed</param>
  */
 public static void PlayAnimClip(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode = AnimationBlendMode.Blend, WrapMode wrapMode = WrapMode.ClampForever, float fadeTime = 0f, Transform mixingBone = null, bool reverse = false)
 {
     if (clip != null)
     {
         AddAnimClip(_animation, layer, clip, blendMode, wrapMode, mixingBone);
         if (reverse)
         {
             _animation[clip.name].speed *= -1f;
         }
         _animation.CrossFade(clip.name, fadeTime);
         CleanUnusedClips(_animation);
     }
 }
Пример #30
0
        public static void PlayAnimClipFrame(Animation _animation, int layer, AnimationClip clip, AnimationBlendMode blendMode, WrapMode wrapMode, float fadeTime, Transform mixingBone, float normalisedFrame)
        {
            // Initialises and plays the last frame of a clip

            if (clip != null)
            {
                AddAnimClip(_animation, layer, clip, blendMode, wrapMode, mixingBone);
                _animation [clip.name].normalizedTime = normalisedFrame;
                _animation [clip.name].speed         *= 1f;
                _animation.Play(clip.name);
                CleanUnusedClips(_animation);
            }
        }
Пример #31
0
 /// <summary>
 /// Set animation blending mode. Return true on success.
 /// </summary>
 public bool SetBlendMode(string name, AnimationBlendMode mode)
 {
     Runtime.ValidateRefCounted(this);
     return(AnimationController_SetBlendMode(handle, name, mode));
 }