This commit is contained in:
CortexCore
2023-11-06 01:17:23 +08:00
parent bd40165ade
commit 5446067f91
114 changed files with 2023 additions and 414 deletions

View File

@@ -0,0 +1,4 @@
{
"name": "BITKit.Entities.InputSystem",
"references":[ "GUID:14fe60d984bf9f84eac55c6ea033a8f4", "GUID:f6155d9ae143f3949ac54e8355593d6c", "GUID:7efac18f239530141802fb139776f333", "GUID:709caf8d7fb6ef24bbba0ab9962a3ad0" ]
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7fa5fe8aad740144c9ddda741d067c44
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 34b176396debf404d9190a6fbde6ff77
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: