public System.Collections.IEnumerator TestAnimEffect(AnimEffectData animEffectData, int times, float interval)
        {
            var playerObject = GameObject.Find("Player1");

            RoleController roleController = playerObject.GetComponent <RoleController>();

            for (int i = 0; i < times; i++)
            {
                AnimManager.Instance.PlayAnimEffect(animEffectData, playerObject.transform.position + testPosition, 0, testFlip, moveOrientation, playerObject.transform);

                float time = 0;
                while (time < interval)
                {
                    time += Time.deltaTime;
                    yield return(0);
                }
            }

            yield return(0);
        }
Beispiel #2
0
        public virtual void PlayAnim(AnimEffectData animEffectData)
        {
            switch (animEffectData.animEffectType)
            {
            case AnimEffectData.AnimEffectType.Image:
                ////AnimGameObject.SetActive(false);
                //Texture texture = UnityEditor.AssetDatabase.LoadAssetAtPath<Texture2D>(animEffectData.imagePath);
                ////meshRenderer.material.SetTexture("_MainTex", texture);

                //// 初始大小 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;
                //}
                break;

            case AnimEffectData.AnimEffectType.Anim:
                //AnimGameObject.AddComponentUnique<SortRenderer>();
                //Spine.Unity.SkeletonDataAsset skeletonDataAsset= (Spine.Unity.SkeletonDataAsset)UnityEditor.AssetDatabase.LoadAssetAtPath(animEffectData.animPath, typeof(Spine.Unity.SkeletonDataAsset));
                //Spine.Unity.SkeletonAnimation skeletonAnimation = AnimGameObject.GetComponent<Spine.Unity.SkeletonAnimation>();
                //skeletonAnimation.skeletonDataAsset = (Spine.Unity.SkeletonDataAsset)UnityEditor.AssetDatabase.LoadAssetAtPath(animEffectData.animPath, typeof(Spine.Unity.SkeletonDataAsset));
                //rendererGameObject.SetActive(true);
                //AnimGameObject.SetActive(true);
                //imageGameObject.SetActive(false);

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

                //skeletonAnimation.state.End += (entry) =>
                //{
                //    Destroy(gameObject);
                //};
                break;
            }

            {
                transform.localPosition += animEffectData.pos;
                transform.localScale     = animEffectData.scale;

                gameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    if (rd.material.HasProperty("AddColor"))
                    {
                        if (rd.gameObject.GetComponent <Spine.Unity.SkeletonRenderer>() != null)
                        {
                            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);

                gameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    if (rd.material.HasProperty("MulColor"))
                    {
                        if (rd.gameObject.GetComponent <Spine.Unity.SkeletonRenderer>() != null)
                        {
                            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);

                gameObject.RecursiveComponent <Renderer>((Renderer rd, int depth) =>
                {
                    if (rd.gameObject.GetComponent <Spine.Unity.SkeletonRenderer>() != null)
                    {
                        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
                    {
                        Color color       = rd.material.color;
                        color.a           = animEffectData.alpha;
                        rd.material.color = color;
                    }
                    // Color color = rd.material.color;
                    // color.a = animEffectData.alpha;
                    // rd.material.color = color;



                    // rd.material.SetColor("_Color", new Color(1, 1, 1, 0.1f));

                    // MaterialPropertyBlock mabb = new MaterialPropertyBlock();
                    // mabb.SetColor("_Color", new Color(1, 1, 1, 0.1f));
                    // rd.SetPropertyBlock(mabb);
                }, 1, 99);
            }

            RunAction(animEffectData.actionData, () =>
            {
                // GameObjectManager.Instance.Despawn(gameObject);
                Tools.Destroy(gameObject);
            });
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
 public void PlayAnim(AnimEffectData animEffectData)
 {
     Initialize();
     DoPlayAnim(animEffectData);
 }