2025-04-02 17:30:33 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
public class ActiveStateSynchronizer : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
#if VR
|
|
|
|
|
|
[Header("ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
|
|
|
|
|
|
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫͬ<D2AA><CDAC><EFBFBD><EFBFBD>Ŀ<EFBFBD>길<EFBFBD><EAB8B8><EFBFBD><EFBFBD>")]
|
|
|
|
|
|
public Transform targetParent;
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (targetParent == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
targetParent = GameObject.Find("SceneManager/niu/PTXZ")?.transform;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (targetParent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SynchronizeActiveStates(transform, targetParent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SynchronizeActiveStates(Transform source, Transform target)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>Խ<EFBFBD><D4BD>
|
|
|
|
|
|
int minChildCount = Mathf.Min(source.childCount, target.childCount);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < minChildCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Transform sourceChild = source.GetChild(i);
|
|
|
|
|
|
Transform targetChild = target.GetChild(i);
|
|
|
|
|
|
|
|
|
|
|
|
// ͬ<><CDAC><EFBFBD><EFBFBD>ǰ<EFBFBD>㼶<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>״̬
|
|
|
|
|
|
if (sourceChild.gameObject.activeSelf != targetChild.gameObject.activeSelf)
|
|
|
|
|
|
{
|
|
|
|
|
|
sourceChild.gameObject.SetActive(targetChild.gameObject.activeSelf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-02 17:40:35 +08:00
|
|
|
|
Toggle toggle;
|
|
|
|
|
|
Button btn;
|
|
|
|
|
|
if (sourceChild.TryGetComponent<Toggle>(out toggle) == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
toggle.onValueChanged = targetChild.GetComponent<Toggle>().onValueChanged;
|
2025-04-02 17:30:33 +08:00
|
|
|
|
}
|
2025-04-02 17:40:35 +08:00
|
|
|
|
else if (sourceChild.TryGetComponent<Button>(out btn) == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
btn.onClick = targetChild.GetComponent<Button>().onClick;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-02 17:30:33 +08:00
|
|
|
|
// <20>ݹ鴦<DDB9><E9B4A6><EFBFBD>Ӳ㼶
|
|
|
|
|
|
SynchronizeActiveStates(sourceChild, targetChild);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (source.childCount != target.childCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>: {source.name}({source.childCount}) Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {target.name}({target.childCount})", this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|