Пример #1
0
        //SkeletonAnimation

        /*
         *	Int Value:		0 sets ghostingEnabled to false, 1 sets ghostingEnabled to true
         *	Float Value:	Values greater than 0 set the spawnRate equal the float value
         *	String Value:	Pass RGBA hex color values in to set the color property.  IE:   "A0FF8BFF"
         */
        void OnEvent(Spine.TrackEntry trackEntry, Spine.Event e)
        {
            if (e.Data.Name == "Ghosting")
            {
                ghostingEnabled = e.Int > 0;
                if (e.Float > 0)
                {
                    spawnRate = e.Float;
                }
                if (e.String != null)
                {
                    this.color = HexToColor(e.String);
                }
            }
        }
Пример #2
0
        //SkeletonAnimation

        /*
         *	Int Value:		0 sets ghostingEnabled to false, 1 sets ghostingEnabled to true
         *	Float Value:	Values greater than 0 set the spawnRate equal the float value
         *	String Value:	Pass RGBA hex color values in to set the color property.  IE:   "A0FF8BFF"
         */
        void OnEvent(Spine.TrackEntry trackEntry, Spine.Event e)
        {
            if (e.Data.Name.Equals("Ghosting", System.StringComparison.Ordinal))
            {
                ghostingEnabled = e.Int > 0;
                if (e.Float > 0)
                {
                    spawnRate = e.Float;
                }

                if (!string.IsNullOrEmpty(e.stringValue))
                {
                    this.color = HexToColor(e.String);
                }
            }
        }
Пример #3
0
        public async void NewAnimation(GameObject Rander, SkillData skillData)
        {
            GameObject Animation = Rander.GetChild("Animation", true);

            Spine.Unity.SkeletonAnimation skeletonAnimation = Animation.AddComponent <Spine.Unity.SkeletonAnimation>();
            skeletonAnimation.skeletonDataAsset = await AssetManager.LoadAssetAsync <Spine.Unity.SkeletonDataAsset>(skillData.SkeletonDataAssetPath);

            var skeletonAnimationRenderer = skeletonAnimation.GetComponent <Renderer>();

            skeletonAnimationRenderer.enabled = false;
            DelayFunc(() =>
            {
                skeletonAnimationRenderer.enabled = true;
            }, 0.00001f);
            skeletonAnimation.initialSkinName = skillData.SkinName;
            skeletonAnimation.Initialize(true);
            Spine.TrackEntry TrackEntry = skeletonAnimation.state.SetAnimation(0, skillData.AnimationName, true);
            Animation.AddComponent <SortRenderer>();
        }
        // Use this for initialization
        void Start()
        {
            valueMonitorPool.Clear();
            skeletonAnimation = GetComponent <SkeletonAnimation>();
            Spine.TrackEntry trackEntry = skeletonAnimation.state.GetCurrent(0);
            switch (speedType)
            {
            case SpeedType.Fixedanimatorspeed:
                trackEntry.TimeScale = animator.speed;
                break;

            case SpeedType.Fixed:
                trackEntry.TimeScale = speed;
                break;

            case SpeedType.animatorspeed:
                trackEntry.TimeScale = animator.speed;
                valueMonitorPool.AddMonitor(() =>
                {
                    return(animator.speed);
                }, (float from, float to) =>
                {
                    trackEntry.TimeScale = to;
                });
                break;

            default:
                break;
            }
            valueMonitorPool.AddMonitor(() =>
            {
                return(trackEntry.TrackTime);
            }, (float from, float to) =>
            {
                float dsda = trackEntry.AnimationEnd;
                if (to >= dsda)
                {
                    Tools.Destroy(gameObject);
                }
            });
        }
Пример #5
0
        public override void OnStateEnter(
            Animator animator,
            AnimatorStateInfo stateInfo,
            int layerIndex)
        {
            if (!_controller)
            {
                _controller = animator.GetComponent <SpineController>();
                if (!_controller)
                {
                    throw new NotFoundComponentException <SpineController>();
                }
            }

            if (!_skeletonAnimation)
            {
                _skeletonAnimation = animator.GetComponentInChildren <SkeletonAnimation>();
                if (!_skeletonAnimation)
                {
                    throw new NotFoundComponentException <SkeletonAnimation>();
                }

                _spineAnimationState = _skeletonAnimation.state;
            }

            try
            {
                _trackEntry           = _controller.PlayAnimationForState(animationClip, layer);
                _trackEntry.TimeScale = timeScale;
                _normalizedTime       = 0f;
            }
            catch (KeyNotFoundException)
            {
                Debug.LogError($"{nameof(_trackEntry)} is null!");
            }
        }
