ItemSenceView.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using ShadowStudio.Model;
  2. using ShadowStudio.UI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Threading;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using XRTool.Util;
  10. public class ItemSenceView : MonoBehaviour
  11. {
  12. public Button sceneBtn;
  13. public Button deleteBtn;
  14. public GameObject checkImage;
  15. public Text nameText;
  16. private int senceId;
  17. private void Start()
  18. {
  19. sceneBtn.onClick.AddListener(OnClickChange);
  20. deleteBtn.onClick.AddListener(OnClickDelete);
  21. //ArtInfoMgr.Instance.ContainerCreate += OnContainerChange;
  22. //ArtInfoMgr.Instance.ContainerDel += OnContainerChange;
  23. }
  24. private void OnClickChange()
  25. {
  26. if (checkImage.activeSelf)
  27. {
  28. return;
  29. }
  30. WSHandler.Room.ChangeScene(this.senceId);
  31. }
  32. public void OnClickDelete()
  33. {
  34. WSHandler.Room.DeleteScene(this.senceId);
  35. }
  36. public void Init(int senceId, string sceneName, SceneConfig currentScene, bool isShow = true)
  37. {
  38. nameText.text = sceneName;
  39. ShowViewMgr.RemoteSenceAction += RemoveSence;
  40. ShowViewMgr.ChooseSenceAction += ChooseSence;
  41. this.senceId = senceId;
  42. ChooseSence(currentScene);
  43. if (isShow)
  44. {
  45. deleteBtn.gameObject.SetActive(true);
  46. }
  47. else
  48. {
  49. deleteBtn.gameObject.SetActive(false);
  50. }
  51. }
  52. private void ChooseSence(SceneConfig currentScene)
  53. {
  54. if (this.senceId == currentScene.Id)
  55. {
  56. nameText.text = currentScene.SceneName;
  57. FileListDlg.ChooseSceneName?.Invoke(nameText.text);
  58. if (checkImage)
  59. {
  60. checkImage.SetActive(true);
  61. }
  62. }
  63. else
  64. {
  65. if (checkImage)
  66. {
  67. checkImage.SetActive(false);
  68. }
  69. }
  70. }
  71. private void RemoveSence(List<SceneConfig> remainscene)
  72. {
  73. for (int i = 0; i < remainscene.Count; i++)
  74. {
  75. if (senceId == remainscene[i].Id)
  76. {
  77. Destroy(this.gameObject);
  78. }
  79. }
  80. }
  81. private void OnDestroy()
  82. {
  83. //ArtInfoMgr.Instance.ContainerCreate -= OnContainerChange;
  84. //ArtInfoMgr.Instance.ContainerDel -= OnContainerChange;
  85. ShowViewMgr.RemoteSenceAction -= RemoveSence;
  86. ShowViewMgr.ChooseSenceAction -= ChooseSence;
  87. }
  88. //private void OnContainerChange(ArtContainer obj)
  89. //{
  90. // int count = 0;
  91. // if (GameNode.Instance.PageGoodsIdCount.ContainsKey(this.senceId))
  92. // {
  93. // count = GameNode.Instance.PageGoodsIdCount[this.senceId];
  94. // }
  95. // int num = this.transform.GetSiblingIndex() + 1;
  96. // nameText.text = sceneNamePre + num + "(" + count + ")";
  97. //}
  98. }