SandTable.cs 5.6 KB

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