Files
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

47 lines
1.0 KiB
C#

using UnityEngine;
namespace CW.Common
{
/// <summary>This is the base class for all components that are created as children of another component, allowing them to be more easily managed.</summary>
public abstract class CwChild : MonoBehaviour
{
public interface IHasChildren
{
bool HasChild(CwChild child);
}
[ContextMenu("Destroy GameObject If Invalid All")]
public void DestroyGameObjectIfInvalidAll()
{
if (transform.parent != null)
{
foreach (var siblings in transform.parent.GetComponentsInChildren<CwChild>())
{
siblings.DestroyGameObjectIfInvalid();
}
}
}
[ContextMenu("Destroy GameObject If Invalid")]
public void DestroyGameObjectIfInvalid()
{
var parent = GetParent();
if (parent == null || parent.HasChild(this) == false)
{
#if UNITY_EDITOR
UnityEditor.Undo.DestroyObjectImmediate(gameObject);
#else
DestroyImmediate(gameObject);
#endif
}
}
protected abstract IHasChildren GetParent();
protected virtual void Start()
{
//DestroyGameObjectIfInvalid();
}
}
}