1
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.Entities.InputSystem
|
||||
{
|
||||
public class EntityInputSystem : EntityBehavior
|
||||
{
|
||||
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);
|
||||
UnityEntity.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<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
|
||||
}
|
||||
|
Reference in New Issue
Block a user