SRTitleLayout.cs 12 KB

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