From c6ea64fb4e4755c4290bf5228d8cd463bc81c21f Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 13 十一月 2025 21:42:16 +0800
Subject: [PATCH] 0312 英雄之路红点受限每日任务开启;增加检测装备输出

---
 Main/Component/UI/Effect/BattleEffectPlayer.cs |  270 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 207 insertions(+), 63 deletions(-)

diff --git a/Main/Component/UI/Effect/BattleEffectPlayer.cs b/Main/Component/UI/Effect/BattleEffectPlayer.cs
index 2896e8e..8dbbc57 100644
--- a/Main/Component/UI/Effect/BattleEffectPlayer.cs
+++ b/Main/Component/UI/Effect/BattleEffectPlayer.cs
@@ -30,25 +30,62 @@
         }
     }
 
+    private Bone followedBone;
 
+    public bool isBindBone = false;
 
+    public bool isRedCamp = true;
     public EffectConfig effectConfig;
 
-    public float speedRate = 1f;
+    public float speedRate = 1.5f;
 
+    private float m_Alpha = 1f;
 
+    public float Alpha
+    {
+        get
+        {
+            return m_Alpha;
+        }
+        set
+        {
+            if (value == m_Alpha)
+                return;
 
+            m_Alpha = value;
+            OnAlphaChanged();
+        }
+    }
+
+    private void OnAlphaChanged()
+    {
+        if (spineComp != null)
+        {
+            var skeleton = spineComp.Skeleton;
+            skeleton.A = Alpha;
+            spineComp.LateUpdate();
+        }
+
+        for (int i = 0; i < rendererList.Count; i++)
+        {
+            var renderer = rendererList[i];
+            if (renderer != null && renderer.material != null && renderer.material.HasProperty("_Color"))
+            {
+                Color color = renderer.material.color;
+                color.a = Alpha;
+                renderer.material.color = color;
+            }
+        }
+    }
 
     [Header("鎾斁瀹屾瘯绔嬪嵆鍥炴敹")]
     public bool isReleaseImmediately = false;  //鐣岄潰鐗规晥涓�鑸笉闇�瑕佽嚜鎴戦攢姣侊紝璺熼殢鐣岄潰鎴栬�呯埗瀵硅薄閿�姣佸氨琛�
 
     public Action<BattleEffectPlayer> onDestroy;
 
-    [HideInInspector] public Canvas canvas = null;
-
     [HideInInspector] public GameObject effectTarget = null;
 
-    protected EffectPenetrationBlocker blocker = null;
+    protected RendererAdjuster blocker = null;
 
     protected bool isInit = false;
 
@@ -67,13 +104,19 @@
 
     public Action onComplete;
 
+    private bool isPlaying = false;
+
+    private float timer = 0f;
+
     protected virtual void OnEnable()
     {
-        if (spineComp != null)
-        {
-            //闅愯棌锛屼細鏈夐潤鎬佹樉绀洪棶棰�
-            spineComp.enabled = false;
-        }
+        // if (spineComp != null)
+        // {
+        //     //闅愯棌锛屼細鏈夐潤鎬佹樉绀洪棶棰�
+        //     spineComp.enabled = false;
+        // }
+
+        ApplySortingOrder();
     }
 
 
@@ -115,6 +158,18 @@
         }
         //  鏈夌壒鏁堝彲鑳藉甫spine鍙堝甫unity鐗规晥鐨勬儏鍐�
         spineComp = gameObject.GetComponentInChildren<SkeletonAnimation>(true);
+
+        if (effectConfig.effectPos != null && effectConfig.effectPos.Length >= 2)
+        {
+            rectTrans.anchoredPosition += new Vector2((isRedCamp ? 1f : -1f) * effectConfig.effectPos[0], effectConfig.effectPos[1]);
+        }
+
+        if (effectConfig.effectScale > 0f)
+        {
+            rectTrans.localScale *= effectConfig.effectScale;
+        }
+
+        spineComp.loop = effectConfig.isLoop != 0;
     }
 
     protected virtual void Clear()
@@ -148,24 +203,73 @@
         onComplete?.Invoke();
     }
 
