From 7735b716401f630697d5b02910d50dbf8f3416af Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sat, 30 May 2026 19:35:16 +0800 Subject: 正在编写动态场景加载 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/ActiveGroup.cs | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Assets/Scripts/ActiveGroup.cs (limited to 'Assets/Scripts/ActiveGroup.cs') 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 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 -- cgit