Пример #6
0
 void HandleEvent(Spine.TrackEntry trackEntry, Spine.Event e)
 {
     footstepAudioSource.Stop();
     footstepAudioSource.pitch = GetRandomPitch(0.2f);
     footstepAudioSource.Play();
 }
Пример #7
0
        // NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties.
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            var spineComponent = playerData as SkeletonAnimation;

            if (spineComponent == null)
            {
                return;
            }

            var skeleton = spineComponent.Skeleton;
            var state    = spineComponent.AnimationState;

            if (!Application.isPlaying)
            {
                                #if SPINE_EDITMODEPOSE
                PreviewEditModePose(playable, spineComponent);
                                #endif
                return;
            }

            int inputCount = playable.GetInputCount();

            // Ensure correct buffer size.
            if (this.lastInputWeights == null || this.lastInputWeights.Length < inputCount)
            {
                this.lastInputWeights = new float[inputCount];

                for (int i = 0; i < inputCount; i++)
                {
                    this.lastInputWeights[i] = default(float);
                }
            }
            var lastInputWeights = this.lastInputWeights;

            // Check all clips. If a clip that was weight 0 turned into weight 1, call SetAnimation.
            for (int i = 0; i < inputCount; i++)
            {
                float lastInputWeight = lastInputWeights[i];
                float inputWeight     = playable.GetInputWeight(i);
                bool  trackStarted    = inputWeight > lastInputWeight;
                lastInputWeights[i] = inputWeight;

                if (trackStarted)
                {
                    ScriptPlayable <SpineAnimationStateBehaviour> inputPlayable = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(i);
                    SpineAnimationStateBehaviour clipData = inputPlayable.GetBehaviour();

                    if (clipData.animationReference == null)
                    {
                        float mixDuration = clipData.customDuration ? clipData.mixDuration : state.Data.DefaultMix;
                        state.SetEmptyAnimation(0, mixDuration);
                    }
                    else
                    {
                        if (clipData.animationReference.Animation != null)
                        {
                            Spine.TrackEntry trackEntry = state.SetAnimation(0, clipData.animationReference.Animation, clipData.loop);

                            //trackEntry.TrackTime = (float)inputPlayable.GetTime(); // More accurate time-start?
                            trackEntry.EventThreshold      = clipData.eventThreshold;
                            trackEntry.DrawOrderThreshold  = clipData.drawOrderThreshold;
                            trackEntry.AttachmentThreshold = clipData.attachmentThreshold;

                            if (clipData.customDuration)
                            {
                                trackEntry.MixDuration = clipData.mixDuration;
                            }
                        }
                        //else Debug.LogWarningFormat("Animation named '{0}' not found", clipData.animationName);
                    }

                    // Ensure that the first frame ends with an updated mesh.
                    spineComponent.Update(0);
                    spineComponent.LateUpdate();
                }
            }
        }
Пример #8
0
 private void OnComplete(Spine.TrackEntry trackEntry)
 {
     OnDie();
 }
Пример #9
0
 /// <summary>
 /// One optimization high-frequency YieldInstruction returns is to cache instances to minimize GC pressure.
 /// Use NowWaitFor to reuse the same instance of WaitForSpineAnimationComplete.</summary>
 public WaitForSpineAnimation NowWaitFor(Spine.TrackEntry trackEntry, AnimationEventTypes eventsToWaitFor)
 {
     SafeSubscribe(trackEntry, eventsToWaitFor);
     return(this);
 }
Пример #10
0
 public WaitForSpineAnimation(Spine.TrackEntry trackEntry, AnimationEventTypes eventsToWaitFor)
 {
     SafeSubscribe(trackEntry, eventsToWaitFor);
 }
		void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
			if (e.Data.Name == footstepEventName)
				PlayFootstepSound();
		}