+    public Func<bool> funcIsHeroFront;
+
+    public void SetSortingOrder(Func<bool> _isHeroFrontCallback)
+    {
+        funcIsHeroFront = _isHeroFrontCallback;
+
+        ApplySortingOrder();
+    }
+
+
+    public void ApplySortingOrder()
+    {
+        if (null != blocker && effectConfig != null && funcIsHeroFront != null)
+        {
+            bool isEffectFront = effectConfig.frontBack == 1;
+
+            bool isHeroFront = funcIsHeroFront();
+
+            int finalSortingOrder = isHeroFront ?
+                (isEffectFront ? BattleConst.ActiveHeroActionSortingOrder : BattleConst.ActiveHeroBackSortingOrder) : (isEffectFront ? BattleConst.UnactiveHeroFrontSortingOrder : BattleConst.UnactiveHeroBackSortingOrder);
+
+
+            blocker.SetSortingOrder(finalSortingOrder);
+        }
+    }
+
+    public void FollowBoneXY()
+    {
+        if (followedBone == null || !isBindBone)
+        {
+            return;
+        }
+
+        Vector2 vector2 = Vector2.zero;
+
+        if (effectConfig.effectPos != null && effectConfig.effectPos.Length >= 2)
+        {
+            vector2 = new Vector2((isRedCamp ? 1f : -1f) * effectConfig.effectPos[0], effectConfig.effectPos[1]);
+        }
+
+        if (spineComp != null)
+        {
+            spineComp.transform.localPosition = new Vector3(followedBone.WorldX + vector2.x, followedBone.WorldY + vector2.y, 0);
+        }
+
+        if (effectTarget != null)
+        {
+            effectTarget.transform.localPosition = new Vector3(followedBone.WorldX + vector2.x, followedBone.WorldY + vector2.y, 0);
+        }
+    }
+
     public virtual void Play(bool showLog = true)
     {
-
-
         if (!isInit)
+        {
+            InitComponent(showLog);
+            isInit = true;
+        }
+        else
+        {
+            //閬垮厤閲嶅鍒涘缓
+            if (!this.gameObject.activeSelf)
             {
-                InitComponent(showLog);
-                isInit = true;
+                this.gameObject.SetActive(true);
             }
-            else
-            {
-                //閬垮厤閲嶅鍒涘缓
-                if (!this.gameObject.activeSelf)
-                {
-                    this.gameObject.SetActive(true);
-                }
-                return;
-            }
+            return;
+        }
 
         if (EffectMgr.IsNotShowBySetting(effectId))
         {
@@ -184,15 +288,34 @@
             this.gameObject.SetActive(true);
         }
 
-        if (effectConfig.autoDestroy != 0)
-        {
-            GameObject.Destroy(gameObject, effectConfig.destroyDelay);
-        }
-
+        isPlaying = true;
+        timer = 0f;
 
         PlayEffect();
-        
+    }
 
+
+
+    public void Run()
+    {
+        if (null == effectConfig)
+        {
+            return;
+        }
+
+        if (!isPlaying)
+        {
+            return;
+        }
+
+        if (effectConfig.autoDestroy != 0)
+        {
+            timer += Time.deltaTime * speedRate;
+            if (timer >= effectConfig.destroyDelay)
+            {
+                GameObject.DestroyImmediate(gameObject);
+            }
+        }
     }
 
     protected virtual void PlayEffect()
@@ -204,7 +327,7 @@
         }
 
         //  濡傛灉delay灏忎簬绛変簬0 閭d細绔嬪埢鎵ц
-        this.DelayTime(effectConfig.delayPlay, () =>
+        this.DelayTime(effectConfig.delayPlay / speedRate, () =>
         {
             PlayEffectInternal();
         });
@@ -220,6 +343,7 @@
         {
             PlayUnityEffect();
         }
+        OnAlphaChanged();
     }
 
     protected void PlaySpineEffect()
@@ -237,26 +361,22 @@
         spineComp.Initialize(true);
         spineComp.timeScale = speedRate;
 
+        spineComp.skeleton.A = Alpha;
+
         spineAnimationState = spineComp.state;
         spineAnimationState.Complete -= OnSpineAnimationComplete;
         spineAnimationState.Complete += OnSpineAnimationComplete;
 
-
-        if (null == canvas)
-            canvas = GetComponentInParent<Canvas>();
-
         // 娣诲姞鐗规晥绌块�忛樆鎸″櫒
-        blocker = spineComp.AddMissingComponent<EffectPenetrationBlocker>();
+        blocker = spineComp.AddMissingComponent<RendererAdjuster>();
 
         blocker.onSortingChanged = OnSortingChanged;
 
-        //  濡傛灉娌℃湁canvas鐨勮瘽 姝e父鏄洜涓轰笉鍦˙attleWin涓嬮潰鐨勮妭鐐� 鎰忔�濆氨鏄綋鍓嶆病鏈夋樉绀� 绛夊埌鍒囧洖鎴樻枟鐨勬椂鍊欏啀閫氳繃BattleField.UpdateCanvas鏉ユ洿鏂�
-        if (canvas != null)
-        {
-            blocker.SetParentCanvas(canvas);
-        }
+        ApplySortingOrder();
 
         spineComp.enabled = true;
+
+        spineComp.timeScale = speedRate;
 
         Spine.Animation animation = spineAnimationState.Data.SkeletonData.Animations.First();
         spineAnimationState.SetAnimation(0, animation, effectConfig.isLoop != 0);
@@ -311,19 +431,11 @@
 
         OnUnityAnimationComplete();
 
-        if (null == canvas)
-            canvas = GetComponentInParent<Canvas>();
 
         // 娣诲姞鐗规晥绌块�忛樆鎸″櫒
