50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class testzzz : MonoBehaviour
|
|||
|
{
|
|||
|
private GameObject[] gameObjects;
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
public void UpdateNodeList()
|
|||
|
{
|
|||
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD> SpriteRenderer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GameObject
|
|||
|
List<GameObject> gameObjectsList = new List<GameObject>();
|
|||
|
foreach (Transform child in transform)
|
|||
|
{
|
|||
|
SpriteRenderer renderer = child.GetComponent<SpriteRenderer>();
|
|||
|
if (renderer != null)
|
|||
|
{
|
|||
|
gameObjectsList.Add(child.gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD> y <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
gameObjectsList.Sort((a, b) => a.transform.position.y.CompareTo(b.transform.position.y));
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD> sortingOrder <20><><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for (int i = 0; i < gameObjectsList.Count; i++)
|
|||
|
{
|
|||
|
Debug.Log(gameObjectsList[i].name);
|
|||
|
SpriteRenderer renderer = gameObjectsList[i].GetComponent<SpriteRenderer>();
|
|||
|
if (renderer != null)
|
|||
|
{
|
|||
|
renderer.sortingOrder = gameObjectsList.Count - i;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
private void FixedUpdate()
|
|||
|
{
|
|||
|
UpdateNodeList();
|
|||
|
}
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|