using System.Collections; using System.Collections.Generic; using Spine.Unity; using UnityEngine; public class ParentItem : MonoBehaviour { public List children = new List(); public SkeletonAnimation destory_ani; private void Awake() { // 自动收集子物体上的 ChildItem 脚本 children.AddRange(GetComponentsInChildren()); destory_ani = GetComponentInChildren(); destory_ani.gameObject.SetActive(false); } // 当某个子物体被点击时调用 public void OnChildClicked(ChildItem child) { Debug.Log($"父物体收到点击事件:{child.name}"); // 可以在这里统一管理,比如调用子物体的方法 children.Remove(child); if (children.Count <= 0) { // Destroy(gameObject); GetComponent().enabled = false; GetComponent().enabled = false; GetComponent().simulated = false; destory_ani.gameObject.SetActive(true); destory_ani.state.SetAnimation(0, "animation", false); destory_ani.state.Complete += (trackEntry) => { Destroy(gameObject); }; } } }