ScrollConf.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6. #endif
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using XRTool.Util;
  10. using XRTool.WorldUI;
  11. using static UnityEngine.UI.Toggle;
  12. namespace XRTool.UI
  13. {
  14. /// <summary>
  15. /// 滑动列表的配置
  16. /// </summary>
  17. public class ScrollConf : ScriptableObject
  18. {
  19. /// <summary>
  20. /// 列表的内容
  21. /// </summary>
  22. public List<IteamConf> iteamConfs;
  23. /// <summary>
  24. /// 显示数量
  25. /// </summary>
  26. public int showCount;
  27. /// <summary>
  28. /// 组件的尺寸
  29. /// </summary>
  30. public Vector2 cellSize;
  31. /// <summary>
  32. /// iteam的间隔,作用于layout
  33. /// </summary>
  34. public Vector3 cellSpace = Vector2.one * 10;
  35. /// <summary>
  36. /// 列表的元素载体
  37. /// </summary>
  38. public XRButtonToggle iteamPrefab;
  39. private ToggleGroup toggleGroup;
  40. public ToggleEvent onValueChanged;
  41. public virtual void InitData(XRScrollRect scroll)
  42. {
  43. //if (!toggleGroup)
  44. //{
  45. // toggleGroup = scroll.content.GetComponent<ToggleGroup>();
  46. //}
  47. //XRButtonToggle togglePrefab = iteamPrefab;
  48. //for (int i = 0; i < iteamConfs.Count; i++)
  49. //{
  50. // IteamConf item = iteamConfs[i];
  51. // item.index = i;
  52. // var prefab = item.iteamPrefab;
  53. // if (!prefab)
  54. // {
  55. // prefab = togglePrefab;
  56. // }
  57. // if (prefab)
  58. // {
  59. // var toggle = Instantiate(prefab);
  60. // UnityUtil.SetParent(scroll.content, toggle.transform);
  61. // toggle.isOn = false;
  62. // toggle.group = toggleGroup;
  63. // item.InitData(toggle);
  64. // onValueChanged = toggle.onValueChanged;
  65. // }
  66. //}
  67. }
  68. public void SetData()
  69. {
  70. }
  71. #if UNITY_EDITOR
  72. [MenuItem("Assets/Create/DataConf/ScrollConf", false, 0)]
  73. static void CreateDynamicConf()
  74. {
  75. UnityEngine.Object obj = Selection.activeObject;
  76. if (obj)
  77. {
  78. string path = AssetDatabase.GetAssetPath(obj);
  79. ScrollConf bullet = CreateInstance<ScrollConf>();
  80. if (bullet)
  81. {
  82. string confName = UnityUtil.TryGetName<ScrollConf>(path);
  83. AssetDatabase.CreateAsset(bullet, confName);
  84. }
  85. else
  86. {
  87. Debug.Log(typeof(ScrollConf) + " is null");
  88. }
  89. }
  90. }
  91. #endif
  92. }
  93. }