65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using Byn.Unity.Examples;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Pool;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
|
|
namespace SHINT.UI
|
|
{
|
|
public class UI_ActiveUserCount : MonoBehaviour
|
|
{
|
|
int userCount;
|
|
public GameObject prf_UserIcon;
|
|
TextMeshProUGUI userCounter;
|
|
Image activeState;
|
|
public RectTransform userIconContainer;
|
|
ObjectPool<GameObject> iconPool;
|
|
List<GameObject> activeIcons = new();
|
|
public override void AfterStart()
|
|
{
|
|
iconPool = new ObjectPool<GameObject>(CreateIcon, GetIcon, ReleaseIcon, null, true, 20);
|
|
}
|
|
|
|
void ReleaseIcon(GameObject icon)
|
|
{
|
|
activeIcons.Remove(icon);
|
|
icon.SetActive(false);
|
|
}
|
|
|
|
void GetIcon(GameObject icon)
|
|
{
|
|
activeIcons.Add(icon);
|
|
icon.SetActive(true);
|
|
}
|
|
|
|
GameObject CreateIcon()
|
|
{
|
|
var icon = Instantiate(prf_UserIcon);
|
|
icon.transform.SetParent(userIconContainer);
|
|
icon.transform.localScale = new Vector3(1, 1, 1);
|
|
icon.SetActive(false);
|
|
return icon;
|
|
}
|
|
public void SetActivateUserCount(int count)
|
|
{
|
|
activeState.color = count == 0 ? Color.gray : Color.green;
|
|
userCount = count;
|
|
//userCounter.text = userCount.ToString();
|
|
|
|
int c = activeIcons.Count;
|
|
for(int i =0;i<c;++i)
|
|
{
|
|
iconPool.Release(activeIcons[0]);
|
|
}
|
|
|
|
for(int i =0;i<count;++i)
|
|
{
|
|
var icon = iconPool.Get();
|
|
icon.GetComponent<UI_UserIcon>().SetId("Guest_"+i.ToString());
|
|
}
|
|
}
|
|
}
|
|
} |