1
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using BITKit.Animations;
|
||||
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
|
||||
public sealed class EntityAnimator : EntityComponent
|
||||
{
|
||||
[SerializeField] private Animator[] animators;
|
||||
[SerializeField] private UnityAnimator[] animators;
|
||||
[SerializeReference, SubclassSelector] private References[] animationKeyWords;
|
||||
[SerializeReference, SubclassSelector] private References _rootVelocity;
|
||||
[SerializeReference, SubclassSelector] private References[] boolParameters;
|
||||
@@ -23,13 +25,13 @@ namespace BITKit.Entities
|
||||
|
||||
private void Play(string animationName)
|
||||
{
|
||||
if (enabled is false) return;
|
||||
if (animationKeyWords.Length is 0 || keyWords.Contains(animationName))
|
||||
{
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (!x.isActiveAndEnabled) return;
|
||||
animationName = animationName.Replace(".", "_");
|
||||
x.SetTrigger(animationName);
|
||||
x.Play(animationName);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -40,7 +42,7 @@ namespace BITKit.Entities
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
x.SetBool(boolPar, entity.Get<bool>(boolPar));
|
||||
x.animator.SetBool(boolPar, entity.Get<bool>(boolPar));
|
||||
});
|
||||
}
|
||||
foreach (var floatPar in floatParameters)
|
||||
@@ -48,14 +50,18 @@ namespace BITKit.Entities
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
x.SetFloat(floatPar, entity.Get<float>(floatPar));
|
||||
x.animator.SetFloat(floatPar, entity.Get<float>(floatPar));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimatorMove()
|
||||
{
|
||||
entity.Set(_rootVelocity, animators[0].velocity);
|
||||
if (enabled is false) return;
|
||||
if (_rootVelocity is not null && entity is not null)
|
||||
entity.Set(_rootVelocity, animators[0].animator.velocity);
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
private void AnimationEvent(string eventName)
|
||||
{
|
||||
|
@@ -14,17 +14,14 @@ namespace BITKit
|
||||
private readonly ValidHandle allowHeal = new();
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
public override void Initialize(IEntity _entity)
|
||||
{
|
||||
base.Initialize(_entity);
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
_entity.RegisterCallback<IDamageCallback>(this);
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_health = entity.Get<IHealth>();
|
||||
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
|
||||
entity.RegisterCallback<IDamageCallback>(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
@@ -37,6 +37,7 @@ namespace BITKit
|
||||
destroyCancellationToken.ThrowIfCancellationRequested();
|
||||
Execute();
|
||||
}
|
||||
catch(MissingReferenceException){}
|
||||
catch (OperationCanceledException){}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "BITKit.Entities.InputSystem",
|
||||
"references":[ "GUID:14fe60d984bf9f84eac55c6ea033a8f4", "GUID:f6155d9ae143f3949ac54e8355593d6c", "GUID:7efac18f239530141802fb139776f333", "GUID:709caf8d7fb6ef24bbba0ab9962a3ad0" ]
|
||||
}
|
@@ -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 : 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<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
|
||||
}
|
||||
|
@@ -17,8 +17,6 @@ namespace BITKit.Entities.Player
|
||||
private IntervalUpdate cd = new(0.08f);
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
[Inject]
|
||||
private InputActionGroup _inputActionReference;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "BITKit.Entities.VFX",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:ea5474181b324dd49a5976cd68f44f18",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Entities.VFX
|
||||
{
|
||||
public class EntityVFXPlayer : EntityComponent
|
||||
{
|
||||
[SerializeReference,SubclassSelector] private IReference[] vfxReferences;
|
||||
[SerializeField] private VFXPlayer vfxPlayer;
|
||||
private readonly List<string> keyWords=new();
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
keyWords.AddRange(vfxReferences.Select(x=>x.Value));
|
||||
entity.AddListener<string>(Constant.Animation.Play, Play);
|
||||
}
|
||||
|
||||
private void Play(string animationName)
|
||||
{
|
||||
if (isActiveAndEnabled is false) return;
|
||||
if (keyWords.Contains(animationName) is false) return;
|
||||
vfxPlayer.Execute();
|
||||
}
|
||||
}
|
||||
}
|
@@ -62,11 +62,28 @@ namespace BITKit.Entities
|
||||
else if(attribute?.CanBeNull is false)
|
||||
{
|
||||
BIT4Log.Warning<Entity>($"{name}未找到{obj.GetType().Name}需要的{type.FullName}");
|
||||
BIT4Log.Warning<Entity>(genericEvent.GetDiagnostics());
|
||||
//BIT4Log.Warning<Entity>(genericEvent.GetDiagnostics());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddService<T>(T service)
|
||||
{
|
||||
AddService(typeof(T),service);
|
||||
}
|
||||
|
||||
public void AddService(object service)
|
||||
{
|
||||
AddService(service.GetType(),service);
|
||||
}
|
||||
|
||||
public void AddService(Type type, object service)
|
||||
{
|
||||
genericEvent.Set(type,service);
|
||||
genericEvent.Set(type.FullName, service);
|
||||
genericEvent.SetDirect(type.FullName,service);
|
||||
}
|
||||
|
||||
private CancellationToken _cancellationToken;
|
||||
private bool isInitialized;
|
||||
private Core.Entites.IEntityComponent[] _components => entityComponents.Cast<Core.Entites.IEntityComponent>().ToArray();
|
||||
@@ -85,6 +102,7 @@ namespace BITKit.Entities
|
||||
try
|
||||
{
|
||||
var monoBehaviours = GetComponentsInChildren<MonoBehaviour>(true);
|
||||
entityComponents.ForEach(x => x.Initialize(this));
|
||||
foreach (var x in monoBehaviours)
|
||||
{
|
||||
foreach (var att in x
|
||||
@@ -95,9 +113,7 @@ namespace BITKit.Entities
|
||||
.OfType<CustomTypeAttribute>()
|
||||
)
|
||||
{
|
||||
genericEvent.Set(att.Type,x);
|
||||
genericEvent.Set(att.Type.FullName, x);
|
||||
genericEvent.SetDirect(att.Type.FullName,x);
|
||||
AddService(att.Type, x);
|
||||
}
|
||||
genericEvent.Set(x.GetType(),x);
|
||||
}
|
||||
@@ -105,7 +121,7 @@ namespace BITKit.Entities
|
||||
{
|
||||
Inject(x);
|
||||
}
|
||||
entityComponents.ForEach(x => x.Initialize(this));
|
||||
|
||||
|
||||
entityComponents.ForEach(x => x.OnAwake());
|
||||
entityComponents.ForEach(x => x.OnStart());
|
||||
|
@@ -11,6 +11,9 @@ namespace BITKit.Entities
|
||||
public interface IEntity :BITKit.Core.Entites.IEntity,IGenericEvent<string>, IDatabase, IProcessor, ICallback
|
||||
{
|
||||
IEntityComponent[] entityComponents { get; set; }
|
||||
void AddService<T>(T service);
|
||||
void AddService(object service);
|
||||
void AddService(Type type, object service);
|
||||
}
|
||||
public class IEntityReader : NetMessageReader<IEntity>
|
||||
{
|
||||
|
Reference in New Issue
Block a user