From 82769d5295e83e53ef79c64638829f56fa94b28b Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 24 七月 2025 20:40:42 +0800
Subject: [PATCH] 0312 特效播放优化,描边

---
 Main/ResModule/ResManager.cs             |    4 
 Main/Component/UI/Effect/EffectPlayer.cs |  130 ++++++++++++++++++++++++++++++++++++-------
 Main/System/HeroUI/HeroListWin.cs        |   12 ++-
 Main/Component/UI/Core/OutlineEx.cs      |   20 ++++--
 4 files changed, 133 insertions(+), 33 deletions(-)

diff --git a/Main/Component/UI/Core/OutlineEx.cs b/Main/Component/UI/Core/OutlineEx.cs
index 887988b..e1ee362 100644
--- a/Main/Component/UI/Core/OutlineEx.cs
+++ b/Main/Component/UI/Core/OutlineEx.cs
@@ -34,16 +34,24 @@
     private static List<UIVertex> m_VetexList = new List<UIVertex>();
     // 鏉愯川姹狅細Key涓�"棰滆壊_瀹藉害"鏍煎紡鐨勫瓧绗︿覆锛孷alue涓哄搴旂殑鏉愯川; 鍑忓皯鍚堟壒闂锛屽張鑳戒繚鎸佷笉鍚岀殑鎻忚竟锛涘叡鐢ㄦ潗璐ㄤ細鍚屾椂鏀瑰彉鍙傛暟
     private static Dictionary<string, Material> m_MaterialPool = new Dictionary<string, Material>();
-    private static Shader m_Shader;
+
+    static Shader m_tmpShader;
+    private static Shader m_Shader
+    {
+        get
+        {
+            if (m_tmpShader == null)
+            {
+                m_tmpShader = Shader.Find("TSF Shaders/UI/OutlineEx");
+            }
+            return m_tmpShader;
+        }
+    }
 
     protected override void Start()
     {
         base.Start();
-        if (m_Shader == null)
-        {
-            m_Shader = Shader.Find("TSF Shaders/UI/OutlineEx");
-        }
-        
+
         // 浣跨敤鏉愯川姹犺幏鍙栨垨鍒涘缓鏉愯川
         string key = GetMaterialKey(OutlineColor, OutlineWidth);
         if (!m_MaterialPool.TryGetValue(key, out Material material))
diff --git a/Main/Component/UI/Effect/EffectPlayer.cs b/Main/Component/UI/Effect/EffectPlayer.cs
index 26427fa..c29f2e1 100644
--- a/Main/Component/UI/Effect/EffectPlayer.cs
+++ b/Main/Component/UI/Effect/EffectPlayer.cs
@@ -13,8 +13,17 @@
     public EffectConfig effectConfig;
 
     public Action<EffectPlayer> onDestroy;
+    public Action onComplete;
 
     public float speedRate = 1f;
+
+    [Header("鏄惁鍦ㄦ樉绀烘椂鎾斁")]
+    public bool isPlayOnEnable = true;
+
+    [Header("鏄惁绔嬪嵆鎾斁spine鐗规晥")]
+    public bool isPlaySpineImmediately = false;  
+    [Header("鏄惁寰幆鎾斁spine鐗规晥")]
+    public bool isPlaySpineLoop = false; 
 
     [HideInInspector] public Canvas canvas = null;
 
@@ -31,23 +40,28 @@
     protected List<Renderer> rendererList = new List<Renderer>();
 
     protected SkeletonGraphic spineComp;
+    protected Spine.AnimationState spineAnimationState;
 
-    protected void Start()
+    protected void OnEnable()
     {
-        ReStart();
+        if (isPlayOnEnable)
+        {
+            Play();
+        }
     }
 
-    protected void InitCompnent()
+    protected bool InitCompnent()
     {
         if (effectId <= 0)
         {
             effectConfig = null;
-            Debug.LogError("EffectPlayer effectId is not set");
-#if UNITY_EDITOR
-            UnityEditor.Selection.activeGameObject = gameObject;
-            UnityEditor.EditorGUIUtility.PingObject(gameObject);
-#endif
-            return;
+            // 鏍规嵁閫昏緫闇�姹傦紝鍔ㄦ�佽缃壒鏁堢殑鎯呭喌
+            // Debug.LogError("EffectPlayer effectId is not set");
+            // #if UNITY_EDITOR
+            //             UnityEditor.Selection.activeGameObject = gameObject;
+            //             UnityEditor.EditorGUIUtility.PingObject(gameObject);
+            // #endif
+            return false;
         }
 
         effectConfig = EffectConfig.Get(effectId);
@@ -59,7 +73,7 @@
             UnityEditor.Selection.activeGameObject = gameObject;
             UnityEditor.EditorGUIUtility.PingObject(gameObject);
 #endif
-            return;
+            return false;
         }
 
 
@@ -68,17 +82,21 @@
         rendererList.Clear();
         spineComp = null;
 
+        //spine鏄姞杞芥枃浠讹紝闇�瑕佹彁鍓嶆寕杞借剼鏈紝unity鐗规晥鏄凡缁忓仛濂界殑棰勫埗浣撳緟鍔犺浇鍚庢敹闆嗙粍浠�
         if (effectConfig.isSpine != 0)
         {
-            spineComp = gameObject.GetComponentInChildren<SkeletonGraphic>(true);
+            spineComp = gameObject.AddMissingComponent<SkeletonGraphic>();
+
         }
-        else
-        {
-            //  鏀堕泦缁勪欢
-            particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
-            animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
-        }
-        rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
+        // else
+        // {
+        //     //  鏀堕泦缁勪欢
+        //     particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
+        //     animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
+        // }
+        // rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
+
+        return true;
     }
 
     public void Stop()
