DRFanLayout.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 DRFanLayout : MonoBehaviour
  10. {
  11. public static List<ObjectValue> CalLayout(MaterialObl materialObls, GameObject par, out MaterialObl newmaterial)
  12. {
  13. Debug.LogError("HJJmaterialObls.select DRFanLayout " );
  14. newmaterial = materialObls;
  15. BaseTemPlate text = new BaseTemPlate();
  16. MaterialObjValue textmat = null;
  17. List<BaseTemPlate> noText = new List<BaseTemPlate>();
  18. List<ObjectValue> objectValues = new List<ObjectValue>();
  19. for (int i = 0; i < materialObls.materialList.Count; i++)
  20. {
  21. var mat = materialObls.materialList[i];
  22. GameObject go = null;
  23. switch (mat.type)
  24. {
  25. case (int)MaterialType.None:
  26. break;
  27. case (int)MaterialType.Image:
  28. var pImage = ResMgr.Instance.Load<GameObject>("Image");
  29. go = Instantiate(pImage, par.transform);
  30. var imageitem = go.AddComponent<TemplateImage>();
  31. go.SetActive(true);
  32. imageitem.SetData(mat, materialObls.updateTime);
  33. noText.Add(imageitem);
  34. break;
  35. case (int)MaterialType.Video:
  36. var pVideo = ResMgr.Instance.Load<GameObject>("Video");
  37. go = Instantiate(pVideo, par.transform);
  38. var videoitem = go.AddComponent<TemplateVideo>();
  39. videoitem.autoplay = materialObls.autoplay;
  40. go.SetActive(true);
  41. videoitem.SetData(mat, materialObls.updateTime);
  42. noText.Add(videoitem);
  43. break;
  44. case (int)MaterialType.Text:
  45. textmat = mat;
  46. var pText = ResMgr.Instance.Load<GameObject>("Text");
  47. go = Instantiate(pText, par.transform);
  48. var textitem = go.AddComponent<TemplateText>();
  49. go.SetActive(true);
  50. textitem.SetData(mat, materialObls.updateTime);
  51. text = textitem;
  52. go.SetActive(false);
  53. break;
  54. default:
  55. break;
  56. }
  57. Debug.LogError("HJJmaterialObls.select 123 " );
  58. if (go != null)
  59. {
  60. Debug.LogError("HJJmaterialObls.select 42121 " );
  61. go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name;
  62. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  63. if (materialObls.select)
  64. {
  65. Debug.LogError("HJJmaterialObls.select " + go.transform.name +" "+ mat.ObjectTransform.nowPos);
  66. go.transform.localPosition = mat.ObjectTransform.nowPos;
  67. go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
  68. go.transform.localScale = mat.ObjectTransform.nowScale;
  69. }
  70. else
  71. {
  72. go.transform.localEulerAngles = Vector3.zero;
  73. go.transform.localScale = new Vector3(1, 1, 1);
  74. if (mat.type != (int)MaterialType.Text)
  75. {
  76. go.transform.localPosition = Vector3.zero;
  77. }
  78. else
  79. {
  80. //Set text position
  81. if (mat.textPosition == "top")
  82. {
  83. go.transform.localPosition = new Vector3(0, 1f, 0);
  84. }
  85. else if (mat.textPosition == "bottom")
  86. {
  87. go.transform.localPosition = new Vector3(0, -1f, 0);
  88. }
  89. }
  90. mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  91. }
  92. ObjectValue objectValue = new ObjectValue(i, materialObls.id, mat.name, go);
  93. objectValues.Add(objectValue);
  94. }
  95. }
  96. #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回
  97. if (!materialObls.select)
  98. {
  99. Column(noText, par);
  100. //第一次排列后,需调整初始坐标和当前坐标保持一致
  101. for (int i = 0; i < objectValues.Count; i++)
  102. {
  103. objectValues[i].InitTransform();
  104. objectValues[i].Object.SetActive(true);
  105. var go = objectValues[i].Object;
  106. newmaterial.materialList[objectValues[i].ID].ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  107. }
  108. }
  109. if (textmat != null)
  110. {
  111. text.gameObject.SetActive(true);
  112. }
  113. #endregion
  114. return objectValues;
  115. }
  116. public static IEnumerator CalLayout(ModelList materialObls, GameObject par)
  117. {
  118. BaseTemPlate text = new BaseTemPlate();
  119. ModelItem textmat = null;
  120. List<BaseTemPlate> noText = new List<BaseTemPlate>();
  121. List<ObjectValue> objectValues = new List<ObjectValue>();
  122. for (int i = 0; i < materialObls.materialList.Count; i++)
  123. {
  124. var mat = materialObls.materialList[i];
  125. GameObject go = null;
  126. switch (mat.type)
  127. {
  128. case (int)MaterialType.None:
  129. break;
  130. case (int)MaterialType.Image:
  131. var pImage = ResMgr.Instance.LoadAsync<GameObject>("Image");
  132. yield return pImage;
  133. go = Instantiate(pImage.asset as GameObject, par.transform);
  134. var imageitem = go.AddComponent<TemplateImage>();
  135. go.SetActive(true);
  136. // imageitem.SetData(mat, materialObls.updateTime);
  137. noText.Add(imageitem);
  138. break;
  139. case (int)MaterialType.Video:
  140. var pVideo = ResMgr.Instance.LoadAsync<GameObject>("Video");
  141. yield return pVideo;
  142. go = Instantiate(pVideo.asset as GameObject, par.transform);
  143. var videoitem = go.AddComponent<TemplateVideo>();
  144. videoitem.autoplay = materialObls.autoplay;
  145. go.SetActive(true);
  146. // videoitem.SetData(mat, materialObls.updateTime);
  147. noText.Add(videoitem);
  148. break;
  149. case (int)MaterialType.Text:
  150. textmat = mat;
  151. var pText = ResMgr.Instance.LoadAsync<GameObject>("Text");
  152. yield return pText;
  153. go = Instantiate(pText.asset as GameObject, par.transform);
  154. var textitem = go.AddComponent<TemplateText>();
  155. go.SetActive(true);
  156. // textitem.SetData(mat, materialObls.updateTime);
  157. text = textitem;
  158. go.SetActive(false);
  159. break;
  160. default:
  161. break;
  162. }
  163. if (go != null)
  164. {
  165. go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name;
  166. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  167. if (materialObls.select)
  168. {
  169. go.transform.localPosition = mat.objectTransform.nowPos;
  170. go.transform.localEulerAngles = mat.objectTransform.nowRot;
  171. go.transform.localScale = mat.objectTransform.nowScale;
  172. }
  173. else
  174. {
  175. go.transform.localEulerAngles = Vector3.zero;
  176. go.transform.localScale = new Vector3(1, 1, 1);
  177. if (mat.type != (int)MaterialType.Text)
  178. {
  179. go.transform.localPosition = Vector3.zero;
  180. }
  181. else
  182. {
  183. //Set text position
  184. if (mat.textPosition == "top")
  185. {
  186. go.transform.localPosition = new Vector3(0, 0.3f, 0);
  187. }
  188. else if (mat.textPosition == "bottom")
  189. {
  190. go.transform.localPosition = new Vector3(0, -0.3f, 0);
  191. }
  192. }
  193. mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  194. }
  195. ObjectValue objectValue = new ObjectValue(i, materialObls.id, mat.name, go);
  196. objectValues.Add(objectValue);
  197. mat.prefabModel = go;
  198. // mat.initFrist();
  199. }
  200. }
  201. #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回
  202. if (!materialObls.select)
  203. {
  204. Column(noText, par);
  205. //第一次排列后,需调整初始坐标和当前坐标保持一致
  206. for (int i = 0; i < objectValues.Count; i++)
  207. {
  208. objectValues[i].InitTransform();
  209. objectValues[i].Object.SetActive(true);
  210. var go = objectValues[i].Object;
  211. materialObls.materialList[objectValues[i].ID].objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  212. }
  213. }
  214. if (textmat != null)
  215. {
  216. text.gameObject.SetActive(true);
  217. }
  218. #endregion
  219. }
  220. /// <summary>
  221. /// 根据数量排列图片或文字
  222. /// </summary>
  223. /// <param name="data">图片和视频列表</param>
  224. private static void Column(List<BaseTemPlate> data, GameObject game)
  225. {
  226. var scgrid = game.AddComponent<SCGridLayoutGroup>();
  227. scgrid.IsIgnoreInactiveObj = true;
  228. scgrid.LayoutType = LayoutTypes.Horizontal;
  229. scgrid.Columns = 3;
  230. scgrid.SpaceX = 0.7f;
  231. scgrid.SpaceY = 0.7f;
  232. scgrid.RefreshInfo();
  233. Destroy(scgrid);
  234. data[0].transform.localPosition += new Vector3(0, 0, -0.2f);
  235. data[0].transform.localRotation = Quaternion.Euler(0, -30, 0);
  236. if(data.Count>2)
  237. {
  238. data[2].transform.localPosition += new Vector3(0, 0, -0.2f);
  239. data[2].transform.localRotation = Quaternion.Euler(0, 30, 0);
  240. }
  241. if(data.Count>3)
  242. {
  243. data[3].transform.localPosition += new Vector3(0, 0, -0.2f);
  244. data[3].transform.localRotation = Quaternion.Euler(0, -30, 0);
  245. }
  246. if (data.Count < 6)
  247. Debug.LogWarning("双排扇形不足六个元素图片或视频");
  248. else
  249. {
  250. data[5].transform.localPosition += new Vector3(0, 0, -0.2f);
  251. data[5].transform.localRotation = Quaternion.Euler(0, 30, 0);
  252. }
  253. }
  254. }