62 lines
1.9 KiB
C#
Raw Normal View History

using Assets.Scenes.Ride.Scripts.Model;
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
using Assets.Scripts;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
public class WatcherFactory : MonoBehaviour
{
private Transform content { get; set; }
private CyclingController cyclingController { get;set;}
private GameObject watcher { get; set; }
private GameObject head { get; set; }
private Text watchNum { get; set; }
private void Awake()
{
cyclingController = FindObjectOfType<CyclingController>();
content = transform.Find("List/Viewport/Content");
head = transform.Find("Head").gameObject;
watchNum = transform.Find("Head/OnlineUserNum").GetComponent<Text>();
2021-09-03 13:06:26 +08:00
#if UNITY_IOS || UNITY_ANDROID
watcher = Resources.Load<GameObject>("UI/Prefab/Match/Mobile/Watcher");
#else
watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
2021-09-03 13:06:26 +08:00
#endif
}
private float t = 1f;
private void Update()
{
t -= Time.deltaTime;
while (t<=0)
{
CreateList();
t = 1;
}
}
2021-07-26 14:09:21 +08:00
private const int MAX_COUNT = 7;
private void CreateList()
{
var watchList = cyclingController.GetWatcherList();
var count = watchList.Count();
2021-07-26 14:09:21 +08:00
head.SetActive(count>= MAX_COUNT);
watchNum.text = count.ToString();//绑定观看人数
2021-07-26 14:09:21 +08:00
var list = watchList.Take(MAX_COUNT);
Utils.DestroyChildren(content);
foreach (var item in list)
{
var head = Instantiate(watcher, content);
var headiamge = head.GetComponent<RawImage>();
Utils.DisplayImage(headiamge, item.HeadImage, true);
}
}
}
}