123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<UIWFPositionStore.SerializData> list = new List<UIWFPositionStore.SerializData>(this.positionData);
- foreach (Transform transform in this.addAllDataUnderTheRoot.GetComponentsInChildren<Transform>(true))
- {
- if (!(transform == this.addAllDataUnderTheRoot))
- {
- list.Add(new UIWFPositionStore.SerializData
- {
- objectPath = Utility.GetHierarchyPath(this.parent, transform),
- localPosition = transform.localPosition,
- active = transform.gameObject.activeSelf
- });
- }
- }
- 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("指定オブジェクト配下のデータをすべて追加")]
- private Transform addAllDataUnderTheRoot;
- [Serializable]
- private struct SerializData
- {
- public string objectPath;
- public Vector3 localPosition;
- public bool active;
- [Header("objectPath自動代入用")]
- public Transform storeTarget;
- }
- }
|