From ee791f4c389d9a3f45f32532521eb20efd0d8a9a Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 15 九月 2025 10:25:49 +0800
Subject: [PATCH] 125 【战斗】战斗系统 层级问题处理
---
Main/System/Battle/BattleField/BattleField.cs | 16 ++--
Main/System/UIBase/UIBase.cs | 10 ++
Main/Component/UI/Common/RendererAdjuster.cs | 44 ++++------
Main/System/Battle/SkillEffect/NormalSkillEffect.cs | 4
Main/System/Battle/BattleConst.cs | 97 ++++++++++++++++++++++++
Main/System/Battle/BattleObject/BattleObject.cs | 37 ++++++++
Main/System/Battle/Skill/SkillBase.cs | 19 ++++
Main/Manager/UIManager.cs | 4
Main/System/Battle/BattleObject/BattleObjMgr.cs | 2
Main/System/Battle/SkillEffect/BulletSkillEffect.cs | 2
10 files changed, 192 insertions(+), 43 deletions(-)
diff --git a/Main/Component/UI/Common/RendererAdjuster.cs b/Main/Component/UI/Common/RendererAdjuster.cs
index 56b9b23..1a1977c 100644
--- a/Main/Component/UI/Common/RendererAdjuster.cs
+++ b/Main/Component/UI/Common/RendererAdjuster.cs
@@ -7,50 +7,42 @@
{
public int renderQueue = 3000;
- public Canvas canvas;
-
- public int sortingOrderOffset = 1;
+ public int sortingOrder = 0;
public string customSortingLayer = "UI";
public List<Renderer> renderers = new List<Renderer>();
+
+ public Action<string, int> onSortingChanged;
+
+ public void SetSortingOrder(int sortingOrder)
+ {
+ this.sortingOrder = sortingOrder;
+ UpdateComps();
+ UpdateSortingOrder();
+ }
public void Awake()
{
UpdateComps();
}
+ protected void OnEnable()
+ {
+ UpdateComps();
+ UpdateSortingOrder();
+ }
+
protected void UpdateComps()
{
renderers.Clear();
renderers.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
-
- canvas = GetComponentInParent<Canvas>();
- }
-
- public void SetParentCanvas(Canvas _canvas)
- {
- canvas = _canvas;
- this.DelayFrame(UpdateSortingOrder);
}
public void UpdateSortingOrder()
{
- int canvasSortingOrder = 0;
-
- // 鑾峰彇鐖剁骇Canvas鐨勬帓搴忛『搴�
- if (canvas != null)
- {
- canvasSortingOrder = canvas.sortingOrder;
- }
- else
- {
- // 濡傛灉娌℃湁鎵惧埌鐖剁骇Canvas锛屽垯浣跨敤榛樿鍊�
- canvasSortingOrder = 0;
- }
-
// 灏嗙壒鏁堢殑鎺掑簭椤哄簭璁剧疆涓篊anvas鎺掑簭椤哄簭鍔犱笂鍋忕Щ閲�
- ApplySortingSettings(canvasSortingOrder + sortingOrderOffset, customSortingLayer);
+ ApplySortingSettings(sortingOrder, customSortingLayer);
}
private void ApplySortingSettings(int sortingOrder, string sortingLayer)
@@ -68,5 +60,7 @@
}
}
}
+
+ onSortingChanged?.Invoke(sortingLayer, sortingOrder);
}
}
diff --git a/Main/Manager/UIManager.cs b/Main/Manager/UIManager.cs
index dec0ec4..b368998 100644
--- a/Main/Manager/UIManager.cs
+++ b/Main/Manager/UIManager.cs
@@ -50,7 +50,7 @@
private int currentRound = 0;
// 缂撳瓨灞傜骇瀵瑰簲鐨勬帓搴忛『搴�
- private Dictionary<UILayer, int> layerSortingOrderCache = new Dictionary<UILayer, int>();
+ private static Dictionary<UILayer, int> layerSortingOrderCache = new Dictionary<UILayer, int>();
// 缂撳瓨灞傜骇瀵瑰簲鐨凾ransform
private Dictionary<UILayer, Transform> layerTransformCache = new Dictionary<UILayer, Transform>();
@@ -136,7 +136,7 @@
#region 杈呭姪鏂规硶
// 鑾峰彇UI灞傜骇瀵瑰簲鐨勫熀纭�鎺掑簭椤哄簭
- private int GetBaseSortingOrderForLayer(UILayer layer)
+ public static int GetBaseSortingOrderForLayer(UILayer layer)
{
// 灏濊瘯浠庣紦瀛樹腑鑾峰彇鎺掑簭椤哄簭
if (layerSortingOrderCache.TryGetValue(layer, out int order))
diff --git a/Main/System/Battle/BattleConst.cs b/Main/System/Battle/BattleConst.cs
index 681e4b8..0f46bc4 100644
--- a/Main/System/Battle/BattleConst.cs
+++ b/Main/System/Battle/BattleConst.cs
@@ -7,4 +7,101 @@
public const int skillMotionFps = 30;
public const int BattlePointItemID = 3;//鎴橀敜ID
+
+
+ // 1000~10000涔嬮棿鐨勬垬鏂楀眰绾�
+ // 闇�瑕佽�冭檻鏍规嵁UI 鐗规晥 鎴樻枟瑙掕壊涓夋柟鐨勫眰绾у叧绯�
+ // 纭珛鍩烘湰鐨勫眰绾ц寖鍥� 鍚庡線涓婄疮鍔�
+ // 1.涓嶈兘鍦˙attleWin涔嬩笅 鍚﹀垯灏辩湅涓嶈浜�
+ // 2.澶勭悊EffectPenetrationBlocker鐨勮嚜鍔ㄨ皟鏁存帓搴�
+ // 3.瑕佽仈鍔‥ffectConfig鐨勫墠鍚庣殑闂
+ // BattleWin.Canvas.sortingOrder鏄渶浣庡��
+ // 杩橀渶瑕佺‘绔嬮粦鑹茬殑Mask鐨勫眰绾�
+
+
+ // UI鐣岄潰|闈炴縺娲昏嫳闆剕鎸℃澘|婵�娲昏嫳闆�
+
+ // 闈炴縺娲昏嫳闆勫悗鐗规晥|闈炴縺娲昏嫳闆剕闈炴縺娲昏嫳闆勫墠
+
+ // 婵�娲昏嫳闆勫悗鐗规晥|婵�娲昏嫳闆剕婵�娲昏嫳闆勫墠鐗规晥
+
+ public const int BattleBlackTransparentMaskOffset = 100;
+
+
+ public static int BattleWinSortingOrder
+ {
+ get
+ {
+
+ BattleWin battleWin = UIManager.Instance.GetUI<BattleWin>();
+ if (battleWin != null)
+ {
+ return battleWin.GetSortingOrder();
+ }
+ return 0;
+ }
+ }
+
+ // 闈炴縺娲昏嫳闆勭殑灞傜骇
+ public static int UnactiveHeroSortingOrder
+ {
+ get
+ {
+ return BattleWinSortingOrder + BattleBlackTransparentMaskOffset - 50;
+ }
+ }
+
+ // 闈炴縺娲昏嫳闆勭殑鍚庣壒鏁�
+ public static int UnactiveHeroBackSortingOrder
+ {
+ get
+ {
+ return UnactiveHeroSortingOrder - 1;
+ }
+ }
+
+ // 闈炴縺娲昏嫳闆勭殑鍓嶇壒鏁�
+ public static int UnactiveHeroFrontSortingOrder
+ {
+ get
+ {
+ return UnactiveHeroSortingOrder + 1;
+ }
+ }
+
+ // 鎸℃澘鐨勫眰绾�
+ public static int BlockerSortingOrder
+ {
+ get
+ {
+ return UnactiveHeroFrontSortingOrder + 1;
+ }
+ }
+
+ // 婵�娲昏嫳闆勭殑灞傜骇
+ public static int ActiveHeroSortingOrder
+ {
+ get
+ {
+ return BattleWinSortingOrder + BattleBlackTransparentMaskOffset + 50;
+ }
+ }
+
+ // 婵�娲昏嫳闆勭殑鍚庣壒鏁�
+ public static int ActiveHeroBackSortingOrder
+ {
+ get
+ {
+ return ActiveHeroSortingOrder - 1;
+ }
+ }
+
+ // 婵�娲昏嫳闆勭殑鍓嶇壒鏁�
+ public static int ActiveHeroFrontSortingOrder
+ {
+ get
+ {
+ return ActiveHeroSortingOrder + 1;
+ }
+ }
}
\ No newline at end of file
diff --git a/Main/System/Battle/BattleField/BattleField.cs b/Main/System/Battle/BattleField/BattleField.cs
index 19a23e5..b4dba55 100644
--- a/Main/System/Battle/BattleField/BattleField.cs
+++ b/Main/System/Battle/BattleField/BattleField.cs
@@ -373,14 +373,14 @@
}
}
- RendererAdjuster[] adjusters = battleRootNode.GetComponentsInChildren<RendererAdjuster>(true);
- if (null != adjusters)
- {
- foreach (var adjuster in adjusters)
- {
- adjuster.SetParentCanvas(canvas);
- }
- }
+ // RendererAdjuster[] adjusters = battleRootNode.GetComponentsInChildren<RendererAdjuster>(true);
+ // if (null != adjusters)
+ // {
+ // foreach (var adjuster in adjusters)
+ // {
+ // adjuster.SetParentCanvas(canvas);
+ // }
+ // }
}
public void StartBattle(Action onMoveComplete)
diff --git a/Main/System/Battle/BattleObject/BattleObjMgr.cs b/Main/System/Battle/BattleObject/BattleObjMgr.cs
index f19f5a6..a6f0e39 100644
--- a/Main/System/Battle/BattleObject/BattleObjMgr.cs
+++ b/Main/System/Battle/BattleObject/BattleObjMgr.cs
@@ -12,7 +12,7 @@
private Dictionary<int, BattleObject> redCampDict = new Dictionary<int, BattleObject>();
private Dictionary<int, BattleObject> blueCampDict = new Dictionary<int, BattleObject>();
- protected Dictionary<int, BattleObject> allBattleObjDict = new Dictionary<int, BattleObject>();
+ public Dictionary<int, BattleObject> allBattleObjDict = new Dictionary<int, BattleObject>();
protected BattleField battleField;
diff --git a/Main/System/Battle/BattleObject/BattleObject.cs b/Main/System/Battle/BattleObject/BattleObject.cs
index dfe291d..d086b64 100644
--- a/Main/System/Battle/BattleObject/BattleObject.cs
+++ b/Main/System/Battle/BattleObject/BattleObject.cs
@@ -65,6 +65,8 @@
}
}
+ public int sortingOrder = 0;
+
protected Action onDeathAnimationComplete;
protected Renderer[] renderers;
@@ -96,8 +98,9 @@
var heroInfoBarScale = heroInfoBar.transform.localScale;
heroInfoBarScale.x *= Camp == BattleCamp.Red ? 1 : -1;
heroInfoBar.transform.localScale = heroInfoBarScale;
-
+
heroInfoBar.SetActive(true);
+ SetToFront();
}
@@ -271,7 +274,7 @@
{
motionBase.PlayAnimation(MotionName.hit, false);
}
- }
+ }
public void SuckHp(uint suckHP, SkillConfig skillConfig)
{
@@ -280,7 +283,7 @@
public void HurtByReflect(uint bounceHP, SkillConfig skillConfig)
{
-
+
}
// 闂伩寮�濮�
@@ -386,6 +389,7 @@
heroRectTrans.anchoredPosition = Vector2.zero;
heroInfoBar.SetActive(false);
+ SetToFront();
}
public void PushDropItems(BattleDrops _battleDrops)
@@ -407,8 +411,35 @@
battleDrops = null;
}
+ public void SetToBack()
+ {
+ sortingOrder = BattleConst.UnactiveHeroSortingOrder;
+ UpdateSortingOrder();
+ }
+ public void SetToFront()
+ {
+ sortingOrder = BattleConst.ActiveHeroSortingOrder;
+ UpdateSortingOrder();
+ }
+ private void UpdateSortingOrder()
+ {
+ if (null == renderers) return;
+
+ foreach (var renderer in renderers)
+ {
+ if (renderer != null)
+ {
+ renderer.sortingOrder = sortingOrder;
+ }
+ }
+ }
+
+ public int GetSortingOrder()
+ {
+ return sortingOrder;
+ }
#if UNITY_EDITOR_STOP_USING
diff --git a/Main/System/Battle/Skill/SkillBase.cs b/Main/System/Battle/Skill/SkillBase.cs
index 2ce14ec..7e83c22 100644
--- a/Main/System/Battle/Skill/SkillBase.cs
+++ b/Main/System/Battle/Skill/SkillBase.cs
@@ -373,9 +373,26 @@
protected void HighLightAllTargets()
{
// 楂樹寒鎵�鏈夌洰鏍�
- HashSet<BattleObject> highlightList = new HashSet<BattleObject>(battleField.battleObjMgr.GetBattleObjList(tagUseSkillAttack));
+ List<BattleObject> highlightList = battleField.battleObjMgr.GetBattleObjList(tagUseSkillAttack);
highlightList.Add(caster);
+ List<BattleObject> allList = battleField.battleObjMgr.allBattleObjDict.Values.ToList<BattleObject>();
+
+ for (int i = 0; i < allList.Count; i++)
+ {
+ BattleObject bo = allList[i];
+ if (highlightList.Contains(bo))
+ {
+ bo.SetToFront();
+ }
+ else
+ {
+ bo.SetToBack();
+ }
+ }
+
+ // battleField.skillMask.SetActive(true);
+
// caster.battleField.skillMask
// 鎶婅繖浜汢O鍏ㄩ珮浜� 鎴栬�呰鎶婇櫎浜嗚繖浜涚殑閮芥斁鍦ㄩ伄缃╁悗闈�
// YYL TODO
diff --git a/Main/System/Battle/SkillEffect/BulletSkillEffect.cs b/Main/System/Battle/SkillEffect/BulletSkillEffect.cs
index 22d88ed..47cd4c1 100644
--- a/Main/System/Battle/SkillEffect/BulletSkillEffect.cs
+++ b/Main/System/Battle/SkillEffect/BulletSkillEffect.cs
@@ -336,7 +336,7 @@
if (effectId <= 0)
return;
- var effect = caster.battleField.battleEffectMgr.PlayEffect(0, effectId, parent, camp);
+ var effect = caster.battleField.battleEffectMgr.PlayEffect(caster.ObjID, effectId, parent, camp);
if (effect != null)
{
effect.transform.localRotation = parent.localRotation;
diff --git a/Main/System/Battle/SkillEffect/NormalSkillEffect.cs b/Main/System/Battle/SkillEffect/NormalSkillEffect.cs
index 0fa8e87..140ddf8 100644
--- a/Main/System/Battle/SkillEffect/NormalSkillEffect.cs
+++ b/Main/System/Battle/SkillEffect/NormalSkillEffect.cs
@@ -29,12 +29,12 @@
if (skillConfig.ExplosionEffectId > 0)
{
- caster.battleField.battleEffectMgr.PlayEffect(0, skillConfig.ExplosionEffectId, targetTransform, caster.Camp);
+ caster.battleField.battleEffectMgr.PlayEffect(caster.ObjID, skillConfig.ExplosionEffectId, targetTransform, caster.Camp);
}
if (skillConfig.ExplosionEffect2 > 0)
{
- caster.battleField.battleEffectMgr.PlayEffect(0, skillConfig.ExplosionEffect2, targetTransform, caster.Camp);
+ caster.battleField.battleEffectMgr.PlayEffect(caster.ObjID, skillConfig.ExplosionEffect2, targetTransform, caster.Camp);
}
for (int i = 0; i < tagUseSkillAttack.HurtList.Length; i++)
diff --git a/Main/System/UIBase/UIBase.cs b/Main/System/UIBase/UIBase.cs
index e81b824..59236e8 100644
--- a/Main/System/UIBase/UIBase.cs
+++ b/Main/System/UIBase/UIBase.cs
@@ -433,6 +433,16 @@
return UIEffectPlayer.CreateEffect(id, parent, false);
}
+
+ public int GetSortingOrder()
+ {
+ if (null != canvas)
+ {
+ return canvas.sortingOrder;
+ }
+
+ return 0;
+ }
#endregion
--
Gitblit v1.8.0