UIAddMaterial.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /****************************************************************************
  2. * 2022.1 SK-20211220VCWK
  3. ****************************************************************************/
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using QFramework;
  9. using UniRx;
  10. using System.Collections;
  11. using System.IO;
  12. namespace QFramework.MREditor
  13. {
  14. public partial class UIAddMaterial : UIElement
  15. {
  16. private void Awake()
  17. {
  18. }
  19. protected override void OnBeforeDestroy()
  20. {
  21. }
  22. public void Close()
  23. {
  24. gameObject.SetActive(false);
  25. }
  26. private CompositeMaterialValue selectObj;
  27. /// <summary>
  28. /// 根据传进来的Json文件 生成对应数据(主要是 用户自己上传的数据)
  29. /// </summary>
  30. public void Initialized( List<CompositeMaterialValue> localMaterials ,List<CompositeMaterialValue> upLocalMaterials ,SingleMaterial material )
  31. {
  32. selectObj = null;
  33. UCBtn.onClick.AddListener(() =>
  34. {
  35. if (LocalView.gameObject.activeSelf)
  36. return;
  37. LocalView.gameObject.SetActive(true);
  38. UpLoadView.gameObject.SetActive(false);
  39. });
  40. TicBtn.onClick.AddListener(() =>
  41. {
  42. if (UpLoadView.gameObject.activeSelf)
  43. return;
  44. LocalView.gameObject.SetActive(false);
  45. UpLoadView.gameObject.SetActive(true);
  46. });
  47. ADDBtn.onClick.AddListener(() =>
  48. {
  49. //Debug.Log(selectObj.name +" ?????????");
  50. // 添加选中素材
  51. //if (selectObj==null)
  52. // return;
  53. SendMsg(new OnAddNewMaterial(selectObj));
  54. });
  55. CloseBtn.onClick.AddListener(() =>
  56. {
  57. selectObj = null;
  58. Debug.Log("Close" + "@@@@");
  59. SendMsg(new OnUIOpenElenemt(true));
  60. });
  61. LocalContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, (localMaterials.Count / 3 + 1) * 140 + 25);
  62. localMaterials.ForEach(item =>
  63. {
  64. material.Instantiate()
  65. .Parent(LocalContent)
  66. .Identity()
  67. .ApplySelfTo(SelfObj =>
  68. {
  69. SelfObj.Name.text = item.name;
  70. SelfObj.GetComponent<Button>().onClick.AddListener(() => { selectObj = item; Debug.Log(item.name); });
  71. Vector3 pos = SelfObj.GetComponent<RectTransform>().anchoredPosition3D;
  72. SelfObj.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
  73. LoadSprite(SelfObj.Image, item);
  74. })
  75. .Show();
  76. });
  77. UpLoadContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, (upLocalMaterials.Count / 3 + 1) * 140 + 25);
  78. upLocalMaterials.ForEach(item =>
  79. {
  80. material.Instantiate()
  81. .Parent(UpLoadContent)
  82. .Identity()
  83. .ApplySelfTo(SelfObj =>
  84. {
  85. SelfObj.Name.text = item.name;
  86. SelfObj.GetComponent<Button>().onClick.AddListener(() => { selectObj = item; Debug.Log(item.name); });
  87. Vector3 pos = SelfObj.GetComponent<RectTransform>().anchoredPosition3D;
  88. SelfObj.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
  89. LoadSprite(SelfObj.Image, item);
  90. })
  91. .Show();
  92. });
  93. // Debug.Log(upLocalMaterials.Count);
  94. }
  95. /// <summary>
  96. /// 加载背景图片
  97. /// </summary>
  98. /// <param name="image"></param>
  99. /// <param name="objValue"></param>
  100. public void LoadSprite(Image image , CompositeMaterialValue objValue)
  101. {
  102. var loader = ResLoader.Allocate();
  103. if(objValue.icon.IsNullOrEmpty())
  104. {
  105. switch ((MaterialType)objValue.type)
  106. {
  107. case MaterialType.NULL:
  108. break;
  109. case MaterialType.Image:
  110. objValue.icon = "";
  111. break;
  112. case MaterialType.Video:
  113. objValue.icon = "";
  114. break;
  115. case MaterialType.Model:
  116. objValue.icon = "";
  117. break;
  118. case MaterialType.Text:
  119. objValue.icon = "";
  120. break;
  121. case MaterialType.ImageorViedoAndText:
  122. objValue.icon = "";
  123. break;
  124. case MaterialType.ModelAndText:
  125. objValue.icon = "";
  126. break;
  127. default:
  128. break;
  129. }
  130. // image.sprite = loader.LoadSync<Sprite>(objValue.icon);
  131. }
  132. else
  133. {
  134. if(objValue.icon.Contains("Resources/LocalMaterials"))
  135. {
  136. image.sprite = loader.LoadSync<Sprite>(objValue.icon);
  137. }
  138. else
  139. {
  140. Debug.Log("LoadManager.Instance.GetMaterial");
  141. object obj = LoadManager.Instance.GetMaterial(objValue.icon, objValue.updateTime);
  142. if (obj != null)
  143. image.sprite = (Sprite)obj;
  144. }
  145. //image.sprite = loader.LoadSync<Sprite>(objValue.icon);
  146. }
  147. //
  148. }
  149. }
  150. }