2023-10-29 15:27:13 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEditor.UIElements;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
namespace BITKit.Entities.InputSystem
|
|
|
|
{
|
2023-10-30 01:25:53 +08:00
|
|
|
public class EntityInputSystem : EntityBehavior
|
2023-10-29 15:27:13 +08:00
|
|
|
{
|
|
|
|
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);
|
2023-10-30 01:25:53 +08:00
|
|
|
UnityEntity.AddService(inputActionGroup);
|
2023-10-29 15:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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<EntityInputSystem>
|
|
|
|
{
|
|
|
|
public override VisualElement CreateInspectorGUI()
|
|
|
|
{
|
|
|
|
FillDefaultInspector();
|
|
|
|
var checkBox = root.Create<Toggle>();
|
|
|
|
checkBox.label = "Allow Input";
|
|
|
|
checkBox.SetEnabled(false);
|
|
|
|
|
|
|
|
checkBox.BindProperty(serializedObject.FindProperty(nameof(EntityInputSystem.Allow)));
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|