UIWFPositionStore.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class UIWFPositionStore : MonoBehaviour
  6. {
  7. public void Apply()
  8. {
  9. if (this.positionData == null || this.parent == null)
  10. {
  11. return;
  12. }
  13. foreach (UIWFPositionStore.SerializData serializData in this.positionData)
  14. {
  15. if (!string.IsNullOrEmpty(serializData.objectPath))
  16. {
  17. GameObject childObject = UTY.GetChildObject(this.parent.gameObject, serializData.objectPath, true);
  18. if (!(childObject == null))
  19. {
  20. if (this.applyPosition)
  21. {
  22. childObject.transform.localPosition = serializData.localPosition;
  23. }
  24. if (this.applyActive)
  25. {
  26. childObject.gameObject.SetActive(serializData.active);
  27. }
  28. }
  29. }
  30. }
  31. }
  32. private void OnValidate()
  33. {
  34. if (this.parent == null)
  35. {
  36. return;
  37. }
  38. if (this.addAllDataUnderTheRoot != null)
  39. {
  40. List<UIWFPositionStore.SerializData> list = new List<UIWFPositionStore.SerializData>(this.positionData);
  41. foreach (Transform transform in this.addAllDataUnderTheRoot.GetComponentsInChildren<Transform>(true))
  42. {
  43. if (!(transform == this.addAllDataUnderTheRoot))
  44. {
  45. list.Add(new UIWFPositionStore.SerializData
  46. {
  47. objectPath = Utility.GetHierarchyPath(this.parent, transform),
  48. localPosition = transform.localPosition,
  49. active = transform.gameObject.active
  50. });
  51. }
  52. }
  53. this.addAllDataUnderTheRoot = null;
  54. this.positionData = list.ToArray();
  55. return;
  56. }
  57. if (this.positionData == null)
  58. {
  59. return;
  60. }
  61. for (int j = 0; j < this.positionData.Length; j++)
  62. {
  63. if (!(this.positionData[j].storeTarget == null))
  64. {
  65. UIWFPositionStore.SerializData serializData = default(UIWFPositionStore.SerializData);
  66. serializData.objectPath = Utility.GetHierarchyPath(this.parent, this.positionData[j].storeTarget);
  67. serializData.localPosition = this.positionData[j].storeTarget.localPosition;
  68. serializData.active = this.positionData[j].storeTarget.gameObject.activeSelf;
  69. this.positionData[j] = serializData;
  70. }
  71. }
  72. }
  73. public bool applyActive = true;
  74. public bool applyPosition = true;
  75. [SerializeField]
  76. private Transform parent;
  77. [SerializeField]
  78. private UIWFPositionStore.SerializData[] positionData;
  79. [Header("指定オブジェクト配下のデータをすべて追加")]
  80. public Transform addAllDataUnderTheRoot;
  81. [Serializable]
  82. private struct SerializData
  83. {
  84. public string objectPath;
  85. public Vector3 localPosition;
  86. public bool active;
  87. [Header("objectPath自動代入用")]
  88. public Transform storeTarget;
  89. }
  90. }