using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace BITKit.Entities.InputSystem { public class EntityInputSystem : EntityComponent { protected readonly InputActionGroup inputActionGroup = new() { allowGlobalActivation = true }; [Inject(true)] private IHealth _health; [Inject(true)] private IEntityOverride _override; #if UNITY_EDITOR [SerializeField,HideInInspector] internal bool Allow; #endif public override void Initialize(IEntity _entity) { base.Initialize(_entity); _entity.AddService(inputActionGroup); } public override void OnAwake() { base.OnAwake(); inputActionGroup.allowInput.AddListener(x=>Allow=x); if (_health is not null) { _health.OnSetAlive += x => { inputActionGroup.allowInput.SetElements(_health,x); }; } if (_override is not null) { _override.OnOverride += x => { inputActionGroup.allowInput.SetDisableElements(_override,x); }; } } } #if UNITY_EDITOR [CustomEditor(typeof(EntityInputSystem))] public sealed class EntityInputSystemInspector : BITInspector { public override VisualElement CreateInspectorGUI() { FillDefaultInspector(); var checkBox = root.Create(); checkBox.label = "Allow Input"; checkBox.SetEnabled(false); checkBox.BindProperty(serializedObject.FindProperty(nameof(EntityInputSystem.Allow))); return root; } } #endif }