1
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:96f476e982d6fb945bfc9140ba094b7f",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4"
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80d35d9e6778dc84b88662124834dd35
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Player.Character",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:7efac18f239530141802fb139776f333",
|
||||
"GUID:9354affc93e0f3e4a904785e7d4c0f59"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05850b7e403af6d48bc240ab3c2bc8f4
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,105 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit.PlayerCamera;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
namespace BITKit.Entities.Player.Character
|
||||
{
|
||||
public class EntityCharacter : EntityPlayerBehavior
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
[SerializeField] private Renderer[] fpvRenderer = Array.Empty<Renderer>();
|
||||
[SerializeField] private Renderer[] tpvRenderer = Array.Empty<Renderer>();
|
||||
[SerializeField] private Renderer[] fpvOverrideRenderers = Array.Empty<Renderer>();
|
||||
[SerializeField] private Transform[] tpvRendererGroup = Array.Empty<Transform>();
|
||||
[Header(Constant.Header.Reference)]
|
||||
[SerializeReference, SubclassSelector] public IReference getDamage;
|
||||
|
||||
[Inject(true)] private IHealth _health;
|
||||
|
||||
[Inject(true)] private IPlayerCameraService _cameraService;
|
||||
|
||||
[Inject(true)] private IEntityOverride _entityOverride;
|
||||
|
||||
private Renderer[] _tpvRendererGroup;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
if (_health is not null)
|
||||
{
|
||||
_health.OnSetAlive += _ => UpdateMeshState();
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
}
|
||||
|
||||
if (_cameraService is not null)
|
||||
_cameraService.OnCameraActivated += _ => UpdateMeshState();
|
||||
|
||||
if(_entityOverride is not null)
|
||||
_entityOverride.OnOverride += _ => UpdateMeshState();
|
||||
|
||||
_tpvRendererGroup = tpvRendererGroup.SelectMany(x => x.GetComponentsInChildren<Renderer>(true)).ToArray();
|
||||
}
|
||||
public override void OnPlayerInitialized()
|
||||
{
|
||||
UpdateMeshState();
|
||||
}
|
||||
public override void OnPlayerDispose()
|
||||
{
|
||||
SetFPV(false);
|
||||
}
|
||||
private void OnSetHP(int hp)
|
||||
{
|
||||
UnityEntity.Invoke<string>(Constant.Animation.Play, getDamage.Value);
|
||||
}
|
||||
|
||||
private void UpdateMeshState()
|
||||
{
|
||||
switch (_health, _cameraService)
|
||||
{
|
||||
case (null, null):
|
||||
SetFPV(true);
|
||||
break;
|
||||
case (null, not null):
|
||||
SetFPV(_cameraService.IsCameraActivated);
|
||||
break;
|
||||
case (not null, null):
|
||||
SetFPV(_health.IsAlive);
|
||||
break;
|
||||
case (not null, not null):
|
||||
SetFPV(_health.IsAlive && _cameraService.IsCameraActivated);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFPV(bool isFpv)
|
||||
{
|
||||
var shadowMode = isFpv ?
|
||||
ShadowCastingMode.ShadowsOnly :
|
||||
ShadowCastingMode.On;
|
||||
foreach (var x in fpvRenderer)
|
||||
{
|
||||
x.enabled = isFpv;
|
||||
}
|
||||
foreach (var x in tpvRenderer)
|
||||
{
|
||||
x.shadowCastingMode = shadowMode;
|
||||
}
|
||||
foreach (var x in _tpvRendererGroup)
|
||||
{
|
||||
x.shadowCastingMode =
|
||||
_entityOverride is not null
|
||||
? _entityOverride.IsOvering ? ShadowCastingMode.On : shadowMode
|
||||
: shadowMode;
|
||||
}
|
||||
|
||||
if (_entityOverride is not null)
|
||||
{
|
||||
foreach (var x in fpvOverrideRenderers)
|
||||
{
|
||||
x.enabled = isFpv && _entityOverride.IsOvering;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8cf20e38c0584247ab1573e085274d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -62,6 +62,7 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
public interface IEntityMovement:IStateMachine<IEntityMovementState>
|
||||
{
|
||||
float ReferenceSpeed => 2.5f;
|
||||
Vector3 Position { get; set; }
|
||||
Quaternion Rotation { get; set; }
|
||||
Vector3 Forward { get; }
|
||||
@@ -113,12 +114,12 @@ namespace BITKit.Entities
|
||||
/// 基于相对坐标的移动
|
||||
/// </summary>
|
||||
/// <param name="relativeVector"></param>
|
||||
void Movement(Vector3 relativeVector);
|
||||
void OnMovement(Vector3 relativeVector);
|
||||
/// <summary>
|
||||
/// 基于InputAction的移动
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
void Movement(InputAction.CallbackContext context);
|
||||
void OnMovement(InputAction.CallbackContext context);
|
||||
/// <summary>
|
||||
/// 执行命令
|
||||
/// </summary>
|
||||
|
@@ -12,8 +12,8 @@ namespace BITKit.Entities.Movement
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private bool allowRootMotion;
|
||||
|
||||
|
||||
|
||||
|
||||
public Vector3 Position { get; set; }
|
||||
public Quaternion Rotation { get; set; }
|
||||
public Vector3 Forward { get; }
|
||||
@@ -35,11 +35,11 @@ namespace BITKit.Entities.Movement
|
||||
{
|
||||
}
|
||||
|
||||
public void Movement(Vector3 relativeVector)
|
||||
public void OnMovement(Vector3 relativeVector)
|
||||
{
|
||||
}
|
||||
|
||||
public void Movement(InputAction.CallbackContext context)
|
||||
public void OnMovement(InputAction.CallbackContext context)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.SubSystems;
|
||||
@@ -9,14 +10,16 @@ namespace BITKit.Entities
|
||||
{
|
||||
|
||||
public interface IDamageType { }
|
||||
|
||||
public interface IDamageService
|
||||
{
|
||||
public event Action<DamageMessage> OnEntityDamaged;
|
||||
public event Action<DamageMessage> OnEntityKilled;
|
||||
void Execute(DamageMessage damageMessage);
|
||||
}
|
||||
public struct MeleeDamageMessage:IDamageType{}
|
||||
public struct MeleeDamageMessage : IDamageType
|
||||
{
|
||||
public bool Bleeding;
|
||||
}
|
||||
public struct BulletDamageMessage:IDamageType{}
|
||||
[Serializable]
|
||||
public class DamageServiceSingleton:IDamageService
|
||||
@@ -71,6 +74,34 @@ namespace BITKit.Entities
|
||||
public Vector3 Position;
|
||||
public Quaternion Rotation;
|
||||
public IDamageType DamageType;
|
||||
public RaycastHit? RaycastHit;
|
||||
}
|
||||
|
||||
public sealed class DamageMessageNetMessageWriter : NetMessageReader<DamageMessage>
|
||||
{
|
||||
public override DamageMessage ReadBinary(BinaryReader reader)
|
||||
{
|
||||
UnityEntitiesService.TryGetEntity(reader.ReadUInt64(),out var initiator);
|
||||
UnityEntitiesService.TryGetEntity(reader.ReadUInt64(),out var target);
|
||||
return new DamageMessage()
|
||||
{
|
||||
Initiator = initiator as Entity,
|
||||
Target = target as Entity,
|
||||
RawDamage = reader.ReadBoolean(),
|
||||
Damage = reader.ReadInt32(),
|
||||
Position = reader.ReadFloat3(),
|
||||
Rotation = reader.ReadQuaternion(),
|
||||
};
|
||||
}
|
||||
public override void WriteBinary(BinaryWriter writer, DamageMessage value)
|
||||
{
|
||||
writer.Write(value.Initiator?.Id ?? 0);
|
||||
writer.Write(value.Target?.Id ?? 0);
|
||||
writer.Write(value.RawDamage);
|
||||
writer.Write(value.Damage);
|
||||
writer.WriteFloat3(value.Position);
|
||||
writer.WriteQuaternion(value.Rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IDamageCallback
|
||||
@@ -79,35 +110,65 @@ namespace BITKit.Entities
|
||||
}
|
||||
public interface IDamagable
|
||||
{
|
||||
IHealth Health { get; }
|
||||
IUnityEntity UnityEntity { get; }
|
||||
Rigidbody Rigidbody { get; }
|
||||
void GiveDamage(DamageMessage message);
|
||||
}
|
||||
public class DamageService:MonoBehaviour,IDamageService
|
||||
{
|
||||
internal static IDamageService Singleton { get; set; }
|
||||
public static IDamageService Singleton { get;private set; }
|
||||
private readonly Queue<DamageMessage> Messages = new();
|
||||
|
||||
[SerializeReference,SubclassSelector] private INetClient netClient;
|
||||
[SerializeReference,SubclassSelector] private INetServer netServer;
|
||||
|
||||
private INetProvider netClientProvider => netClient.Source as INetProvider;
|
||||
private INetProvider netServerProvider => netServer.Source as INetProvider;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
netClientProvider.AddCommandListener<DamageMessage>(ExecuteInternal);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!netServer.IsRunningServer && netClient.IsConnected) return;
|
||||
while (Messages.TryDequeue(out var damageMessage))
|
||||
{
|
||||
var unityEntity = (Entity)damageMessage.Target;
|
||||
if (!unityEntity || !unityEntity.TryGetComponent<IHealth>(out var heal) || !heal.IsAlive) continue;
|
||||
|
||||
damageMessage.Initiator?.Invoke(damageMessage);
|
||||
damageMessage.Target?.Invoke(damageMessage);
|
||||
|
||||
ExecuteInternal(damageMessage);
|
||||
|
||||
netServerProvider?.AllClientCommand(damageMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteInternal(DamageMessage damageMessage)
|
||||
{
|
||||
IHealth heal = null;
|
||||
if (damageMessage.Target?.TryGetComponent<IHealth>(out heal) is false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
damageMessage.Initiator?.Invoke(damageMessage);
|
||||
damageMessage.Target?.Invoke(damageMessage);
|
||||
|
||||
if (heal!.IsAlive)
|
||||
{
|
||||
OnEntityDamaged?.Invoke(damageMessage);
|
||||
if (heal.IsAlive is false)
|
||||
{
|
||||
OnEntityKilled?.Invoke(damageMessage);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
OnEntityKilled?.Invoke(damageMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using UnityEngine;
|
||||
@@ -20,21 +21,34 @@ namespace BITKit.Entities
|
||||
/// <summary>
|
||||
/// 当受到伤害时的回调
|
||||
/// </summary>
|
||||
public event Func<DamageMessage,int,int> OnDamageFactory;
|
||||
public event Func<DamageMessage,int,int> OnDamageFactory;
|
||||
/// <summary>
|
||||
/// 收到伤害时的回调
|
||||
/// </summary>
|
||||
public event Action<DamageMessage> OnDamageRelease;
|
||||
/// <summary>
|
||||
/// 当伤害被阻止时的回调
|
||||
/// </summary>
|
||||
public event Action<DamageMessage> OnDamageVoid;
|
||||
|
||||
int HealthPoint { get; set; }
|
||||
int MaxHealthPoint { get; set; }
|
||||
bool IsAlive { get; }
|
||||
}
|
||||
[CustomType(typeof(IHealth))]
|
||||
public class EntityHealth : EntityBehavior, IHealth
|
||||
public class EntityHealth : EntityBehavior, IHealth,IEntityBinaryComponent
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private int healthPoint = 100;
|
||||
[SerializeField] private int maxHealthPoint = 100;
|
||||
|
||||
public int Id { get; } = 84946486;
|
||||
|
||||
public event Action<int> OnSetHealthPoint;
|
||||
public event Action<bool> OnSetAlive;
|
||||
public event Func<DamageMessage,int, int> OnDamageFactory;
|
||||
public event Action<DamageMessage> OnDamageRelease;
|
||||
public event Action<DamageMessage> OnDamageVoid;
|
||||
|
||||
public int HealthPoint
|
||||
{
|
||||
@@ -61,7 +75,7 @@ namespace BITKit.Entities
|
||||
|
||||
private void OnHealthPointChangedInternal(int old, int newHP)
|
||||
{
|
||||
healthPoint = newHP;
|
||||
healthPoint =Mathf.Clamp(newHP,-1,maxHealthPoint) ;
|
||||
var _isAlive = newHP >= 0;
|
||||
if (_isAlive != IsAlive)
|
||||
{
|
||||
@@ -84,15 +98,28 @@ namespace BITKit.Entities
|
||||
private void OnGetDamage(DamageMessage damageMessage)
|
||||
{
|
||||
if (damageMessage.Target != UnityEntity) return;
|
||||
if (IsAlive is false) return;
|
||||
var damage = damageMessage.Damage;
|
||||
foreach (var x in OnDamageFactory.CastAsFunc().Reverse())
|
||||
if (IsAlive is false)
|
||||
{
|
||||
damage = x.Invoke(damageMessage, damage);
|
||||
if (damage <= 0) break;
|
||||
OnDamageVoid?.Invoke(damageMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
var damage = damageMessage.Damage;
|
||||
foreach (var x in OnDamageFactory.CastAsFunc())
|
||||
{
|
||||
damage = x.Invoke(damageMessage, damage);
|
||||
if (damage <= 0)
|
||||
{
|
||||
OnDamageVoid?.Invoke(damageMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Data.Get<bool>("god") is false)
|
||||
AddHP(-damage);
|
||||
|
||||
damageMessage.Damage = damage;
|
||||
OnDamageRelease?.Invoke(damageMessage);
|
||||
}
|
||||
if (Data.Get<bool>("god") is false)
|
||||
AddHP(-damage);
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[BIT]
|
||||
@@ -109,6 +136,17 @@ namespace BITKit.Entities
|
||||
OnHealthPointChangedInternal(100, -1);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(HealthPoint);
|
||||
}
|
||||
|
||||
public void Deserialize(BinaryReader reader)
|
||||
{
|
||||
var newHealthPoint = reader.ReadInt32();
|
||||
if (HealthPoint != newHealthPoint)
|
||||
HealthPoint = newHealthPoint;
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,15 +4,52 @@ using UnityEngine;
|
||||
using BITKit;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public class EntityHitbox : EntityBehavior,IDamagable
|
||||
public class EntityHitbox : MonoBehaviour,IDamagable
|
||||
{
|
||||
IUnityEntity IDamagable.UnityEntity => UnityEntity;
|
||||
public Rigidbody Rigidbody => m_rigidbody;
|
||||
public IHealth Health
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureConfigure();
|
||||
return _health;
|
||||
}
|
||||
}
|
||||
|
||||
public IUnityEntity UnityEntity
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureConfigure();
|
||||
return _unityEntity;
|
||||
}
|
||||
}
|
||||
public Rigidbody Rigidbody
|
||||
{
|
||||
get=>m_rigidbody;
|
||||
set=>m_rigidbody=value;
|
||||
}
|
||||
|
||||
public void GiveDamage(DamageMessage message)
|
||||
{
|
||||
UnityEntity.Invoke(message);
|
||||
if (_unityEntity is not null)
|
||||
UnityEntity.Invoke(message);
|
||||
}
|
||||
|
||||
[SerializeField]private Rigidbody m_rigidbody;
|
||||
|
||||
|
||||
[Inject(true)]
|
||||
private IHealth _health;
|
||||
|
||||
private IUnityEntity _unityEntity;
|
||||
|
||||
private bool _initialized;
|
||||
|
||||
private void EnsureConfigure()
|
||||
{
|
||||
if (_initialized) return;
|
||||
_unityEntity = GetComponentInParent<IUnityEntity>(true);
|
||||
_unityEntity?.Inject(this);
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Rig;
|
||||
using BITKit.Entities;
|
||||
using Cysharp.Threading.Tasks.Triggers;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class EntityHitboxBuilder : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Collider[] colliders;
|
||||
[SerializeField] private EntityHitbox[] hitboxes;
|
||||
|
||||
[SerializeReference,SubclassSelector] private IReference[] tagReferences;
|
||||
[BIT]
|
||||
private void Build()
|
||||
{
|
||||
foreach (var x in hitboxes)
|
||||
{
|
||||
DestroyImmediate(x.gameObject);
|
||||
}
|
||||
hitboxes = new EntityHitbox[colliders.Length];
|
||||
for (var i = 0; i < colliders.Length; i++)
|
||||
{
|
||||
var collider = colliders[i];
|
||||
var newGameObject = new GameObject($"Hitbox_{collider.gameObject.name}");
|
||||
|
||||
newGameObject.layer = gameObject.layer;
|
||||
|
||||
newGameObject.transform.SetParent(transform);
|
||||
var transform1 = collider.transform;
|
||||
newGameObject.transform.position = transform1.position;
|
||||
newGameObject.transform.rotation = transform1.rotation;
|
||||
var hitbox =hitboxes[i] = newGameObject.AddComponent<EntityHitbox>();
|
||||
var tag = newGameObject.AddComponent<Tag>();
|
||||
|
||||
var tickOverride = newGameObject.AddComponent<TickOverrideTransform>();
|
||||
|
||||
tickOverride.Source = newGameObject.transform;
|
||||
tickOverride.Target = collider.transform;
|
||||
|
||||
if (collider.TryGetComponent<Rigidbody>(out var newRigidbody))
|
||||
{
|
||||
hitbox.Rigidbody = newRigidbody;
|
||||
}
|
||||
|
||||
switch (collider)
|
||||
{
|
||||
case BoxCollider boxCollider:
|
||||
var box = newGameObject.AddComponent<BoxCollider>();
|
||||
box.size = boxCollider.size;
|
||||
box.center = boxCollider.center;
|
||||
break;
|
||||
case SphereCollider sphereCollider:
|
||||
var sphere = newGameObject.AddComponent<SphereCollider>();
|
||||
sphere.radius = sphereCollider.radius;
|
||||
sphere.center = sphereCollider.center;
|
||||
break;
|
||||
case CapsuleCollider capsuleCollider:
|
||||
var capsule = newGameObject.AddComponent<CapsuleCollider>();
|
||||
capsule.radius = capsuleCollider.radius;
|
||||
capsule.height = capsuleCollider.height;
|
||||
capsule.direction = capsuleCollider.direction;
|
||||
capsule.center = capsuleCollider.center;
|
||||
break;
|
||||
}
|
||||
|
||||
tag.SetTags(tagReferences);
|
||||
EditorUtility.SetDirty(hitbox);
|
||||
EditorUtility.SetDirty(tag);
|
||||
}
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8de7270cf1d43f64fafdc3413158cea3
|
||||
guid: 21e16997211c6f44c837beae9450cb58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -13,7 +13,8 @@ namespace BITKit.Entities.InputSystem
|
||||
{
|
||||
protected readonly InputActionGroup inputActionGroup = new()
|
||||
{
|
||||
allowGlobalActivation = true
|
||||
allowGlobalActivation = true,
|
||||
Source = nameof(EntityInputSystem)
|
||||
};
|
||||
[Inject(true)]
|
||||
private IHealth _health;
|
||||
|
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Player.Interactive",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:508392158bd966c4d9c21e19661a441d",
|
||||
"GUID:7efac18f239530141802fb139776f333",
|
||||
"GUID:9354affc93e0f3e4a904785e7d4c0f59"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e144f3bb79485843b0a2df56bef0900
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,141 +0,0 @@
|
||||
using System;
|
||||
using BITKit.PlayerCamera;
|
||||
using BITKit.Selection;
|
||||
using BITKit.Sensors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
namespace BITKit.Entities.Player
|
||||
{
|
||||
[CustomType(typeof(ISelector))]
|
||||
public class EntityInteractive : EntityPlayerBehavior,ISelector
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeReference, SubclassSelector] private ISensor sensor;
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform sensorTransform;
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private ISelectable selected;
|
||||
private IntervalUpdate cd = new(0.08f);
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
|
||||
[Inject(true)] private IEntityMovement _movement;
|
||||
|
||||
[Inject(true)] IPlayerCameraService _cameraService;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
}
|
||||
|
||||
private void OnSetAlive(bool obj)
|
||||
{
|
||||
TryDeSelected();
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_cameraService is not null && _movement is not null)
|
||||
{
|
||||
if (_cameraService.IsCameraActivated)
|
||||
{
|
||||
sensorTransform.SetPositionAndRotation(_cameraService.CameraPosition, _cameraService.CameraRotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
sensorTransform.position = _movement.Position + _movement.Rotation * _movement.ViewCenter;
|
||||
sensorTransform.rotation = _movement.ViewRotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if (sensor.Get().TryGetAny(x=>x.TryGetComponentAny<ISelectable>(out _),out var detected))
|
||||
try
|
||||
{
|
||||
if (sensor.Get().TryGetAny(x=>x.GetComponentInParent<ISelectable>() is not null,out var detected))
|
||||
{
|
||||
if (detected.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
{
|
||||
if (_detected == selected)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TryDeSelected();
|
||||
|
||||
Detected(_detected);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TryDeSelected();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TryDeSelected();
|
||||
}
|
||||
}
|
||||
catch(MissingReferenceException e)
|
||||
{}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
private void TryDeSelected()
|
||||
{
|
||||
if (selected is null) return;
|
||||
selected.SetSelectionState(SelectionState.None);
|
||||
OnInactive?.Invoke(selected);
|
||||
selected = null;
|
||||
}
|
||||
private void Detected(ISelectable detected)
|
||||
{
|
||||
selected = detected;
|
||||
detected.SetSelectionState(SelectionState.Hover);
|
||||
OnSelected?.Invoke(selected);
|
||||
}
|
||||
|
||||
public void Interactive(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.interaction is not PressInteraction || !context.performed ) return;
|
||||
if (cd.AllowUpdate is false) return;
|
||||
var _selected = selected;
|
||||
if (_selected is not MonoBehaviour monoBehaviour) return;
|
||||
if (monoBehaviour.TryGetComponentAny<IAction>(out var action))
|
||||
{
|
||||
action.Execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
selected.SetSelectionState(SelectionState.Active);
|
||||
OnActive?.Invoke(selected);
|
||||
}
|
||||
|
||||
public bool TryGetCurrentSelectable(out ISelectable selectable)
|
||||
{
|
||||
selectable = selected;
|
||||
return selected?.Transform;
|
||||
}
|
||||
|
||||
public event Action<ISelectable> OnNone;
|
||||
public event Action<ISelectable> OnHover;
|
||||
public event Action<ISelectable> OnActive;
|
||||
public event Action<ISelectable> OnInactive;
|
||||
public event Action<ISelectable> OnFocus;
|
||||
public event Action<ISelectable> OnSelected;
|
||||
public event Action<ISelectable> OnEnabled;
|
||||
public event Action<ISelectable> OnChecked;
|
||||
public event Action<ISelectable> OnRoot;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b8ff0f400ff5fd44b5205e0adaa1969
|
||||
guid: 0dcb052e1b8841743aaa68d522200c5e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Physics.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:a3de65b07192e7d49bad7b4032d681de",
|
||||
"GUID:7efac18f239530141802fb139776f333"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be39401f40b20344a8e59d5ddab532bc
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b5481cf34bf4a145898ac81e58abf8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,118 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit.Entities.Physics;
|
||||
using UnityEngine;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
[CustomType(typeof(IEntityPhysics))]
|
||||
public class EntityPhysics : EntityBehavior,IEntityPhysics
|
||||
{
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private Rigidbody[] rigidbodies;
|
||||
[SerializeField] private Collider[] ragdollColliders;
|
||||
[SerializeField] private Joint[] joints;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointXMotions=new();
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointYMotions=new();
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointZMotions=new();
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointAngularXMotions=new();
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointAngularYMotions=new();
|
||||
private readonly Dictionary<Joint,ConfigurableJointMotion> _jointAngularZMotions=new();
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
foreach (var x in joints)
|
||||
{
|
||||
switch (x)
|
||||
{
|
||||
case ConfigurableJoint configurableJoint:
|
||||
_jointXMotions.Add(configurableJoint,configurableJoint.xMotion);
|
||||
_jointYMotions.Add(configurableJoint,configurableJoint.yMotion);
|
||||
_jointZMotions.Add(configurableJoint,configurableJoint.zMotion);
|
||||
_jointAngularXMotions.Add(configurableJoint,configurableJoint.angularXMotion);
|
||||
_jointAngularYMotions.Add(configurableJoint,configurableJoint.angularYMotion);
|
||||
_jointAngularZMotions.Add(configurableJoint,configurableJoint.angularZMotion);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnSetAlive(bool alive)
|
||||
{
|
||||
IsPhysics = !alive;
|
||||
if (animator)
|
||||
animator.enabled = alive;
|
||||
try
|
||||
{
|
||||
await Task.Delay(10, destroyCancellationToken);
|
||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
||||
rigidbodies.ForEach(x => { x.isKinematic = alive; });
|
||||
ragdollColliders.ForEach(x => { x.enabled = !alive; });
|
||||
OnSetPhysics?.Invoke(!alive);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
foreach (var joint in joints)
|
||||
{
|
||||
switch (joint)
|
||||
{
|
||||
case ConfigurableJoint configurableJoint:
|
||||
configurableJoint.xMotion = alive ? _jointXMotions[joint] : ConfigurableJointMotion.Free;
|
||||
configurableJoint.yMotion = alive ? _jointYMotions[joint] : ConfigurableJointMotion.Free;
|
||||
configurableJoint.zMotion = alive ? _jointZMotions[joint] : ConfigurableJointMotion.Free;
|
||||
configurableJoint.angularXMotion =
|
||||
alive ? _jointAngularXMotions[joint] : ConfigurableJointMotion.Free;
|
||||
configurableJoint.angularYMotion =
|
||||
alive ? _jointAngularYMotions[joint] : ConfigurableJointMotion.Free;
|
||||
configurableJoint.angularZMotion =
|
||||
alive ? _jointAngularZMotions[joint] : ConfigurableJointMotion.Free;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnSetHP(int hp)
|
||||
{
|
||||
}
|
||||
|
||||
public Vector3 Center => rigidbody.worldCenterOfMass;
|
||||
public bool IsPhysics { get; private set; }
|
||||
public Vector3 Velocity
|
||||
{
|
||||
get=>rigidbody.velocity;
|
||||
set
|
||||
{
|
||||
foreach (var x in rigidbodies)
|
||||
{
|
||||
x.velocity = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public Action<bool> OnSetPhysics { get; set; }
|
||||
public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)
|
||||
{
|
||||
foreach (var x in rigidbodies)
|
||||
{
|
||||
x.AddForce(force, mode);
|
||||
}
|
||||
}
|
||||
public void AddTorque(Vector3 torque, ForceMode mode = ForceMode.Force)
|
||||
{
|
||||
foreach (var x in rigidbodies)
|
||||
{
|
||||
x.AddTorque(torque, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c78fe9fd58f5efc4abdeb6d193bf258b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user