diff options
Diffstat (limited to 'Assets/Scripts/ActiveGroup.cs')
| -rw-r--r-- | Assets/Scripts/ActiveGroup.cs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Assets/Scripts/ActiveGroup.cs b/Assets/Scripts/ActiveGroup.cs new file mode 100644 index 0000000..c2e32d0 --- /dev/null +++ b/Assets/Scripts/ActiveGroup.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +[ExecuteAlways] +public class ActiveGroup : MonoBehaviour +{ + public List<GameObject> members = new(); + + private void Awake() + { + foreach (var member in members) + member.SetActive(gameObject.activeSelf); + + MarkDirty(); + } + + private void OnEnable() + { + foreach (var member in members) + member.SetActive(true); + + MarkDirty(); + } + + private void OnDisable() + { + foreach (var member in members) + member.SetActive(false); + + MarkDirty(); + } + +#if UNITY_EDITOR + private void OnValidate() + { + if (!Application.isPlaying) + EditorUtility.SetDirty(this); + } + + private void MarkDirty() + { + if (!Application.isPlaying) + EditorUtility.SetDirty(this); + } +#else + // 非编辑器平台下,MarkDirty为空方法 + private void MarkDirty() { } +#endif +}
\ No newline at end of file |
