PKMatchingView.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class PKMatchingView : MonoBehaviour
  7. {
  8. [SerializeField] Sprite[] matchHeadBGList;
  9. float waitingTime = 0;
  10. void Awake()
  11. {
  12. }
  13. void Start()
  14. {
  15. (Sprite avatar, string nickname) = RoleMgr.GetRoleInfo(0);
  16. RenderPlayerInfo(1, avatar, nickname, true);
  17. RenderPlayerInfo(2, null, "", false);
  18. }
  19. void Update() {
  20. waitingTime += Time.deltaTime;
  21. this.transform.Find("BoxRight/TimeBG").GetComponentInChildren<Text>().text = TimeUtil.GetTimeStr(waitingTime, false);
  22. }
  23. void RenderPlayerInfo(int playerID, Sprite avatar, string nickname, bool active) {
  24. this.transform.Find($"BoxRight/Player{playerID}/NameBox")
  25. .GetComponentInChildren<Text>().text = active ? nickname : "等待加入";
  26. Transform avatarT = this.transform.Find($"BoxRight/Player{playerID}/MatchHeadBG/Avatar");
  27. avatarT.gameObject.SetActive(active);
  28. avatarT.Find("Sprite").GetComponent<Image>().sprite = avatar;
  29. }
  30. void ChangeMatchHeadBG(int typeIndex) {
  31. Image img = this.transform.Find("BoxRight/Player2/MatchHeadBG").GetComponent<Image>();
  32. img.sprite = matchHeadBGList[typeIndex];
  33. img.GetComponent<Button>().enabled = typeIndex == 1;
  34. }
  35. public void Back() {
  36. AudioMgr.ins.PlayBtn();
  37. Destroy(this.gameObject);
  38. }
  39. }