Пример #12
0
        private async void DoPlayAnim(AnimEffectData animEffectData)
        {
            switch (animEffectData.animEffectType)
            {
            case AnimEffectData.AnimEffectType.Image:
                Texture texture = await AssetManager.LoadAssetAsync <Texture2D>(animEffectData.imagePath);

                imageGameObject.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", texture);

                imageGameObject.GetComponent <MeshRenderer>().material.SetFloat("ZWrite",
                                                                                animEffectData.zwriteType == FrameEventInfo.ZwriteType.Off ? 0 : 1);

                {
                    switch (animEffectData.renderQueue)
                    {
                    case FrameEventInfo.RenderQueue.Geometry:
                        imageGameObject.GetComponent <MeshRenderer>().material.renderQueue = 2000;
                        break;

                    case FrameEventInfo.RenderQueue.AlphaTest:
                        imageGameObject.GetComponent <MeshRenderer>().material.renderQueue = 2450;
                        break;

                    case FrameEventInfo.RenderQueue.Transparent:
                        imageGameObject.GetComponent <MeshRenderer>().material.renderQueue = 3000;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                // 初始大小 add by TangJian 2018/9/12 10:42
                {
                    rendererSize.x = texture.width / 100f;
                    rendererSize.y = texture.height / 100f;
                    rendererSize.z = 1;

                    float factor = 1.0f / rendererSize.y;

                    rendererSize.x *= factor;
                    rendererSize.y *= factor;
                }

                // 锚点 add by TangJian 2018/9/12 10:42
                {
                    imageGameObject.transform.localPosition = -animEffectData.anchor;
                }

                moveGameObject = gameObject;

                // 显示图片 add by TangJian 2019/6/14 16:22
                imageGameObject.SetActive(true);
                break;

            case AnimEffectData.AnimEffectType.Anim:
                Spine.Unity.SkeletonAnimation skeletonAnimation = animGameObject.GetComponent <Spine.Unity.SkeletonAnimation>();
                skeletonAnimation.skeletonDataAsset = await AssetManager.LoadAssetAsync <Spine.Unity.SkeletonDataAsset>(animEffectData.animPath);

                skeletonAnimation.Initialize(true);
                Spine.TrackEntry TrackEntry = skeletonAnimation.state.SetAnimation(0, animEffectData.animName, animEffectData.animLoop);
                TrackEntry.TimeScale = 1;

                skeletonAnimation.state.TimeScale      = animEffectData.animSpeed;
                animGameObject.transform.localPosition = Vector3.zero;
                moveGameObject = animGameObject;

                // 显示动画 add by TangJian 2019/6/14 16:23
                animGameObject.SetActive(true);
                break;

            case AnimEffectData.AnimEffectType.Particle:
//                    var particle = await AssetManager.Instantiate(animEffectData.prefabname);

                var particle = await AssetManager.SpawnAsync(animEffectData.prefabname);

                particle.transform.parent = particleGameObject.transform;

                particle.transform.localPosition = Vector3.zero;

                moveGameObject = particleGameObject;

                // 显示粒子 add by TangJian 2019/6/14 16:23
                particleGameObject.SetActive(true);
                break;

            case AnimEffectData.AnimEffectType.Gameobject:
//                    var other = await AssetManager.Instantiate(animEffectData.prefabpath);
                var other = await AssetManager.SpawnAsync(animEffectData.prefabpath);

                other.transform.parent = otherGameObject.transform;

                other.transform.localPosition = Vector3.zero;

                other.transform.eulerAngles = Vector3.zero;

                moveGameObject = otherGameObject;

                // 显示其他 add by TangJian 2019/6/14 16:23
                otherGameObject.SetActive(true);
                break;

            default:
                Debug.LogError("");
                break;
            }

            Init();

            RunAction(animEffectData.actionData, () =>
            {
                Tang.PoolManager.Instance.Despawn(gameObject);
            });

            {
                gameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    SortRenderer sortRenderer = rd.gameObject.AddComponentIfNone <SortRenderer>();
                    sortRenderer.Pos          = Vector3.zero;
                }, 1, 99);
            }

            {
                moveGameObject.transform.localPosition += animEffectData.pos.RotateFrontTo(orientation).Flip(MoveFlip);
                if (animEffectData.animEffectType == AnimEffectData.AnimEffectType.Particle)
                {
                    moveGameObject.transform.localScale = animEffectData.scale;
                }
                else
                {
                    moveGameObject.transform.localScale = animEffectData.scale.Flip(RenderFlip);
                }

                if (moveGameObject.transform.localScale.x > 0)
                {
                    moveGameObject.transform.localRotation = Quaternion.Euler((moveGameObject.transform.localRotation.eulerAngles + animEffectData.rotation));
                }
                else
                {
                    moveGameObject.transform.localRotation = Quaternion.Euler((moveGameObject.transform.localRotation.eulerAngles + new Vector3(animEffectData.rotation.x, animEffectData.rotation.y, animEffectData.rotation.z * -1)));
                }


                moveGameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    if (rd.material.HasProperty("AddColor"))
                    {
                        if (rd.gameObject.name == "Anim")
                        {
                            Set_Color(rd, "AddColor", new Color(0, 0, 0, 0));
                            Color color = Get_Color(rd, "AddColor");
                            color       = animEffectData.addColor;
                            Set_Color(rd, "AddColor", color);
                        }
                        else
                        {
                            rd.material.SetColor("AddColor", animEffectData.addColor);
                        }
                    }
                }, 1, 99);

                moveGameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    if (rd.material.HasProperty("MulColor"))
                    {
                        if (rd.gameObject.name == "Anim")
                        {
                            Set_Color(rd, "MulColor", new Color(1, 1, 1, 1));
                            Color color = Get_Color(rd, "MulColor");
                            color       = animEffectData.mulColor;
                            Set_Color(rd, "MulColor", color);
                        }
                        else
                        {
                            rd.material.SetColor("MulColor", animEffectData.mulColor);
                        }
                    }
                }, 1, 99);

                moveGameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    if (rd.gameObject.name == "Anim" && rd.material.HasProperty("_Color"))
                    {
                        Set_Color(rd, "_Color", new Color(1, 1, 1, 1));

                        Color color = Get_Color(rd, "_Color");
                        color.a     = animEffectData.alpha;
                        Set_Color(rd, "_Color", color);
                    }
                    else
                    {
                        if (animEffectData.animEffectType != AnimEffectData.AnimEffectType.Particle)
                        {
                            if (rd.material.HasProperty("_Color"))
                            {
                                Color color       = rd.material.color;
                                color.a           = animEffectData.alpha;
                                rd.material.color = color;
                            }
                            else
                            {
                                Debug.Log("没有_Color属性");
                            }
                        }
                    }
                }, 1, 99);
            }
        }
