1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.Net.Configuration;
|
||||
using BITKit.Animations;
|
||||
|
||||
namespace BITKit.Entities
|
||||
@@ -14,9 +15,15 @@ namespace BITKit.Entities
|
||||
[SerializeReference, SubclassSelector] private References[] boolParameters;
|
||||
[SerializeReference, SubclassSelector] private References[] floatParameters;
|
||||
private List<string> keyWords;
|
||||
|
||||
private ConstantHash[] _boolParameterHashes;
|
||||
private ConstantHash[] _floatParameterHashes;
|
||||
public override void OnAwake()
|
||||
{
|
||||
keyWords = animationKeyWords.Select(x => x.Get()).ToList();
|
||||
|
||||
_boolParameterHashes = boolParameters.Select(x =>new ConstantHash(x.Get())).ToArray();
|
||||
_floatParameterHashes = floatParameters.Select(x =>new ConstantHash(x.Get())).ToArray();
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
@@ -35,26 +42,30 @@ namespace BITKit.Entities
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnFixedUpdate(float deltaTime)
|
||||
{
|
||||
foreach (var boolPar in boolParameters)
|
||||
bool cacheBool;
|
||||
float cacheFloat;
|
||||
foreach (var boolPar in _boolParameterHashes)
|
||||
{
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
x.animator.SetBool(boolPar, UnityEntity.Get<bool>(boolPar));
|
||||
});
|
||||
foreach (var x in animators)
|
||||
{
|
||||
if (!x.isActiveAndEnabled) return;
|
||||
UnityEntity.GetDirect<bool>(boolPar, out cacheBool);
|
||||
x.animator.SetBool(boolPar.HashCode, cacheBool);
|
||||
}
|
||||
}
|
||||
foreach (var floatPar in floatParameters)
|
||||
foreach (var floatPar in _floatParameterHashes)
|
||||
{
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
x.animator.SetFloat(floatPar, UnityEntity.Get<float>(floatPar));
|
||||
});
|
||||
foreach (var x in animators)
|
||||
{
|
||||
if (!x.isActiveAndEnabled) return;
|
||||
UnityEntity.GetDirect<float>(floatPar, out cacheFloat);
|
||||
x.animator.SetFloat(floatPar.HashCode, cacheFloat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimatorMove()
|
||||
{
|
||||
if (enabled is false) return;
|
||||
|
@@ -10,7 +10,7 @@ namespace BITKit.Entities.Player.Character
|
||||
[SerializeField] private Renderer[] fpvRenderer = Array.Empty<Renderer>();
|
||||
[SerializeField] private Renderer[] tpvRenderer = Array.Empty<Renderer>();
|
||||
[Header(Constant.Header.Reference)]
|
||||
[SerializeReference, SubclassSelector] public References _getDamage;
|
||||
[SerializeReference, SubclassSelector] public IReference getDamage;
|
||||
public override void OnStart()
|
||||
{
|
||||
var heal = UnityEntity.Get<IHealth>();
|
||||
@@ -33,7 +33,7 @@ namespace BITKit.Entities.Player.Character
|
||||
}
|
||||
private void OnSetHP(int hp)
|
||||
{
|
||||
UnityEntity.Invoke<string>(Constant.Animation.Play, _getDamage);
|
||||
UnityEntity.Invoke<string>(Constant.Animation.Play, getDamage.Value);
|
||||
}
|
||||
private void SetFPV(bool isFpv)
|
||||
{
|
||||
|
@@ -1,132 +0,0 @@
|
||||
using System;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class NavAgentMovement: StateBasedBehavior<IEntityMovementState>,IEntityMovement
|
||||
{
|
||||
#region 属性
|
||||
[SerializeField] private NavMeshAgent agent;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
|
||||
[Inject] private IHealth _health;
|
||||
|
||||
[Inject(true)] private IEntityOverride _override;
|
||||
#endregion
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
if (_override is not null)
|
||||
{
|
||||
_override.OnOverride += (x) =>
|
||||
{
|
||||
agent.isStopped = x;
|
||||
};
|
||||
}
|
||||
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
|
||||
}
|
||||
|
||||
#region 接口实现
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
get=>transform.position;
|
||||
set=>transform.position=value;
|
||||
}
|
||||
|
||||
public Quaternion Rotation
|
||||
{
|
||||
get=>transform.rotation;
|
||||
set=>transform.rotation=value;
|
||||
}
|
||||
|
||||
public Vector3 Forward => transform.forward;
|
||||
public Vector3 ViewCenter { get; set; }
|
||||
public Quaternion ViewRotation { get; set; }
|
||||
public Vector3 LocomotionBasedVelocity { get; private set; }
|
||||
public Vector3 Velocity { get; private set; }
|
||||
public Vector3 GroundVelocity { get; private set; }
|
||||
public Vector3 AngularVelocity { get; private set; }
|
||||
public bool IsGrounded { get; private set; }
|
||||
private bool isDead;
|
||||
private Vector3 recordPosition;
|
||||
private Quaternion recordRotation;
|
||||
private IEntityMovement _entityMovementImplementation;
|
||||
#endregion
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
Velocity = agent.velocity;
|
||||
var _groundVelocity = Velocity;
|
||||
_groundVelocity.y = 0;
|
||||
GroundVelocity = _groundVelocity;
|
||||
IsGrounded = agent.isOnOffMeshLink is false;
|
||||
|
||||
UnityEntity.Set<bool>("IsMoving",Velocity.sqrMagnitude>=0.16f);
|
||||
UnityEntity.Set<float>("SqrMagnitude",Velocity.sqrMagnitude);
|
||||
|
||||
if (!isDead) return;
|
||||
|
||||
recordPosition = rigidbody.position;
|
||||
recordRotation = rigidbody.rotation * transform.rotation;
|
||||
}
|
||||
public void SyncMovement(Vector3 velocity, Vector3 position, Quaternion rotation, bool isGrounded)
|
||||
{
|
||||
|
||||
}
|
||||
public void Movement(Vector3 relativeVector)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Movement(InputAction.CallbackContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ExecuteCommand<T>(T command)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public event Action<object> OnCommand;
|
||||
|
||||
public void OnSetAlive(bool alive)
|
||||
{
|
||||
switch (alive)
|
||||
{
|
||||
case false:
|
||||
isDead = true;
|
||||
break;
|
||||
case true when isDead:
|
||||
{
|
||||
var _transform = transform;
|
||||
_transform.position = new Vector3()
|
||||
{
|
||||
x=recordPosition.x,
|
||||
y=0,
|
||||
z=recordPosition.x,
|
||||
};
|
||||
rigidbody.position = recordPosition;
|
||||
|
||||
_transform.rotation *= recordRotation;
|
||||
|
||||
rigidbody.rotation = recordRotation;
|
||||
|
||||
isDead = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSetHP(int hp)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f4b115cecfadd40b191dc35f29ef08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -16,6 +16,8 @@ namespace BITKit.Entities
|
||||
public event Action<DamageMessage> OnEntityKilled;
|
||||
void Execute(DamageMessage damageMessage);
|
||||
}
|
||||
public struct MeleeDamageMessage:IDamageType{}
|
||||
public struct BulletDamageMessage:IDamageType{}
|
||||
[Serializable]
|
||||
public class DamageServiceSingleton:IDamageService
|
||||
{
|
||||
@@ -69,6 +71,7 @@ namespace BITKit.Entities
|
||||
public Location Location;
|
||||
public IDamageType DamageType;
|
||||
}
|
||||
|
||||
public interface IDamageCallback
|
||||
{
|
||||
void OnGetDamage(DamageMessage message);
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
@@ -18,9 +20,7 @@ namespace BITKit.Entities.InputSystem
|
||||
[Inject(true)]
|
||||
private IEntityOverride _override;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[SerializeField,HideInInspector] internal bool Allow;
|
||||
#endif
|
||||
public override void Initialize(IEntity _entity)
|
||||
{
|
||||
base.Initialize(_entity);
|
||||
@@ -46,6 +46,18 @@ namespace BITKit.Entities.InputSystem
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
inputActionGroup.allowInput.Invoke();
|
||||
}
|
||||
|
||||
public override void OnDestroyComponent()
|
||||
{
|
||||
base.OnDestroyComponent();
|
||||
inputActionGroup.Dispose();
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(EntityInputSystem))]
|
||||
|
@@ -31,20 +31,27 @@ namespace BITKit.Entities.Player
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
//if (sensor.Get().TryGetAny(x=>x.TryGetComponentAny<ISelectable>(out _),out var detected))
|
||||
if (sensor.Get().TryGetAny(x=>x.GetComponentInParent<ISelectable>() is not null,out var detected))
|
||||
try
|
||||
{
|
||||
if (detected.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
if (sensor.Get().TryGetAny(x=>x.GetComponentInParent<ISelectable>() is not null,out var detected))
|
||||
{
|
||||
if (_detected == selected)
|
||||
if (detected.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
{
|
||||
if (_detected == selected)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TryDeSelected();
|
||||
|
||||
Detected(_detected);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TryDeSelected();
|
||||
|
||||
Detected(_detected);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -52,10 +59,14 @@ namespace BITKit.Entities.Player
|
||||
TryDeSelected();
|
||||
}
|
||||
}
|
||||
else
|
||||
catch(MissingReferenceException e)
|
||||
{}
|
||||
catch (Exception e)
|
||||
{
|
||||
TryDeSelected();
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
private void TryDeSelected()
|
||||
{
|
||||
|
@@ -15,7 +15,6 @@ namespace BITKit.Entities
|
||||
[SerializeField] private Collider[] ragdollColliders;
|
||||
[SerializeField] private Joint[] joints;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
private CancellationToken _cancellationToken;
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointXMotions=new();
|
||||
@@ -29,7 +28,6 @@ namespace BITKit.Entities
|
||||
{
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
_cancellationToken = UnityEntity.Get<CancellationToken>();
|
||||
foreach (var x in joints)
|
||||
{
|
||||
switch (x)
|
||||
@@ -53,7 +51,7 @@ namespace BITKit.Entities
|
||||
animator.enabled = alive;
|
||||
try
|
||||
{
|
||||
await Task.Delay(10, _cancellationToken);
|
||||
await Task.Delay(10, destroyCancellationToken);
|
||||
rigidbodies.ForEach(x => { x.isKinematic = alive; });
|
||||
ragdollColliders.ForEach(x => { x.enabled = !alive; });
|
||||
OnSetPhysics?.Invoke(!alive);
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -19,9 +20,18 @@ namespace BITKit.Entities.VFX
|
||||
|
||||
private void Play(string animationName)
|
||||
{
|
||||
if (isActiveAndEnabled is false) return;
|
||||
if (keyWords.Contains(animationName) is false) return;
|
||||
vfxPlayer.Execute();
|
||||
try
|
||||
{
|
||||
if (isActiveAndEnabled is false) return;
|
||||
if (keyWords.Contains(animationName) is false) return;
|
||||
vfxPlayer.Execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning(transform.name);
|
||||
Debug.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user