SandTable.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using QFramework;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /// <summary>
  6. /// 打开时播放沙盘
  7. /// </summary>
  8. public class SandTable : MonoSingleton<SandTable>
  9. {
  10. public MaterialObjValue value;
  11. public int updateTime;
  12. public void OpenSandTable()
  13. {
  14. if(value ==null)
  15. {
  16. StartCoroutine(OpenPlanel(1));
  17. }
  18. else if ( value.DownloadPath != value.localSavePath)
  19. {
  20. MsgHandler.AddListener(value.DownloadPath, HandleMsg);
  21. LoadManager.Instance.LoadMaterial(value, updateTime);
  22. }
  23. else if( value.DownloadPath == value.localSavePath)
  24. {
  25. LoadLocalMaterial();
  26. }
  27. }
  28. /// <summary>
  29. /// 返回素材
  30. /// </summary>
  31. /// <param name="msg"></param>
  32. private void HandleMsg(Msg msg)
  33. {
  34. LoadMaterial(msg.Value);
  35. }
  36. /// <summary>
  37. /// 加载素材
  38. /// </summary>
  39. /// <param name="loaderObj"> 返回加载物体 </param>
  40. public void LoadMaterial(object loaderObj)
  41. {
  42. var loader = ResLoader.Allocate();
  43. switch ((MaterialType)int.Parse(value.type))
  44. {
  45. case MaterialType.Text:
  46. string path = "Resources/Template/Prefab/Text";
  47. //if (int.Parse(value.TextBJ) == 1)
  48. //{
  49. // path = "Resources/Template/Prefab/Text";
  50. //}
  51. var mText = loader.LoadSync<GameObject>(path);
  52. GameObject objText = (GameObject)mText.Instantiate();
  53. objText.GetComponent<SetTextV>().SetText(loaderObj.ToString());
  54. objText.transform.SetParent(transform);
  55. objText.name = value.name;
  56. objText.transform.Identity();
  57. break;
  58. case MaterialType.Image:
  59. var image = loader.LoadSync<GameObject>("Resources/Template/Prefab/Image");
  60. GameObject objImage = image.Instantiate();
  61. objImage.GetComponent<SetImageV>().SetImage((Sprite)loaderObj);
  62. objImage.transform.SetParent(transform);
  63. objImage.name = value.name;
  64. objImage.transform.Identity();
  65. break;
  66. case MaterialType.Video:
  67. var video = loader.LoadSync<GameObject>("Resources/Template/Prefab/Video");
  68. GameObject objVideo = video.Instantiate();
  69. objVideo.GetComponent<VideoControl>().VideoURL = loaderObj.ToString();
  70. objVideo.transform.SetParent(transform);
  71. objVideo.name = value.name;
  72. objVideo.transform.Identity();
  73. break;
  74. case MaterialType.Model:
  75. List<GameObject> listobj = (List<GameObject>)loaderObj;
  76. GameObject model = listobj[0];
  77. GameObject objModel = model.Instantiate();
  78. objModel.transform.SetParent(transform);
  79. objModel.name = value.name;
  80. objModel.transform.Identity();
  81. break;
  82. default:
  83. break;
  84. }
  85. MsgHandler.RemoveListener(value.DownloadPath, HandleMsg);
  86. StartCoroutine(OpenPlanel(15));
  87. }
  88. /// <summary>
  89. /// 加载本地素材
  90. /// </summary>
  91. public void LoadLocalMaterial()
  92. {
  93. Debug.Log(value.name + " 本地素材@@@@@@@@@@@@@");
  94. var loader = ResLoader.Allocate();
  95. switch ((MaterialType)int.Parse(value.type))
  96. {
  97. case MaterialType.Text:
  98. string path = "Resources/Template/Prefab/Text";
  99. if (int.Parse(value.TextBJ) == 1)
  100. {
  101. path = "Resources/Template/Prefab/Text111111111111111";
  102. }
  103. var mText = loader.LoadSync<GameObject>(path);
  104. GameObject objText = (GameObject)mText.Instantiate();
  105. objText.GetComponent<SetTextV>().SetText(value.textContent);
  106. objText.transform.SetParent(transform);
  107. objText.name = value.name;
  108. objText.transform.Identity();
  109. break;
  110. case MaterialType.Image:
  111. var image = loader.LoadSync<GameObject>("Resources/Template/Prefab/Image");
  112. GameObject objImage = image.Instantiate();
  113. objImage.GetComponent<SetImageV>().SetImage(loader.LoadSync<Sprite>(value.DownloadPath));
  114. objImage.transform.SetParent(transform);
  115. objImage.name = value.name;
  116. objImage.transform.Identity();
  117. break;
  118. case MaterialType.Video:
  119. var video = loader.LoadSync<GameObject>("Resources/Template/Prefab/Video");
  120. GameObject objVideo = video.Instantiate();
  121. objVideo.GetComponent<VideoControl>().VideoURL = value.DownloadPath;
  122. objVideo.transform.SetParent(transform);
  123. objVideo.name = value.name;
  124. objVideo.transform.Identity();
  125. break;
  126. case MaterialType.Model:
  127. GameObject model = loader.LoadSync<GameObject>(value.DownloadPath);
  128. GameObject objModel = model.Instantiate();
  129. objModel.transform.SetParent(transform);
  130. objModel.name = value.name;
  131. objModel.transform.Identity();
  132. break;
  133. default:
  134. break;
  135. }
  136. StartCoroutine(OpenPlanel(15));
  137. }
  138. IEnumerator OpenPlanel( float times)
  139. {
  140. yield return new WaitForSeconds(times);
  141. GameManager.Instance.OpenPlanel();
  142. gameObject.SetActive(false);
  143. }
  144. }