Пример #13
0
 private void OnComplete(Spine.TrackEntry trackEntry)
 {
     mOwner.Post("State.ChangeState.Idle");
 }
Пример #14
0
        // NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties.
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            var trackBinding = playerData as SkeletonAnimation;

            if (trackBinding == null)
            {
                return;
            }

            if (!Application.isPlaying)
            {
                                #if SPINE_EDITMODEPOSE
                PreviewEditModePose(playable, trackBinding);
                                #endif
                return;
            }

            int inputCount = playable.GetInputCount();

            if (this.lastInputWeights == null || this.lastInputWeights.Length < inputCount)
            {
                this.lastInputWeights = new float[inputCount];

                for (int i = 0; i < inputCount; i++)
                {
                    this.lastInputWeights[i] = 0f;
                }
            }

            var lastInputWeights = this.lastInputWeights;

            for (int i = 0; i < inputCount; i++)
            {
                float lastInputWeight = lastInputWeights[i];
                float inputWeight     = playable.GetInputWeight(i);
                bool  trackStarted    = inputWeight > lastInputWeight;
                lastInputWeights[i] = inputWeight;

                if (trackStarted)
                {
                    ScriptPlayable <SpineAnimationStateBehaviour> inputPlayable = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(i);
                    SpineAnimationStateBehaviour input = inputPlayable.GetBehaviour();
                    Spine.Animation animation          = trackBinding.Skeleton.Data.FindAnimation(input.animationName);

                    if (animation != null)
                    {
                        Spine.TrackEntry trackEntry = trackBinding.AnimationState.SetAnimation(0, input.animationName, input.loop);

                        trackEntry.EventThreshold      = input.eventThreshold;
                        trackEntry.DrawOrderThreshold  = input.drawOrderThreshold;
                        trackEntry.AttachmentThreshold = input.attachmentThreshold;

                        if (input.customDuration)
                        {
                            trackEntry.MixDuration = input.mixDuration;
                        }
                    }
                    else if (string.IsNullOrEmpty(input.animationName))
                    {
                        float mixDuration = input.customDuration ? input.mixDuration : trackBinding.AnimationState.Data.DefaultMix;
                        trackBinding.AnimationState.SetEmptyAnimation(0, mixDuration);
                        continue;
                    }
//					else {
//						Debug.LogWarningFormat("Animation named '{0}' not found", input.animationName);
//					}
                }
            }
        }