@@ -107,8 +125,16 @@
     {
         if (!isInit)
         {
-            isInit = true;
-            InitCompnent();
+            if (InitCompnent())
+            {
+                isInit = true;
+            }
+            else
+            {
+                //鏍规嵁閫昏緫闇�姹傦紝鍔ㄦ�佽缃壒鏁堢殑鎯呭喌
+                return;
+            }
+
         }
 
         if (EffectMgr.Instance.IsNotShowBySetting(effectId))
@@ -125,7 +151,41 @@
         //	YYL TODO
         //	鍦ㄨ繖閲岃�冭檻鐢ㄦ睜鐨勮瘽鍙兘璧伴厤缃ソ涓�鐐� 鍘熸湰鐨勬槸鏃犺濡備綍閮借蛋姹� 浣嗘槸瀹為檯涓婃湁浜涚壒鏁堝苟涓嶉渶瑕�
 
-        // 鍔犺浇鐗规晥璧勬簮
+        // 鍔犺浇spine鐗规晥璧勬簮
+        if (effectConfig.isSpine != 0)
+        {
+            spineComp.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("UIEffect/" + effectConfig.packageName, effectConfig.fxName + "_SkeletonData");
+            spineComp.raycastTarget = false;
+            spineComp.Initialize(true);
+            spineAnimationState = spineComp.AnimationState;
+            spineAnimationState.Complete -= OnSpineAnimationComplete;
+            spineAnimationState.Complete += OnSpineAnimationComplete;
+            if (isPlaySpineImmediately)
+            {
+                //UI鐗规晥甯哥敤鏂瑰紡
+                spineComp.enabled = true;
+                // 鎾斁绗竴涓姩鐢伙紙浣滀负榛樿鍔ㄧ敾锛�
+                var skeletonData = spineComp.Skeleton.Data;
+                if (skeletonData.Animations.Count > 0)
+                {
+                    string defaultAnimationName = skeletonData.Animations.Items[0].Name;
+                    spineComp.AnimationState.SetAnimation(0, defaultAnimationName, isPlaySpineLoop);
+                }
+                else
+                {
+                    Debug.LogError("Spine 鏁版嵁涓病鏈夋壘鍒颁换浣曞姩鐢伙紒" + effectConfig.id);
+                }
+            }
+            else
+            {
+                spineComp.enabled = false;
+            }
+
+            
+            return;
+        }
+
+        //鍔犺浇unity鐗规晥
         var effectPrefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectConfig.packageName, effectConfig.fxName);
         if (effectPrefab == null)
         {
@@ -136,6 +196,12 @@
         // 瀹炰緥鍖栫壒鏁�
         effectTarget = Instantiate(effectPrefab, transform);
         effectTarget.name = $"Effect_{effectConfig.fxName}";
+
+        //鎸傝浇缁勪欢鍚� 寮�濮嬫敹闆�
+        particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
+        animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
+        rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
+
 
         //  鎬濊�冧竴涓嬪湪娌℃湁鎸傚湪鑺傜偣鐨勬椂鍊�
         if (null == canvas)
@@ -166,8 +232,30 @@
             onDestroy.Invoke(this);
             onDestroy = null;
         }
