SRTitleLayout.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using SC.XR.Unity;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /// <summary>
  6. /// 单排平铺
  7. /// </summary>
  8. public class SRTitleLayout : MonoBehaviour
  9. {
  10. /// <summary>
  11. /// 根据素材数量对物体进行布局组合
  12. /// 忽略文字类型
  13. /// </summary>
  14. /// <param name="materialObls">素材</param>
  15. /// <param name="par">素材父物体,景点</param>
  16. /// <returns></returns>
  17. public static List<ObjectValue> CalLayout(SpoitValue spoitjd, MaterialObl materialObls, GameObject par, out MaterialObl newmaterial,string type ="1")
  18. {
  19. var yangshi = ResMgr.Instance.Load<GameObject>("Template/Prefab/yangshi" + materialObls.typesetting);
  20. GameObject ys = Instantiate((yangshi as GameObject), par.transform);
  21. YangShiManager ysm = ys.GetComponent<YangShiManager>();
  22. ys.transform.localEulerAngles = Vector3.zero;
  23. ys.transform.localScale = new Vector3(1, 1, 1);
  24. newmaterial = materialObls;
  25. BaseTemPlate text = new BaseTemPlate();
  26. List<BaseTemPlate> noText = new List<BaseTemPlate>();
  27. MaterialObjValue textmat = null;
  28. List<ObjectValue> objectValues = new List<ObjectValue>();
  29. ysm.yangshiText.gameObject.SetActive(false);
  30. Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + materialObls.materialList.Count);
  31. for (int i = 0; i < materialObls.materialList.Count; i++)
  32. {
  33. var mat = materialObls.materialList[i];
  34. Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + mat.type);
  35. GameObject go = null;
  36. switch (mat.type)
  37. {
  38. case (int)MaterialType.None:
  39. ysm.yangshiList[i].Close();
  40. break;
  41. case (int)MaterialType.Image:
  42. go = ysm.yangshiList[i].showimg();
  43. var imageitem = go.AddComponent<TemplateImage>();
  44. go.SetActive(true);
  45. imageitem.SetData(mat, materialObls.updateTime);
  46. noText.Add(imageitem);
  47. break;
  48. case (int)MaterialType.Video:
  49. go = ysm.yangshiList[i].showvideo();
  50. var videoitem = go.AddComponent<TemplateVideo>();
  51. videoitem.autoplay = materialObls.autoplay;
  52. go.SetActive(true);
  53. videoitem.SetData(mat, materialObls.updateTime);
  54. noText.Add(videoitem);
  55. break;
  56. case (int)MaterialType.Text:
  57. textmat = mat;
  58. go = ysm.yangshiText.gameObject;
  59. var textitem = go.AddComponent<TemplateText>();
  60. go.SetActive(true);
  61. textitem.SetData(mat, materialObls.updateTime);
  62. text = textitem;
  63. break;
  64. default:
  65. ysm.yangshiList[i].Close();
  66. break;
  67. }
  68. if (go != null)
  69. {
  70. if (!GameManager.Instance.allobjs.ContainsKey(spoitjd.id.ToString()))
  71. {
  72. GameManager.Instance.allobjs.Add(spoitjd.id.ToString(), new Dictionary<string, Dictionary<string, GameObject>>());
  73. }
  74. if (!GameManager.Instance.allobjs[spoitjd.id.ToString()].ContainsKey(materialObls.id.ToString()))
  75. {
  76. GameManager.Instance.allobjs[spoitjd.id.ToString()].Add(materialObls.id.ToString(), new Dictionary<string, GameObject>());
  77. }
  78. if (!GameManager.Instance.allobjs[spoitjd.id.ToString()][materialObls.id.ToString()].ContainsKey(mat.id.ToString()))
  79. {
  80. GameManager.Instance.allobjs[spoitjd.id.ToString()][materialObls.id.ToString()].Add(mat.id.ToString(), go);
  81. }
  82. else
  83. {
  84. GameManager.Instance.allobjs[spoitjd.id.ToString()][materialObls.id.ToString()][mat.id.ToString()] = go;
  85. }
  86. Debug.Log("HJJSSSSSSSSSSSSSSSS获取 ===》" + spoitjd.id.ToString() + "_" + materialObls.id.ToString() + "_" + mat.id.ToString());
  87. go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name;
  88. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  89. if (materialObls.select)
  90. {
  91. go.transform.localPosition = mat.ObjectTransform.nowPos;
  92. go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
  93. go.transform.localScale = mat.ObjectTransform.nowScale;
  94. }
  95. else
  96. {
  97. if (mat.type != (int)MaterialType.Text)
  98. {
  99. go.transform.localPosition = Vector3.zero;
  100. }
  101. else
  102. {
  103. //Set text position
  104. if (mat.textPosition == "top")
  105. {
  106. go.transform.localPosition = new Vector3(0, ysm.yangshiText.topf, 0);
  107. }
  108. else if (mat.textPosition == "bottom")
  109. {
  110. go.transform.localPosition = new Vector3(0, ysm.yangshiText.buttomf, 0);
  111. }
  112. }
  113. mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  114. }
  115. ObjectValue objectValue = new ObjectValue(i, materialObls.id, mat.name, go);
  116. objectValues.Add(objectValue);
  117. }
  118. }
  119. #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回
  120. if (!materialObls.select)
  121. {
  122. if(type !="1") // 判断是不是巨幕
  123. {
  124. if (objectValues.Count > 0)
  125. {
  126. objectValues[0].Object.transform.parent.localScale=new Vector3(3,3,3);
  127. }
  128. }
  129. }
  130. if (textmat != null)
  131. {
  132. text.gameObject.SetActive(true);
  133. }
  134. #endregion
  135. return objectValues;
  136. }
  137. /// <summary>
  138. /// 根据素材数量对物体进行布局组合
  139. /// 忽略文字类型
  140. /// </summary>
  141. /// <param name="materialObls">素材</param>
  142. /// <param name="par">素材父物体,景点</param>
  143. /// <returns></returns>
  144. public static IEnumerator CalLayout(ModelList materialObls, GameObject par)
  145. {
  146. var yangshi = ResMgr.Instance.LoadAsync<GameObject>("Template/Prefab/yangshi" + materialObls.typesetting);
  147. yield return yangshi;
  148. GameObject ys = Instantiate((yangshi.asset as GameObject), par.transform);
  149. YangShiManager ysm = ys.GetComponent<YangShiManager>();
  150. ys.transform.localEulerAngles = Vector3.zero;
  151. ys.transform.localScale = new Vector3(1, 1, 1);
  152. BaseTemPlate text = new BaseTemPlate();
  153. List<BaseTemPlate> noText = new List<BaseTemPlate>();
  154. ModelItem textmat = null;
  155. List<ObjectValue> objectValues = new List<ObjectValue>();
  156. for (int i = 0; i < materialObls.materialList.Count; i++)
  157. {
  158. var mat = materialObls.materialList[i];
  159. GameObject go = null;
  160. switch (mat.type)
  161. {
  162. case (int)MaterialType.None:
  163. break;
  164. case (int)MaterialType.Image:
  165. go = ysm.yangshiList[i].showimg();
  166. var imageitem = go.AddComponent<TemplateImage>();
  167. go.SetActive(true);
  168. // imageitem.SetData(mat, materialObls.updateTime);
  169. noText.Add(imageitem);
  170. break;
  171. case (int)MaterialType.Video:
  172. go = ysm.yangshiList[i].showvideo();
  173. var videoitem = go.AddComponent<TemplateVideo>();
  174. videoitem.autoplay = materialObls.autoplay;
  175. go.SetActive(true);
  176. // videoitem.SetData(mat, materialObls.updateTime);
  177. noText.Add(videoitem);
  178. break;
  179. case (int)MaterialType.Text:
  180. go = ysm.yangshiText.gameObject;
  181. var textitem = go.AddComponent<TemplateText>();
  182. go.SetActive(true);
  183. // textitem.SetData(mat, materialObls.updateTime);
  184. text = textitem;
  185. go.SetActive(false);
  186. break;
  187. default:
  188. break;
  189. }
  190. if (go != null)
  191. {
  192. go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name;
  193. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  194. if (materialObls.select)
  195. {
  196. go.transform.localPosition = mat.objectTransform.nowPos;
  197. go.transform.localEulerAngles = mat.objectTransform.nowRot;
  198. go.transform.localScale = mat.objectTransform.nowScale;
  199. }
  200. else
  201. {
  202. if (mat.type != (int)MaterialType.Text)
  203. {
  204. go.transform.localPosition = Vector3.zero;
  205. }
  206. else
  207. {
  208. //Set text position
  209. if (mat.textPosition == "top")
  210. {
  211. go.transform.localPosition = new Vector3(0, ysm.yangshiText.topf, 0);
  212. }
  213. else if (mat.textPosition == "bottom")
  214. {
  215. go.transform.localPosition = new Vector3(0, ysm.yangshiText.buttomf, 0);
  216. }
  217. }
  218. mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  219. }
  220. mat.prefabModel = go;
  221. }
  222. }
  223. #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回
  224. if (textmat != null)
  225. {
  226. text.gameObject.SetActive(true);
  227. }
  228. #endregion
  229. }
  230. /// <summary>
  231. /// 排列顺序
  232. /// </summary>
  233. /// <param name="data"></param>
  234. /// <param name="game"></param>
  235. public static void Column(List<BaseTemPlate> data, GameObject game)
  236. {
  237. var scgrid = game.AddComponent<SCGridLayoutGroup>();
  238. scgrid.IsIgnoreInactiveObj = true;
  239. scgrid.LayoutType = LayoutTypes.Vertical;
  240. scgrid.Rows = 1;
  241. scgrid.SpaceX = 0.7f;
  242. scgrid.RefreshInfo();
  243. Destroy(scgrid);
  244. }
  245. }