From 871594462e82d6bc1341918d39e11ab036d59563 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 18 九月 2025 19:26:28 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_scripts
---
Main/Component/UI/Effect/BattleEffectPlayer.cs | 173 +++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 111 insertions(+), 62 deletions(-)
diff --git a/Main/Component/UI/Effect/BattleEffectPlayer.cs b/Main/Component/UI/Effect/BattleEffectPlayer.cs
index 853ecf8..df7c822 100644
--- a/Main/Component/UI/Effect/BattleEffectPlayer.cs
+++ b/Main/Component/UI/Effect/BattleEffectPlayer.cs
@@ -30,13 +30,10 @@
}
}
-
-
+ public bool isRedCamp = true;
public EffectConfig effectConfig;
- public float speedRate = 1f;
-
-
+ public float speedRate = 1.5f;
[Header("鎾斁瀹屾瘯绔嬪嵆鍥炴敹")]
@@ -44,11 +41,9 @@
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;
@@ -63,9 +58,15 @@
protected SkeletonAnimation spineComp;
protected Spine.AnimationState spineAnimationState;
+ protected int heroSetedSortingOrder;
+
public GameObjectPoolManager.GameObjectPool pool;
public Action onComplete;
+
+ private bool isPlaying = false;
+
+ private float timer = 0f;
protected virtual void OnEnable()
{
@@ -115,6 +116,16 @@
}
// 鏈夌壒鏁堝彲鑳藉甫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;
+ }
}
protected virtual void Clear()
@@ -148,24 +159,43 @@
onComplete?.Invoke();
}
- public virtual void Play(bool showLog = true)
+ public void SetSortingOrder(int _heroSetedSortingOrder)
{
+ heroSetedSortingOrder = _heroSetedSortingOrder;
+ int so = heroSetedSortingOrder;
- if (!isInit)
+ if (null != blocker && effectConfig != null)
+ {
+ if (BattleConst.UnactiveHeroSortingOrder == heroSetedSortingOrder)
{
- InitComponent(showLog);
- isInit = true;
+ so = effectConfig.frontBack == 1 ? BattleConst.UnactiveHeroFrontSortingOrder : BattleConst.UnactiveHeroBackSortingOrder;
}
else
{
- //閬垮厤閲嶅鍒涘缓
- if (!this.gameObject.activeSelf)
- {
- this.gameObject.SetActive(true);
- }
- return;
+ so = effectConfig.frontBack == 1 ? BattleConst.ActiveHeroFrontSortingOrder : BattleConst.ActiveHeroBackSortingOrder;
}
+
+ blocker.SetSortingOrder(so);
+ }
+ }
+
+ public virtual void Play(bool showLog = true)
+ {
+ if (!isInit)
+ {
+ InitComponent(showLog);
+ isInit = true;
+ }
+ else
+ {
+ //閬垮厤閲嶅鍒涘缓
+ if (!this.gameObject.activeSelf)
+ {
+ this.gameObject.SetActive(true);
+ }
+ return;
+ }
if (EffectMgr.IsNotShowBySetting(effectId))
{
@@ -184,15 +214,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()
@@ -237,26 +286,19 @@
spineComp.Initialize(true);
spineComp.timeScale = speedRate;
- spineAnimationState = spineComp.AnimationState;
+ 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);
- }
-
spineComp.enabled = true;
+
+ spineComp.timeScale = speedRate;
+ spineAnimationState.TimeScale = speedRate;
Spine.Animation animation = spineAnimationState.Data.SkeletonData.Animations.First();
spineAnimationState.SetAnimation(0, animation, effectConfig.isLoop != 0);
@@ -311,19 +353,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 +375,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 +440,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 +472,7 @@
public void Pause()
{
- if (effectTarget == null) return;
+ // if (effectTarget == null) return;
// Spine鍔ㄧ敾
// var spineGraphics = effectTarget.GetComponentsInChildren<SkeletonGraphic>(true);
@@ -438,6 +480,11 @@
if (spineComp != null)
{
spineComp.timeScale = 0f;
+ }
+
+ if (spineAnimationState != null)
+ {
+ spineAnimationState.TimeScale = 0f;
}
// Animator鍔ㄧ敾
@@ -455,11 +502,16 @@
public void Resume()
{
- if (effectTarget == null) return;
+ // if (effectTarget == null) return;
if (spineComp != null)
{
spineComp.timeScale = speedRate;
+ }
+
+ if (spineAnimationState != null)
+ {
+ spineAnimationState.TimeScale = speedRate;
}
// Animator鍔ㄧ敾
@@ -509,21 +561,18 @@
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;
}
}
-
-
}
--
Gitblit v1.8.0