From eb27e5fd31f73b998a4bbd85511a31e40b8c61b7 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 21 十一月 2025 17:03:47 +0800
Subject: [PATCH] 0312 关闭游戏内日志
---
Main/Component/UI/Effect/EffectPlayer.cs | 232 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 187 insertions(+), 45 deletions(-)
diff --git a/Main/Component/UI/Effect/EffectPlayer.cs b/Main/Component/UI/Effect/EffectPlayer.cs
index a86d3b7..eec97f3 100644
--- a/Main/Component/UI/Effect/EffectPlayer.cs
+++ b/Main/Component/UI/Effect/EffectPlayer.cs
@@ -5,11 +5,11 @@
using UnityEngine;
using Spine;
using UnityEngine.UI;
+using Cysharp.Threading.Tasks;
-// 鐗规晥鎾斁鍣紝瀵硅薄姹犵鐞嗭細unity鐗规晥鍜宻pine鐗规晥閮芥槸鍋氬ソ鐨勯鍒朵綋
-// unity鐗规晥棰勫埗浣撴槸鐗规晥甯堝湪鍒朵綔鐨勬椂鍊欑敓鎴愮殑锛寀nity鐗规晥蹇呴』鎸傝浇璁剧疆鎾斁鏃堕暱鑴氭湰 EffectTime
-// spine鐗规晥鏄壒鏁堝笀鍒朵綔鐨勫姩鐢绘枃浠跺彲鐩存帴鍔犺浇鐢紝鍒朵綔鎴愰鍒朵綋鍙鍔燘oneFollower涔嬬被鐨勮繘琛岄�昏緫澶勭悊
-// 闈濽I鐗规晥浣跨敤锛孶I鐗规晥UIEffectPlayer缁ф壙EffectPlayer锛屽悗缁鏋滈�昏緫鍐茬獊澶у垯涓嶇敤缁ф壙
+// 鐗规晥鎾斁鍣紝棰勫埗浣撳璞℃睜绠$悊锛寀nity鐨勯鍒朵綋姹犱娇鐢ㄦ湁闂锛�1涓壒鏁�1涓睜浣嗗鐢ㄥ張浣庯級鍚庣画淇敼
+// unity鐗规晥銆婇鍒朵綋銆嬫槸鐗规晥甯堝湪鍒朵綔鐨勬椂鍊欑敓鎴愮殑涓嶅悓棰勫埗浣擄紝unity鐗规晥蹇呴』鎸傝浇璁剧疆鎾斁鏃堕暱鑴氭湰 EffectTime
+// spine鐗规晥鏄壒鏁堝笀鍒朵綔鐨勫姩鐢绘枃浠讹紝鍙叡鍚屽鐢ㄤ竴涓�婇鍒朵綋銆�
public class EffectPlayer : MonoBehaviour
{
[SerializeField]
@@ -24,6 +24,7 @@
{
if (value != m_EffectID)
{
+ Stop();
isInit = false;
m_EffectID = value;
}
@@ -36,7 +37,16 @@
public float speedRate = 1f;
+ [Header("鏄惁寰幆鎾斁spine鐗规晥")]
+ public bool isPlaySpineLoop = false;
+ [Header("鏄惁鍦ㄦ樉绀烘椂鎾斁")]
+ public bool isPlayOnEnable = false;
+
+ [Header("寤惰繜鎾斁(姣)")]
+ public int playDelayTime = 0;
+
+ public int playSpineAnimIndex = -1; //鎾斁spine鐗规晥鍔ㄧ敾绱㈠紩,浠g爜鎺у埗
[Header("鎾斁瀹屾瘯绔嬪嵆鍥炴敹")]
@@ -51,7 +61,11 @@
protected EffectPenetrationBlocker blocker = null;
protected bool isInit = false;
- protected bool isPlaying = false;
+ public bool isPlaying
+ {
+ get;
+ protected set;
+ }
protected List<ParticleSystem> particleList = new List<ParticleSystem>();
@@ -68,10 +82,15 @@
protected virtual void OnEnable()
{
- if (spineComp != null)
+
+ if (isPlayOnEnable)
+ {
+ Play(false);
+ }
+ else if (spineComp != null)
{
if (!isPlaying)
- {
+ {
//闅愯棌锛屼細鏈夐潤鎬佹樉绀洪棶棰�
spineComp.enabled = false;
}
@@ -106,18 +125,25 @@
return;
}
-
Clear();
return;
}
protected virtual void Clear()
{
+ isInit = false;
particleList.Clear();
animatorList.Clear();
rendererList.Clear();
+
+ if (spineComp != null)
+ {
+ spineComp.skeletonDataAsset = null;
+ // spineComp.Initialize(false);
+ spineComp.Clear();
+ }
+
spineComp = null;
- pool = null;
}
public virtual void Stop()
@@ -135,17 +161,24 @@
{
spineComp.enabled = false;
}
- isInit = false;
isPlaying = false;
- Clear();
- onComplete?.Invoke();
+ playSpineAnimIndex = -1;
}
- public virtual void Play(bool showLog = true)
+ protected void Release()
{
+ Stop();
+
+ Clear();
+ }
+
+ public virtual void Play(bool showLog = true, bool closePMA = false)
+ {
+ isPlaying = true;
if (!isInit)
{
InitComponent(showLog);
+ //effeid 涓�0涔熷垵濮嬪寲鎴愬姛锛岄伩鍏嶉噸澶嶅鐞嗭紝鍦ㄥ彉鏇磂ffectid鏃朵細閲嶆柊鍒濆鍖�
isInit = true;
}
else
@@ -155,13 +188,20 @@
{
this.gameObject.SetActive(true);
}
+ //闃茶寖effeid 涓�0
+ if (effectConfig != null && effectConfig.isSpine != 0)
+ {
+ PlaySpineEffect(closePMA);
+ }
return;
}
+ if (effectConfig == null)
+ return;
if (EffectMgr.IsNotShowBySetting(effectId))
- {
- return;
- }
+ {
+ return;
+ }
if (null != effectTarget)
{
@@ -175,28 +215,118 @@
this.gameObject.SetActive(true);
}
- PlayerEffect(true);
+ // 鍔犺浇spine鐗规晥璧勬簮
+ if (effectConfig.isSpine != 0)
+ {
+ PlaySpineEffect(closePMA);
+ }
+ else
+ {
+ PlayerEffect();
+ }
+
SoundPlayer.Instance.PlayUIAudio(effectConfig.audio);
}
- protected virtual void PlaySpineEffect()
+ // protected virtual void PlaySpineEffect()
+ // {
+ // spineComp = gameObject.GetComponentInChildren<SkeletonGraphic>(true);
+ // spineComp.raycastTarget = false;
+ // spineComp.Initialize(true);
+ // spineAnimationState = spineComp.AnimationState;
+ // spineAnimationState.Complete -= OnSpineAnimationComplete;
+ // spineAnimationState.Complete += OnSpineAnimationComplete;
+
+ // // 澶栧眰鎺у埗鍏蜂綋鎾斁鍝釜鍔ㄧ敾
+ // spineComp.enabled = true;
+
+ // return;
+ // }
+
+
+
+ protected void PlaySpineEffect(bool closePMA = false)
{
- spineComp = gameObject.GetComponentInChildren<SkeletonGraphic>(true);
- spineComp.raycastTarget = false;
- spineComp.Initialize(true);
- spineAnimationState = spineComp.AnimationState;
- spineAnimationState.Complete -= OnSpineAnimationComplete;
- spineAnimationState.Complete += OnSpineAnimationComplete;
- // 澶栧眰鎺у埗鍏蜂綋鎾斁鍝釜鍔ㄧ敾
+ // 浠庣壒鏁堥鍒朵綋姹犺幏鍙栫壒鏁�
+ if (spineComp == null)
+ {
+ spineComp = gameObject.AddMissingComponent<SkeletonGraphic>();
+ }
+
+ if (spineComp.skeletonDataAsset == null || spineAnimationState == null)
+ {
+ //LoadAsset 宸茬粡鏈夌紦瀛楽keletonDataAsset
+ spineComp.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("UIEffect/" + effectConfig.packageName, effectConfig.fxName);
+ //涓簍rue鏃朵細鏈夐儴鍒嗙壒鏁堜笉鏄剧ず 濡傛弧绾х粡楠屾潯锛涙敼鎴愪冀椹悗閮ㄥ垎鐗规晥姝e父锛岃繕鏈夐儴鍒嗕緷鐒惰鏀规璁剧疆
+ spineComp.MeshGenerator.settings.pmaVertexColors = !closePMA;
+ spineComp.raycastTarget = false;
+ spineComp.Initialize(true);
+ spineComp.timeScale = speedRate;
+ // 妫�鏌ュ姩鐢绘槸鍚︽湁鐩稿姞妯″紡
+ // 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;
+ // }
+ spineComp.material = ResManager.Instance.LoadAsset<Material>("Materials", "SkeletonGraphicDefault-Straight");
+
+ spineAnimationState = spineComp.AnimationState;
+ spineAnimationState.Data.DefaultMix = 0f;
+ spineAnimationState.Complete -= OnSpineAnimationComplete;
+ spineAnimationState.Complete += OnSpineAnimationComplete;
+ }
+
spineComp.enabled = true;
-
- return;
+ PlayerTheSpineAnim();
}
- protected virtual void PlayerEffect(bool playSpine)
+ // 鎾斁鎸囧畾鍔ㄧ敾
+ void PlayerTheSpineAnim()
+ {
+ spineComp.enabled = true;
+ var skeletonData = spineComp.Skeleton.Data;
+ if (skeletonData.Animations.Count > 0)
+ {
+ //鎸夐厤缃垨鑰呴粯璁ょ涓�涓�
+ int defaultAnimIndex = Math.Max(0, effectConfig.animIndex.Length == 0 ? 0 : effectConfig.animIndex[0]);
+ if (playSpineAnimIndex >= skeletonData.Animations.Count)
+ {
+ playSpineAnimIndex = -1;
+ Debug.LogError("鐗规晥锛�" + effectConfig.id + " 绱㈠紩瓒呭嚭鎾斁榛樿鍔ㄧ敾銆� error锛�" + playSpineAnimIndex);
+ }
+ string defaultAnimationName = skeletonData.Animations.Items[playSpineAnimIndex == -1 ? defaultAnimIndex : playSpineAnimIndex].Name;
+ spineAnimationState.SetAnimation(0, defaultAnimationName, isPlaySpineLoop);
+ }
+ else
+ {
+ Debug.LogError("Spine 鏁版嵁涓病鏈夋壘鍒颁换浣曞姩鐢伙紒" + effectConfig.id);
+ }
+ }
+
+
+ private bool CheckForAdditiveBlend(Spine.Skeleton skeleton)
+ {
+ // 閬嶅巻鎵�鏈夋彃妲斤紝妫�鏌ユ槸鍚︽湁鐩稿姞妯″紡
+ foreach (var slot in skeleton.Slots)
+ {
+ if (slot.Data.BlendMode == Spine.BlendMode.Additive)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ //unity鐗规晥
+ protected virtual void PlayerEffect()
{
var effectPrefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectConfig.packageName, effectConfig.fxName);
if (effectPrefab == null)
@@ -226,19 +356,13 @@
effectTarget.transform.localRotation = Quaternion.identity;
effectTarget.name = $"Effect_{effectConfig.fxName}";
- if (effectConfig.isSpine != 0 && playSpine)
- {
- //棰勫埗浣�
- PlaySpineEffect();
- }
- else
- {
- //鎸傝浇缁勪欢鍚� 寮�濮嬫敹闆�
- particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
- animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
- rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
- OnUnityAnimationComplete();
- }
+
+ //鎸傝浇缁勪欢鍚� 寮�濮嬫敹闆�
+ particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
+ animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
+ rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
+ OnUnityAnimationComplete();
+
if (null == canvas)
canvas = GetComponentInParent<Canvas>();
@@ -253,6 +377,18 @@
}
}
+ public async UniTask PlayAsync(bool showLog = true, bool closePMA = false)
+ {
+ await UniTask.Delay(playDelayTime);
+ try
+ {
+ Play(showLog, closePMA);
+ }
+ catch (Exception e)
+ {
+ Debug.LogError(e);
+ }
+ }
protected void OnDestroy()
{
@@ -262,7 +398,7 @@
onDestroy = null;
}
// 鍋滄鐗规晥骞跺綊杩樺埌姹犱腑
- Stop();
+ Release();
if (spineAnimationState != null)
{
@@ -275,11 +411,17 @@
//鍗曟鎾斁瀹屾瘯灏变細瑙﹀彂锛屽嵆浣挎槸寰幆
protected virtual void OnSpineAnimationComplete(Spine.TrackEntry trackEntry)
{
- if (isReleaseImmediately)
+ if (!isPlaySpineLoop)
{
spineComp.enabled = false;
isPlaying = false;
- Stop();
+ onComplete?.Invoke();
+ // TODO 浼氭姤閿欐殏鏃舵敞閲�
+ // if (isReleaseImmediately)
+ // {
+ // Release();
+ // }
+
}
}
@@ -299,7 +441,7 @@
{
this.DoWaitStop();
if (isReleaseImmediately)
- Stop();
+ Release();
}
--
Gitblit v1.8.0