DRFanLayout.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 DRFanLayout : MonoBehaviour
  9. {
  10. public static List<ObjectValue> CalLayout(MaterialObl materialObls, GameObject par, out MaterialObl newmaterial)
  11. {
  12. newmaterial = materialObls;
  13. BaseTemPlate text = new BaseTemPlate();
  14. MaterialObjValue textmat = null;
  15. List<BaseTemPlate> noText = new List<BaseTemPlate>();
  16. List<ObjectValue> objectValues = new List<ObjectValue>();
  17. for (int i = 0; i < materialObls.materialList.Count; i++)
  18. {
  19. var mat = materialObls.materialList[i];
  20. GameObject go = null;
  21. switch (int.Parse(mat.type))
  22. {
  23. case (int)MaterialType.None:
  24. break;
  25. case (int)MaterialType.Image:
  26. var pImage = ResMgr.Instance.Load<GameObject>("Template/Prefab/Image");
  27. go = Instantiate(pImage, par.transform);
  28. var imageitem = go.AddComponent<TemplateImage>();
  29. go.SetActive(true);
  30. imageitem.SetData(mat, materialObls.updateTime);
  31. noText.Add(imageitem);
  32. break;
  33. case (int)MaterialType.Video:
  34. var pVideo = ResMgr.Instance.Load<GameObject>("Template/Prefab/Video");
  35. go = Instantiate(pVideo, par.transform);
  36. var videoitem = go.AddComponent<TemplateVideo>();
  37. go.SetActive(true);
  38. videoitem.SetData(mat, materialObls.updateTime);
  39. noText.Add(videoitem);
  40. break;
  41. case (int)MaterialType.Text:
  42. textmat = mat;
  43. var pText = ResMgr.Instance.Load<GameObject>("Template/Prefab/Text");
  44. go = Instantiate(pText, par.transform);
  45. var textitem = go.AddComponent<TemplateText>();
  46. go.SetActive(true);
  47. textitem.SetData(mat, materialObls.updateTime);
  48. text = textitem;
  49. go.SetActive(false);
  50. break;
  51. default:
  52. break;
  53. }
  54. if (go != null)
  55. {
  56. go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name;
  57. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(int.Parse(mat.type));
  58. if (materialObls.select)
  59. {
  60. go.transform.localPosition = mat.ObjectTransform.nowPos;
  61. go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
  62. go.transform.localScale = mat.ObjectTransform.nowScale;
  63. }
  64. else
  65. {
  66. go.transform.localEulerAngles = Vector3.zero;
  67. go.transform.localScale = new Vector3(1, 1, 1);
  68. if (int.Parse(mat.type) != (int)MaterialType.Text)
  69. {
  70. go.transform.localPosition = Vector3.zero;
  71. }
  72. else
  73. {
  74. //Set text position
  75. if (mat.textPosition == "top")
  76. {
  77. go.transform.localPosition = new Vector3(0, 0.3f, 0);
  78. }
  79. else if (mat.textPosition == "bottom")
  80. {
  81. go.transform.localPosition = new Vector3(0, -0.3f, 0);
  82. }
  83. }
  84. mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  85. }
  86. ObjectValue objectValue = new ObjectValue(i, materialObls.id, mat.name, go);
  87. objectValues.Add(objectValue);
  88. }
  89. }
  90. #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回
  91. if (!materialObls.select)
  92. {
  93. Column(noText, par);
  94. //第一次排列后,需调整初始坐标和当前坐标保持一致
  95. for (int i = 0; i < objectValues.Count; i++)
  96. {
  97. objectValues[i].InitTransform();
  98. objectValues[i].Object.SetActive(true);
  99. var go = objectValues[i].Object;
  100. newmaterial.materialList[objectValues[i].ID].ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  101. }
  102. }
  103. if (textmat != null)
  104. {
  105. text.gameObject.SetActive(true);
  106. }
  107. #endregion
  108. return objectValues;
  109. }
  110. /// <summary>
  111. /// 根据数量排列图片或文字
  112. /// </summary>
  113. /// <param name="data">图片和视频列表</param>
  114. private static void Column(List<BaseTemPlate> data, GameObject game)
  115. {
  116. var scgrid = game.AddComponent<SCGridLayoutGroup>();
  117. scgrid.IsIgnoreInactiveObj = true;
  118. scgrid.LayoutType = LayoutTypes.Horizontal;
  119. scgrid.Columns = 3;
  120. scgrid.SpaceX = 0.7f;
  121. scgrid.SpaceY = 0.7f;
  122. scgrid.RefreshInfo();
  123. Destroy(scgrid);
  124. data[0].transform.localPosition += new Vector3(0, 0, -0.2f);
  125. data[0].transform.localRotation = Quaternion.Euler(0, -30, 0);
  126. data[2].transform.localPosition += new Vector3(0, 0, -0.2f);
  127. data[2].transform.localRotation = Quaternion.Euler(0, 30, 0);
  128. data[3].transform.localPosition += new Vector3(0, 0, -0.2f);
  129. data[3].transform.localRotation = Quaternion.Euler(0, -30, 0);
  130. data[5].transform.localPosition += new Vector3(0, 0, -0.2f);
  131. data[5].transform.localRotation = Quaternion.Euler(0, 30, 0);
  132. }
  133. }