107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Linq;
|
|||
|
using UnityEngine.Events;
|
|||
|
public class Personnelpreparation : MonoBehaviour
|
|||
|
{
|
|||
|
private Button closeBtn;
|
|||
|
private ScrollRect scrollView;
|
|||
|
private List<Transform> subObjects; // <20><><EFBFBD>ڴ洢Scroll View<65><77>Content<6E>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Transform<72>б<EFBFBD>
|
|||
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>仯ʱ<E4BBAF><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public UnityEvent onStatusChanged;
|
|||
|
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
closeBtn=transform.Find("bg/top/closeBtn").GetComponent<Button>();
|
|||
|
closeBtn.onClick.AddListener(OnClickCloseBtn);
|
|||
|
scrollView=transform.Find("bg/mid/Scroll View").GetComponent<ScrollRect>();
|
|||
|
if (scrollView != null)
|
|||
|
{
|
|||
|
subObjects = new List<Transform>();
|
|||
|
UpdateSubObjectList(); // <20><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>ȡ<EFBFBD><C8A1><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
|||
|
// Ϊÿ<CEAA><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ItemInfo<66><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>仯<EFBFBD><E4BBAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
foreach (Transform subObject in subObjects)
|
|||
|
{
|
|||
|
ItemInfo itemInfo = subObject.GetComponent<ItemInfo>();
|
|||
|
if (itemInfo != null)
|
|||
|
{
|
|||
|
itemInfo.statusChanged.AddListener(OnStatusChanged);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
SortSubObjects();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("δ<><CEB4>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD> Scroll View<65><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飡");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
private void UpdateSubObjectList()
|
|||
|
{
|
|||
|
Transform contentTransform = scrollView.content;
|
|||
|
subObjects.Clear();
|
|||
|
// <20><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>Content<6E>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
for (int i = 0; i < contentTransform.childCount; i++)
|
|||
|
{
|
|||
|
subObjects.Add(contentTransform.GetChild(i));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnStatusChanged()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>仯ʱ<E4BBAF><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (onStatusChanged != null)
|
|||
|
{
|
|||
|
onStatusChanged.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SortSubObjects()
|
|||
|
{
|
|||
|
//ʹ<><CAB9>Linq<6E><71><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
subObjects = subObjects.OrderByDescending(sub => sub.GetComponent<ItemInfo>().status == "<22><><EFBFBD><EFBFBD>")
|
|||
|
.ThenBy(sub => sub.GetComponent<ItemInfo>().status == "<><D7BC><EFBFBD><EFBFBD>")
|
|||
|
.ThenBy(sub => sub.GetComponent<ItemInfo>().accountName)
|
|||
|
.ToList();
|
|||
|
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Content<6E>µ<EFBFBD>˳<EFBFBD><CBB3>
|
|||
|
|
|||
|
for (int i = 0; i < subObjects.Count; i++)
|
|||
|
{
|
|||
|
subObjects[i].SetParent(scrollView.content.transform);
|
|||
|
subObjects[i].SetSiblingIndex(i);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
// <20><>Update<74>м<EFBFBD><D0BC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (onStatusChanged != null && onStatusChanged.GetPersistentEventCount() > 0)
|
|||
|
{
|
|||
|
SortSubObjects();
|
|||
|
onStatusChanged.RemoveAllListeners(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
UpdateSubObjectList(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
foreach (Transform subObject in subObjects)
|
|||
|
{
|
|||
|
ItemInfo itemInfo = subObject.GetComponent<ItemInfo>();
|
|||
|
if (itemInfo != null)
|
|||
|
{
|
|||
|
itemInfo.statusChanged.AddListener(OnStatusChanged);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
void OnClickCloseBtn()
|
|||
|
{
|
|||
|
Game.uiManager.CloseUI("Panel");
|
|||
|
}
|
|||
|
}
|