+        if (spineAnimationState != null)
+        {
+            spineAnimationState.Complete -= OnSpineAnimationComplete;
+        }
     }
 
+    //鍗曟鎾斁瀹屾瘯灏变細瑙﹀彂锛屽嵆浣挎槸寰幆
+    protected void OnSpineAnimationComplete(Spine.TrackEntry trackEntry)
+    {
+        if (!isPlaySpineLoop)
+        {
+            if (onComplete == null)
+            {
+                if (effectConfig.isSpine != 0)
+                {
+                    spineComp.enabled = false;
+                }
+            }
+
+            onComplete?.Invoke();
+        }
+    }
+
+
     //  鍒涘缓鍚庣殑鐗规晥浼氳嚜鍔ㄩ殣钘� 闇�瑕佹墜鍔ㄨ皟鐢≒lay鎵嶈兘鎾斁
     public static EffectPlayer Create(int effectId, Transform parent, bool createNewChild = false)
     {
diff --git a/Main/ResModule/ResManager.cs b/Main/ResModule/ResManager.cs
index 3d68b85..7c55d05 100644
--- a/Main/ResModule/ResManager.cs
+++ b/Main/ResModule/ResManager.cs
@@ -162,13 +162,13 @@
     public string[] LoadConfig(string name)
     {
         string path = string.Empty;
+#if UNITY_EDITOR
         if (!AssetSource.isUseAssetBundle)
         {
-#if UNITY_EDITOR
             path = ResourcesPath.CONFIG_FODLER + "/" + name + ".txt";
-#endif
         }
         else
+#endif
         {
             path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
         }
diff --git a/Main/System/HeroUI/HeroListWin.cs b/Main/System/HeroUI/HeroListWin.cs
index 5f7eb94..fd85ec5 100644
--- a/Main/System/HeroUI/HeroListWin.cs
+++ b/Main/System/HeroUI/HeroListWin.cs
@@ -56,7 +56,7 @@
 
     public override void Refresh()
     {
-        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Item);
+        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Hero);
         if (singlePack == null || singlePack.GetAllItems().Count <= 0)
         {
             heroListEmpty.SetActive(true);
@@ -71,8 +71,10 @@
         //涓婇樀灞炴��
         for (int i = 0; i < attrOnList.Count; i++)
         {
-            attrOnList[i].text = PlayerPropertyConfig.GetFullDescription(new Int2 (PlayerPropertyConfig.baseAttrs[i], 1 ));
+            attrOnList[i].text = PlayerPropertyConfig.GetFullDescription(new Int2(PlayerPropertyConfig.baseAttrs[i], 1));
         }
+
+        RefreshPakCount(PackType.Hero, 0, 0);
     }
 
     void OnRefreshCell(ScrollerDataType type, CellView cell)
@@ -96,13 +98,15 @@
 
     void RefreshPakCount(PackType type, int index, int itemID)
     {
-        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Item);
+        if (type != PackType.Hero)
+            return;
+        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Hero);
         if (singlePack == null)
             return;
 
         int count = singlePack.GetAllItems().Count;
 
-        heroPackText.text =  UIHelper.AppendColor(count > singlePack.unlockedGridCount ? TextColType.Red : TextColType.NavyBrown,
+        heroPackText.text = UIHelper.AppendColor(count > singlePack.unlockedGridCount ? TextColType.Red : TextColType.NavyBrown,
                             string.Format("{0}/{1}", count, singlePack.unlockedGridCount));
         
     }

--
Gitblit v1.8.0