public void Initialize(bool overwrite) { if ((this.skeletonAnimations.Count == 0) || overwrite) { this.Clear(); MeshGenerator.Settings meshGeneratorSettings = this.meshGeneratorSettings; Transform parent = base.transform; foreach (SkeletonDataAsset asset in this.skeletonDataAssets) { SkeletonAnimation item = SkeletonAnimation.NewSkeletonAnimationGameObject(asset); item.transform.SetParent(parent, false); item.SetMeshSettings(meshGeneratorSettings); item.initialFlipX = this.initialFlipX; item.initialFlipY = this.initialFlipY; Skeleton skeleton = item.skeleton; skeleton.FlipX = this.initialFlipX; skeleton.FlipY = this.initialFlipY; item.Initialize(false); this.skeletonAnimations.Add(item); } Dictionary <string, Spine.Animation> animationNameTable = this.animationNameTable; Dictionary <Spine.Animation, SkeletonAnimation> animationSkeletonTable = this.animationSkeletonTable; foreach (SkeletonAnimation animation2 in this.skeletonAnimations) { foreach (Spine.Animation animation3 in animation2.Skeleton.Data.Animations) { animationNameTable[animation3.Name] = animation3; animationSkeletonTable[animation3] = animation2; } } this.SetActiveSkeleton(this.skeletonAnimations[0]); this.SetAnimation(this.initialAnimation, this.initialLoop); } }
public static Spine.Unity.SkeletonAnimation Reload(this Spine.Unity.SkeletonAnimation s) { try { s.Initialize(true); } catch (System.Exception e) { Util.LogError(e); } return(s); }
static int Initialize(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Spine.Unity.SkeletonAnimation obj = (Spine.Unity.SkeletonAnimation)ToLua.CheckObject(L, 1, typeof(Spine.Unity.SkeletonAnimation)); bool arg0 = LuaDLL.luaL_checkboolean(L, 2); obj.Initialize(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
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); } }