using System; using System.Collections.Generic; using UnityEngine; using wf; public class UIWFPositionStore : MonoBehaviour { public void Apply() { if (this.positionData == null || this.parent == null) { return; } foreach (UIWFPositionStore.SerializData serializData in this.positionData) { if (!string.IsNullOrEmpty(serializData.objectPath)) { GameObject childObject = UTY.GetChildObject(this.parent.gameObject, serializData.objectPath, true); if (!(childObject == null)) { if (this.applyPosition) { childObject.transform.localPosition = serializData.localPosition; } if (this.applyActive) { childObject.gameObject.SetActive(serializData.active); } } } } } private void OnValidate() { if (this.parent == null) { return; } if (this.addAllDataUnderTheRoot != null) { List list = new List(this.positionData); foreach (Transform transform in this.addAllDataUnderTheRoot.GetComponentsInChildren(true)) { if (!(transform == this.addAllDataUnderTheRoot)) { list.Add(new UIWFPositionStore.SerializData { objectPath = Utility.GetHierarchyPath(this.parent, transform), localPosition = transform.localPosition, active = transform.gameObject.active }); } } this.addAllDataUnderTheRoot = null; this.positionData = list.ToArray(); return; } if (this.positionData == null) { return; } for (int j = 0; j < this.positionData.Length; j++) { if (!(this.positionData[j].storeTarget == null)) { UIWFPositionStore.SerializData serializData = default(UIWFPositionStore.SerializData); serializData.objectPath = Utility.GetHierarchyPath(this.parent, this.positionData[j].storeTarget); serializData.localPosition = this.positionData[j].storeTarget.localPosition; serializData.active = this.positionData[j].storeTarget.gameObject.activeSelf; this.positionData[j] = serializData; } } } public bool applyActive = true; public bool applyPosition = true; [SerializeField] private Transform parent; [SerializeField] private UIWFPositionStore.SerializData[] positionData; [Header("指定オブジェクト配下のデータをすべて追加")] public Transform addAllDataUnderTheRoot; [Serializable] private struct SerializData { public string objectPath; public Vector3 localPosition; public bool active; [Header("objectPath自動代入用")] public Transform storeTarget; } }