| | |
| | | |
| | | protected async UniTask PlaySpineEffect(bool closePMA = false) |
| | | { |
| | | |
| | | // 从特效预制体池获取特效 |
| | | if (spineComp == null) |
| | | { |
| | | spineComp = gameObject.AddMissingComponent<SkeletonGraphic>(); |
| | | } |
| | | |
| | | if (spineComp.skeletonDataAsset == null || spineAnimationState == null) |
| | | try |
| | | { |
| | | //LoadAsset 已经有缓存SkeletonDataAsset |
| | | spineComp.skeletonDataAsset = await ResManager.Instance.LoadAssetAsync<SkeletonDataAsset>("UIEffect/" + effectConfig.packageName, effectConfig.fxName); |
| | | //为true时会有部分特效不显示 如满级经验条;改成伽马后部分特效正常,还有部分依然要改此设置 |
| | | spineComp.MeshGenerator.settings.pmaVertexColors = !closePMA; |
| | | spineComp.raycastTarget = false; |
| | | spineComp.Initialize(true); |
| | | // 检查动画是否有相加模式 |
| | | // bool hasAdditiveBlend = CheckForAdditiveBlend(spineComp.Skeleton); |
| | | // if (hasAdditiveBlend) |
| | | // { |
| | | // spineComp.material = ResManager.Instance.LoadAsset<Material>("UIEffect/" + effectConfig.packageName, effectConfig.fxName.Split('_')[0] + "_Material-Additive"); |
| | | // } |
| | | // else |
| | | // { |
| | | // spineComp.material = null; |
| | | // } |
| | | var material = await ResManager.Instance.LoadAssetAsync<Material>("Materials", "SkeletonGraphicDefault-Straight"); |
| | | if (material != null) |
| | | { |
| | | spineComp.material = material; |
| | | #if UNITY_WEBGL && !UNITY_EDITOR |
| | | Debug.Log($"[SpineEffect][WebGL] effectId={effectConfig.id} fxName={effectConfig.fxName}" + |
| | | $" mat={material.name} shader={material.shader.name}" + |
| | | $" straightAlpha={material.IsKeywordEnabled("_STRAIGHT_ALPHA_INPUT")}" + |
| | | $" canvasGroup={material.IsKeywordEnabled("_CANVAS_GROUP_COMPATIBLE")}" + |
| | | $" pmaVert={spineComp.MeshGenerator.settings.pmaVertexColors}"); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | Debug.LogError("Failed to load material for Spine effect: " + effectConfig.fxName); |
| | | // 从特效预制体池获取特效 |
| | | if (spineComp == null) |
| | | { |
| | | spineComp = gameObject.AddMissingComponent<SkeletonGraphic>(); |
| | | } |
| | | |
| | | spineAnimationState = spineComp.AnimationState; |
| | | spineAnimationState.TimeScale = speedRate; |
| | | spineAnimationState.Data.DefaultMix = 0f; |
| | | spineAnimationState.Complete -= OnSpineAnimationComplete; |
| | | spineAnimationState.Complete += OnSpineAnimationComplete; |
| | | if (spineComp.skeletonDataAsset == null || spineAnimationState == null) |
| | | { |
| | | //LoadAsset 已经有缓存SkeletonDataAsset;使用异步API兼容WebGL |
| | | spineComp.skeletonDataAsset = await ResManager.Instance.LoadAssetAsync<SkeletonDataAsset>("UIEffect/" + effectConfig.packageName, effectConfig.fxName); |
| | | if (this == null || spineComp == null) return; |
| | | //为true时会有部分特效不显示 如满级经验条;改成伽马后部分特效正常,还有部分依然要改此设置 |
| | | spineComp.MeshGenerator.settings.pmaVertexColors = !closePMA; |
| | | spineComp.raycastTarget = false; |
| | | spineComp.Initialize(true); |
| | | // 检查动画是否有相加模式 |
| | | // bool hasAdditiveBlend = CheckForAdditiveBlend(spineComp.Skeleton); |
| | | // if (hasAdditiveBlend) |
| | | // { |
| | | // spineComp.material = ResManager.Instance.LoadAsset<Material>("UIEffect/" + effectConfig.packageName, effectConfig.fxName.Split('_')[0] + "_Material-Additive"); |
| | | // } |
| | | // else |
| | | // { |
| | | // spineComp.material = null; |
| | | // } |
| | | var material = await ResManager.Instance.LoadAssetAsync<Material>("Materials", "SkeletonGraphicDefault-Straight"); |
| | | if (this == null || spineComp == null) return; |
| | | if (material != null) |
| | | { |
| | | spineComp.material = material; |
| | | #if UNITY_WEBGL && !UNITY_EDITOR |
| | | Debug.Log($"[SpineEffect][WebGL] effectId={effectConfig.id} fxName={effectConfig.fxName}" + |
| | | $" mat={material.name} shader={material.shader.name}" + |
| | | $" straightAlpha={material.IsKeywordEnabled("_STRAIGHT_ALPHA_INPUT")}" + |
| | | $" canvasGroup={material.IsKeywordEnabled("_CANVAS_GROUP_COMPATIBLE")}" + |
| | | $" pmaVert={spineComp.MeshGenerator.settings.pmaVertexColors}"); |
| | | #endif |
| | | } |
| | | |
| | | spineAnimationState = spineComp.AnimationState; |
| | | spineAnimationState.TimeScale = speedRate; |
| | | spineAnimationState.Data.DefaultMix = 0f; |
| | | spineAnimationState.Complete -= OnSpineAnimationComplete; |
| | | spineAnimationState.Complete += OnSpineAnimationComplete; |
| | | } |
| | | |
| | | spineComp.enabled = true; |
| | | PlayerTheSpineAnim(); |
| | | SoundPlayer.Instance.PlayUIAudioDelay(effectConfig.audio).Forget(); |
| | | } |
| | | |
| | | spineComp.enabled = true; |
| | | PlayerTheSpineAnim(); |
| | | SoundPlayer.Instance.PlayUIAudioDelay(effectConfig.audio).Forget(); |
| | | |
| | | #if UNITY_EDITOR |
| | | // 编辑器模式下强制刷新材质球,解决部分特效不显示问题 |
| | | await UniTask.Delay(100); |
| | | if (spineComp != null && this != null && spineComp.material != null) |
| | | catch (Exception e) |
| | | { |
| | | spineComp.material.shader = Shader.Find(spineComp.material.shader.name); |
| | | Debug.LogError(e); |
| | | } |
| | | #endif |
| | | |
| | | await UniTask.CompletedTask; |
| | | } |
| | | |
| | | // 播放指定动画 |