-        blocker = effectTarget.AddMissingComponent<EffectPenetrationBlocker>();
+        blocker = effectTarget.AddMissingComponent<RendererAdjuster>();
 
         blocker.onSortingChanged = OnSortingChanged;
-
-        //  濡傛灉娌℃湁canvas鐨勮瘽 姝e父鏄洜涓轰笉鍦˙attleWin涓嬮潰鐨勮妭鐐� 鎰忔�濆氨鏄綋鍓嶆病鏈夋樉绀� 绛夊埌鍒囧洖鎴樻枟鐨勬椂鍊欏啀閫氳繃BattleField.UpdateCanvas鏉ユ洿鏂�
-        if (canvas != null)
-        {
-            blocker.SetParentCanvas(canvas);
-        }
 
         SoundPlayer.Instance.PlayUIAudio(effectConfig.audio);
 
@@ -341,9 +453,13 @@
 
     public string sortingLayer;
     public int sortingOrder;
+    public RectTransform rectTrans;
 
     protected void OnSortingChanged(string _sortingLayer, int _sortingOrder)
     {
+        if (null == spineComp)
+            return;
+            
         sortingLayer = _sortingLayer;
         sortingOrder = _sortingOrder;
         // 澶勭悊鎺掑簭鍙樺寲
@@ -402,17 +518,21 @@
 
 
     //  鍒涘缓鍚庣殑鐗规晥浼氳嚜鍔ㄩ殣钘� 闇�瑕佹墜鍔ㄨ皟鐢≒lay鎵嶈兘鎾斁
-    public static BattleEffectPlayer Create(int effectId, Transform parent)
+    public static BattleEffectPlayer Create(int effectId, Transform parent, bool isRedCamp)
     {
         // 鐩存帴鍒涘缓鐗规晥鎾斁鍣紝涓嶄娇鐢ㄥ璞℃睜
         BattleEffectPlayer battleEffectPlayer = null;
 
         GameObject newGo = new GameObject("BattleEffectPlayer_" + effectId);
         newGo.transform.SetParent(parent, false);
-        newGo.AddMissingComponent<RectTransform>();
         battleEffectPlayer = newGo.AddComponent<BattleEffectPlayer>();
+        battleEffectPlayer.rectTrans = newGo.AddMissingComponent<RectTransform>();
         
         battleEffectPlayer.effectId = effectId;
+
+        // 璁剧疆闃佃惀
+        battleEffectPlayer.isRedCamp = isRedCamp;
+
         battleEffectPlayer.SetActive(true);
         return battleEffectPlayer;
     }
@@ -430,7 +550,7 @@
 
     public void Pause()
     {
-        if (effectTarget == null) return;
+        // if (effectTarget == null) return;
 
         // Spine鍔ㄧ敾
         // var spineGraphics = effectTarget.GetComponentsInChildren<SkeletonGraphic>(true);
@@ -455,7 +575,7 @@
 
     public void Resume()
     {
-        if (effectTarget == null) return;
+        // if (effectTarget == null) return;
 
         if (spineComp != null)
         {
@@ -509,21 +629,45 @@
         return true;
     }
 
-    /// <summary>
-    /// 璁剧疆閬僵锛堟敮鎸丷ectMask2D銆丮ask銆丼moothMask绛夛級
-    /// </summary>
-    public void SetMask(RectTransform maskArea = null)
+    public void SetSpeedRatio(float ratio)
     {
-        if (effectTarget == null || blocker == null)
-            return;
-
-        // 浼樺厛浣跨敤浼犲叆鐨刴askArea
-        if (maskArea != null)
+        speedRate = ratio;
+        if (spineComp != null)
         {
-            blocker.PerformMask(maskArea);
-            return;
+            spineComp.timeScale = speedRate;
+        }
+
+        // Animator鍔ㄧ敾
+        foreach (var animator in animatorList)
+        {
+            animator.speed = speedRate;
         }
     }
 
+    public void BindBone(SkeletonAnimation skeletonAnim, string v)
+    {
+        Bone bone = skeletonAnim.skeleton.FindBone(v);
 
+        if (null == bone)
+        {
+             return;
+        }
+
+        isBindBone = true;
+        followedBone = bone;
+
+        BoneFollower boneFollower = gameObject.AddMissingComponent<BoneFollower>();
+        boneFollower.boneName = v;
+        boneFollower.skeletonRenderer = skeletonAnim;
+        
+        boneFollower.followBoneRotation = false;
+        boneFollower.followXYPosition = true;
+        boneFollower.followZPosition = false;
+        boneFollower.followLocalScale = false;
+        boneFollower.followParentWorldScale = false;
+        boneFollower.followSkeletonFlip = false;
+
+        boneFollower.Initialize();
+        boneFollower.LateUpdate();
+    }
 }

--
Gitblit v1.8.0