层级,有点说法

This commit is contained in:
GL 2024-12-24 18:02:36 +08:00
parent 312ed20f77
commit ad0b0d64fc
2 changed files with 25 additions and 12 deletions

View File

@ -311,6 +311,7 @@ MonoBehaviour:
- {fileID: 0}
- {fileID: 0}
moveSpeed: 1
speedFactor: 1
obj: {fileID: 4703411402842800732}
--- !u!114 &4703411402755586929
MonoBehaviour:
@ -327,6 +328,7 @@ MonoBehaviour:
retbutton: {fileID: 0}
ClosureObj: {fileID: 0}
id: 0
Name:
camp: 1
hp: 100
dieIndex: 1
@ -336,7 +338,18 @@ MonoBehaviour:
_Canvas: {fileID: 4205844203331515742}
spriteRenderers: {fileID: 4703411402842800734}
HurtDirectin: 0
Quality:
Elements:
Info:
SkillId:
AttackType:
AttackActionType:
AttackCD: 0
CritRate: 0
CriticalHitRateBonus: 0
gold: 10
MaxAttack: 10
MinAttack: 10
physicalArmor: 10
magicArmor: 5
Navigation: {fileID: 4703411402755586928}
@ -495,6 +508,8 @@ MonoBehaviour:
role: {fileID: 4703411402755586929}
panelPrefab: {fileID: 103310189314411435, guid: 750dbc96a3815eb4c85c7f89c206a43f, type: 3}
attackRange: {fileID: 0}
isShowPanel: 0
instantiatedPanel: {fileID: 0}
--- !u!1 &4703411402469012869
GameObject:
m_ObjectHideFlags: 0
@ -599,7 +614,7 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 97cc9a8eaafc8d24a849cc7f6ceb3b13, type: 3}
m_Sprite: {fileID: 21300000, guid: 5a21d33cca7048a46aed91d4e3e32ec3, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0

View File

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class ObJPool<T>
{
@ -87,17 +88,16 @@ public class SpawnPool : Base
}
public void UpdateNodeList()
{
// 获取所有带有 SpriteRenderer 组件的子物体
// 获取所有带有 SortingGroup 组件的物体
List<GameObject> gameObjectsList = new List<GameObject>();
foreach (GameObject go in EnemyPool.SurvivalPool)
{
// 获取所有子物体中具有 SpriteRenderer 组件的物体
SpriteRenderer renderer = go.GetComponentInChildren<SpriteRenderer>();
if (renderer != null)
// 获取该物体上的 SortingGroup 组件
SortingGroup sortingGroup = go.GetComponent<SortingGroup>();
if (sortingGroup != null)
{
// 添加到列表中
//Debug.Log("排序添加--------");
gameObjectsList.Add(go);
}
}
@ -105,16 +105,14 @@ public class SpawnPool : Base
// 按照 y 轴排序
gameObjectsList.Sort((a, b) => a.transform.position.y.CompareTo(b.transform.position.y));
// 设置 sortingOrder
// 设置 SortingGroup 的 sortingOrder
for (int i = 0; i < gameObjectsList.Count; i++)
{
SpriteRenderer renderer = gameObjectsList[i].GetComponentInChildren<SpriteRenderer>();
if (renderer != null)
SortingGroup sortingGroup = gameObjectsList[i].GetComponent<SortingGroup>();
if (sortingGroup != null)
{
// 设置 sortingOrder 来决定显示的层级
renderer.sortingOrder = gameObjectsList.Count-i;
//Debug.Log("排序--------");
sortingGroup.sortingOrder = gameObjectsList.Count - i;
}
}
}