SRTitleLayout.cs 12 KB

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