using UnityEngine;
using Script.Gameplay.Interface;

namespace Script.Gameplay.Facility
{
    [RequireComponent(typeof(Collider))]
    public class ColliderEditableController : MonoBehaviour, IEditableComponent
    {
        [SerializeField] private bool isActive = true;

        public bool IsActive
        {
            get => isActive;
            set
            {
                isActive = value;
                // 具体被编辑的逻辑：开启或关闭碰撞体
                if (_collider != null)
                    _collider.enabled = isActive;
            }
        }

        public string ComponentName { get; set; } = "Collider";
        public LockLevel LockLevel { get; } = LockLevel.Red;

        private Collider _collider;

        private void Awake()
        {
            _collider = GetComponent<Collider>();
            // 应用序列化的初始状态
            _collider.enabled = isActive;
        }

#if UNITY_EDITOR
        private void OnValidate()
        {
            // 在编辑器中即时生效
            _collider = _collider == null ? GetComponent<Collider>() : _collider;
            if (_collider != null)
                _collider.enabled = isActive;
        }
#endif
    }
}