This commit is contained in:
CortexCore
2023-10-30 01:25:53 +08:00
parent add6d0cab3
commit 18f664a545
125 changed files with 3529 additions and 700 deletions

View File

@@ -5,7 +5,6 @@ using System.Text;
using BITFALL.Bullet;
using UnityEngine;
using BITKit;
using BITKit.Core.Entites;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEditor;
@@ -121,15 +120,23 @@ namespace BITFALL
var force = (raycastHit.point - (Vector3)bullet.pos).normalized * (physicsInfo?.AddForceMultiple ?? 64);
if (raycastHit.collider.TryGetComponent<IDamagable>(out var damagable))
{
if (damagable.Entity.Id == bullet.initiator) return false;
if (damagable.UnityEntity?.Id == bullet.initiator) return false;
if (layerMask.Includes(raycastHit.collider.gameObject.layer) is false) return false;
var msg = new DamageMessage()
{
Target = damagable.Entity,
Target = damagable.UnityEntity,
Hit = damagable,
Damage = bullet.initialDamage,
};
damageService.Execute(msg);
if (damagable is IEntityComponent)
{
damageService.Execute(msg);
}
else
{
damagable.GiveDamage(msg);
}
}
var _rigidbody = (raycastHit.rigidbody,damagable?.Rigidbody) switch

View File

@@ -7,7 +7,7 @@ using UnityEngine;
namespace BITKit.Entities.Animation
{
public sealed class EntitiesAnimationController : EntityComponent
public sealed class EntitiesAnimationController : EntityBehavior
{
[SerializeField] private UnityAnimator unityAnimator;
[SerializeField] private SerializedDictionary<string, RuntimeAnimatorController> animatorControllers;
@@ -20,7 +20,7 @@ namespace BITKit.Entities.Animation
public override void OnAwake()
{
base.OnAwake();
_entityEquipment.OnEquip += OnEquip;
_entityEquipment.OnEquipAddressable += OnEquip;
_initialRuntimeAnimatorController = unityAnimator.animator.runtimeAnimatorController;
}
@@ -32,16 +32,11 @@ namespace BITKit.Entities.Animation
}
}
private void OnEquip(IBasicItem obj)
private void OnEquip(string equipName)
{
if(animatorControllers.TryGetValue(obj.AddressablePath, out var controller))
{
_runtimeAnimatorControllerBuffer.Release(controller);
}
else
{
_runtimeAnimatorControllerBuffer.Release(_initialRuntimeAnimatorController);
}
_runtimeAnimatorControllerBuffer.Release(animatorControllers.TryGetValue(equipName, out var controller)
? controller
: _initialRuntimeAnimatorController);
}
}

View File

@@ -11,7 +11,7 @@ using UnityEngine;
namespace BITFALL.Entities.Armor
{
[CustomType(typeof(IArmor))]
public class EntityArmor : EntityComponent,IArmor
public class EntityArmor : EntityBehavior,IArmor
{
private int _armor;
public int Armor

View File

@@ -9,7 +9,7 @@ using BITKit.Physics;
namespace BITFALL.Entites
{
public class EntityProxyCharacter : EntityComponent
public class EntityProxyCharacter : EntityBehavior
{
[SerializeField] private UnityAnimator animator;
[SerializeReference, SubclassSelector] public References _getDamage;

View File

@@ -23,7 +23,7 @@ using Debug = UnityEngine.Debug;
namespace BITFALL.Entities.Equipment
{
[CustomType(typeof(IPlayerEquipSelector))]
public class PlayerEquipSelector : EntityComponent,IPlayerEquipSelector
public class PlayerEquipSelector : EntityBehavior,IPlayerEquipSelector
{
[Header(Constant.Header.InternalVariables)]
private readonly Dictionary<int, IBasicItem> equips=new();

View File

@@ -33,7 +33,7 @@ namespace BITKit.Entities
[Header(Constant.Header.Services)]
[SerializeReference,SubclassSelector] protected IMeleeService meleeService;
public Core.Entites.IEntity Entity { get; set; }
public Entities.IEntity Entity { get; set; }
public Entity UnityEntity=>Entity as Entity;
public IBasicItem Item { get; set; }
@@ -57,8 +57,11 @@ namespace BITKit.Entities
if (vfxPlayer)
vfxPlayer.enabled = true;
var animName = animator.animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
animator.animator.Play(animName, -1, 0);
if (animator)
{
var animName = animator.animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
animator.animator.Play(animName, -1, 0);
}
}
public virtual UniTask EntryAsync()
@@ -126,7 +129,8 @@ namespace BITKit.Entities
Position = Transform.position,
Force = meleeForce * equip.MeleeForce,
Range = equip.MeleeRange,
Damage = equip.MeleeDamage
Damage = equip.MeleeDamage,
Forward = UnityEntity.transform.forward
});
break;
case "HeavyAttack":
@@ -137,6 +141,7 @@ namespace BITKit.Entities
Force = meleeForce * equip.HeavyMeleeForce,
Range = equip.HeavyMeleeRange,
Damage = equip.HeavyMeleeDamage,
Forward = UnityEntity.transform.forward
});
break;
}
@@ -144,7 +149,7 @@ namespace BITKit.Entities
}
[CustomType(typeof(IEquipService))]
[CustomType(typeof(IEntityEquipment))]
public class EntityEquipment : EntityComponent,IEquipService,IEntityEquipment
public class EntityEquipment : EntityBehavior,IEquipService,IEntityEquipment
{
public IOptional<float> Zoom { get; } = new Optional<float>(){Value = 1};
@@ -185,7 +190,7 @@ namespace BITKit.Entities
foreach (var x in equips.list)
{
x.Entity = entity;
x.Entity = UnityEntity;
x.OnAwake();
}

View File

@@ -19,7 +19,7 @@ namespace BITFALL
/// 支持,护甲,头盔和背包等
/// </summary>
[CustomType(typeof(IEntityEquipmentContainer))]
public class EntityEquipmentContainer : EntityComponent, IEntityEquipmentContainer
public class EntityEquipmentContainer : EntityBehavior, IEntityEquipmentContainer
{
public IDictionary<IEquipmentSlot, IBasicItem> Equipment { get; } =
new Dictionary<IEquipmentSlot, IBasicItem>();
@@ -28,7 +28,7 @@ namespace BITFALL
public override void OnAwake()
{
var health = entity.Get<IHealth>();
var health = UnityEntity.Get<IHealth>();
health.OnSetAlive += OnSetAlive;
}

View File

@@ -5,7 +5,7 @@ using BITKit;
using BITKit.Entities;
namespace BITFALL.Entites
{
public class EntityFootstep : EntityComponent
public class EntityFootstep : EntityBehavior
{
void FootStep()
{

View File

@@ -12,7 +12,7 @@ using UnityEngine.InputSystem.Interactions;
namespace BITFALL.Entities.Improvised
{
[CustomType(typeof(ImprovisedServiceInterface))]
public class ImprovisedService : EntityComponent,ImprovisedServiceInterface
public class ImprovisedService : EntityBehavior,ImprovisedServiceInterface
{
[Inject] private IHealth _health;
[Inject(true)] private IKnockdown _knockdown;

View File

@@ -16,7 +16,7 @@ namespace BITFALL
{
[CustomType(typeof(IEntityInventory))]
[CustomType(typeof(IBasicItemContainer))]
public class EntityInventory : EntityComponent, IEntityInventory
public class EntityInventory : EntityBehavior, IEntityInventory
{
/// <summary>
/// 数据字典
@@ -25,7 +25,7 @@ namespace BITFALL
/// <summary>
/// 隐式接口实现
/// </summary>
public int Id => (int)entity.Id;
public int Id => (int)UnityEntity.Id;
public bool DropOrSpawn(IBasicItem item)
{

View File

@@ -12,7 +12,7 @@ namespace BITFALL
event Action<double,double> OnWeighted;
}
[CustomType(typeof(IPlayerInventoryWeightable))]
public class InventoryWeightable : EntityComponent,IPlayerInventoryWeightable
public class InventoryWeightable : EntityBehavior,IPlayerInventoryWeightable
{
[Header(Constant.Header.Data)]
public double currentWeight;

View File

@@ -12,7 +12,7 @@ using UnityEngine;
namespace BITFALL.Player.Inventory
{
[CustomType(typeof(IEntitySwapItem))]
public class PlayerInventorySwap : EntityComponent,IEntitySwapItem
public class PlayerInventorySwap : EntityBehavior,IEntitySwapItem
{
public bool TryGetCurrentContainer(out IBasicItemContainer container)
{

View File

@@ -11,7 +11,7 @@ using UnityEngine;
namespace BITFALL.Entities
{
[CustomType(typeof(IKnockdown))]
public sealed class EntityKnockdown :EntityComponent,IKnockdown
public sealed class EntityKnockdown :EntityBehavior,IKnockdown
{
[SerializeField] private int knockedHealth;
[SerializeField] private int initialKnockedHealth;

View File

@@ -9,7 +9,7 @@ using UnityEngine;
namespace BITKit.Entities
{
[CustomType(typeof(IMeleeCombat))]
public class EntityMelee : EntityComponent,IMeleeCombat
public class EntityMelee : EntityBehavior,IMeleeCombat
{
[SerializeField] private UnityAnimator unityAnimator;
@@ -21,8 +21,8 @@ namespace BITKit.Entities
[Inject(true)] private IEntityOverride entityOverride;
public override void OnStart()
{
entity.AddListener<int>("Melee", Melee);
entity.AddListener<string>(AIAction);
UnityEntity.AddListener<int>("Melee", Melee);
UnityEntity.AddListener<string>(AIAction);
unityAnimator[0].onStateEnter += OnStateEnter;
}

View File

@@ -7,7 +7,7 @@ using BITFALL.Entities.Equipment;
namespace BITFALL
{
public class EntityPropsDisplay : EntityComponent
public class EntityPropsDisplay : EntityBehavior
{
[SerializeField] private SerializedDictionary<string, GameObject> equipped = new();
[SerializeField] private SerializedDictionary<string, GameObject> bodyEquips = new();

View File

@@ -4,7 +4,7 @@ using BITKit;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEngine;
using IEntity = BITKit.Core.Entites.IEntity;
using IEntity = BITKit.Entities.IEntity;
namespace BITFALL.Entities.Equipment
{
@@ -12,18 +12,23 @@ namespace BITFALL.Entities.Equipment
{
[SerializeField] protected AssetableItem assetableItem;
public bool IsEntered { get; set; }
public virtual void Entry()
{
UnityEntity.AddListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
}
protected virtual void OnAnimationEvent(string animationEventName)
{
}
public virtual UniTask EntryAsync()
{
return UniTask.CompletedTask;
}
public virtual void Exit()
public virtual void Exit()
{
UnityEntity.RemoveListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
}
public virtual UniTask ExitAsync()

View File

@@ -7,6 +7,7 @@ using BITFALL.Entities.Equipment;
using BITKit;
using BITKit.Entities;
using BITKit.StateMachine;
using Unity.Mathematics;
using UnityEngine;
namespace BITFALL.Guns
@@ -16,6 +17,8 @@ namespace BITFALL.Guns
[SerializeField] private Transform firePoint;
[SerializeReference,SubclassSelector] private IBulletService bulletService;
[SerializeField] private bool forceFire;
[SerializeField] private Optional<int> customFireRate;
[SerializeField] private Optional<IntervalUpdate> customFireInterval;
private AssetableGun _gun=>assetableItem as AssetableGun;
private readonly IntervalUpdate fireInterval = new();
@@ -24,6 +27,10 @@ namespace BITFALL.Guns
{
base.Entry();
fireInterval.Interval = _gun.FireMode.FireRate is 0 ? 1 : 1f/_gun.FireMode.FireRate;
if (customFireRate.Allow)
{
fireInterval.Interval =customFireRate.Value is 0 ? 1 : 1f / customFireRate.Value;
}
UnityEntity.AddListener<BITConstant.Command.AttackCommand>(OnAttack);
}
public override void Exit()
@@ -36,7 +43,17 @@ namespace BITFALL.Guns
{
if (forceFire && fireInterval.AllowUpdate)
{
OnAttack(new BITConstant.Command.AttackCommand());
if(customFireInterval.Allow)
{
if (customFireInterval.Value.AllowUpdate)
{
OnAttack(new BITConstant.Command.AttackCommand());
}
}
else
{
OnAttack(new BITConstant.Command.AttackCommand());
}
}
}

View File

@@ -1,7 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using System.Data.OleDb;
using BITFALL.Bullet;
using BITFALL.Guns;
using BITFALL.Items.Melee;
using BITKit;
using BITKit.Entities.Melee;
using UnityEngine;
@@ -14,6 +16,7 @@ namespace BITFALL.Entities.Equipment
[SerializeField] private bool forceAttack;
private readonly IntervalUpdate interval = new(1);
private AssetableMelee assetableMelee=>assetableItem as AssetableMelee;
public override void Entry()
{
base.Entry();
@@ -37,6 +40,25 @@ namespace BITFALL.Entities.Equipment
{
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
}
protected override void OnAnimationEvent(string animationEventName)
{
switch (animationEventName)
{
case BITConstant.Player.Attack:
case BITConstant.Player.Melee:
meleeService.Melee(new MeleeCommand()
{
Damage = assetableMelee.MeleeDamage,
Force = assetableMelee.MeleeForce,
PlayerId = Entity.Id,
Position = transform.position,
Range = assetableMelee.MeleeRange,
Forward = UnityEntity.transform.forward,
});
break;
}
}
}
}

View File

@@ -292,7 +292,7 @@ namespace BITFALL.Guns.States
}
public override void OnStateEntry(IState old)
{
root.animator.Play(BITConstant.Player.Melee);
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
_entityMovement.ExecuteCommand(new PlayerDisableRunCommand(this));
}

View File

@@ -7,7 +7,7 @@ using BITKit;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEngine;
using IEntity = BITKit.Core.Entites.IEntity;
using IEntity = BITKit.Entities.IEntity;
namespace BITFALL.Guns
{

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using BITKit.Entities;
using BITKit.StateMachine;
using UnityEngine;
namespace BITFALL.Player.Equip
{
public sealed class EmptyController : BITEquipBase<EmptyState>
{
}
}

View File

@@ -9,7 +9,7 @@ using UnityEngine.InputSystem;
namespace BITFALL.Player.Movement
{
public class EquipSway : EntityComponent
public class EquipSway : EntityBehavior
{
[SerializeField] private float rotDelta;
[SerializeField] private float rotValue;
@@ -22,8 +22,8 @@ namespace BITFALL.Player.Movement
private IEquipService _equipService;
public override void OnAwake()
{
_movement = entity.Get<IEntityMovement>();
_equipService = entity.Get<IEquipService>();
_movement = UnityEntity.Get<IEntityMovement>();
_equipService = UnityEntity.Get<IEquipService>();
}
public override void OnLateUpdate(float deltaTime)

View File

@@ -5,7 +5,6 @@ using BITFALL.Items.Melee;
using BITFALL.Combat;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Core.Entites;
using BITKit.Entities;
using BITKit.Entities.Melee;
using BITKit.StateMachine;

View File

@@ -83,7 +83,7 @@ namespace BITFALL.Entities.Equipment.Melee
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
meleeController.animator.Play(BITConstant.Player.Attack);
meleeController.UnityEntity.Invoke(Constant.Animation.Play,BITConstant.Player.Attack);
}
public override void OnStateUpdate(float deltaTime)
{
@@ -100,7 +100,7 @@ namespace BITFALL.Entities.Equipment.Melee
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
meleeController.animator.Play(BITConstant.Player.Charging);
meleeController.UnityEntity.Invoke(Constant.Animation.Play,BITConstant.Player.Charging);
}
public override void OnStateUpdate(float deltaTime)
@@ -127,7 +127,7 @@ namespace BITFALL.Entities.Equipment.Melee
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
meleeController.animator.Play(BITConstant.Player.HeavyAttack);
meleeController.UnityEntity.Invoke(Constant.Animation.Play,BITConstant.Player.HeavyAttack);
_playerMovement.Stamina -= meleeController.melee.HeavyAttackStaminaCost;
}
}
@@ -143,7 +143,7 @@ namespace BITFALL.Entities.Equipment.Melee
{
base.OnStateEntry(old);
_interval.Reset();
meleeController.animator.Play(BITConstant.Player.Blocking);
meleeController.UnityEntity.Invoke(Constant.Animation.Play,BITConstant.Player.Blocking);
}
public override void OnStateUpdate(float deltaTime)
{

View File

@@ -7,7 +7,7 @@ using BITKit.Entities;
using Cysharp.Threading.Tasks;
using RotaryHeart.Lib.SerializableDictionary;
using UnityEngine;
using IEntity = BITKit.Core.Entites.IEntity;
using IEntity = BITKit.Entities.IEntity;
namespace BITFALL.Player.Equip
{

View File

@@ -9,7 +9,7 @@ using UnityEngine;
namespace BITFALL.Feel
{
public sealed class PlayerHandAnimations : EntityComponent
public sealed class PlayerHandAnimations : EntityBehavior
{
[SerializeField] private UnityAnimator animator;

View File

@@ -5,19 +5,19 @@ using UnityEngine;
namespace BITKit.Entities.Player.Feel
{
public sealed class PlayerHitMotion : EntityComponent
public sealed class PlayerHitMotion : EntityBehavior
{
[SerializeField] private Spring3 spring;
[SerializeField] private LocationAdditive locationAdditive;
[SerializeField] private AnimationCurve damageBasedMotion;
public override void OnStart()
{
entity.AddListener<DamageMessage>(OnDamaged);
UnityEntity.AddListener<DamageMessage>(OnDamaged);
}
private void OnDamaged(DamageMessage obj)
{
if (obj.Target != entity) return;
if (obj.Target != UnityEntity) return;
var damage = damageBasedMotion.Evaluate(obj.Damage);
spring.value = new Vector3(damage.Random(), damage.Random(), damage.Random());
}

View File

@@ -41,33 +41,46 @@ namespace BITFALL.Melee
if (Queue.TryDequeue(out var command) is false) return;
var colliders = Physics.OverlapSphere(command.Position, command.Range,detectLayer);
var damaged= new List<IEntity>();
var damaged= new List<IUnityEntity>();
foreach (var x in colliders.Where(x=>x.GetComponent<IDamagable>() is not null))
{
try
{
var damageable = x.GetComponent<IDamagable>();
if (damaged.Contains(damageable.Entity) || damageable.Entity.Id == command.PlayerId)
var toTarget = x.transform.position - (Vector3)command.Position;
toTarget = Vector3.ProjectOnPlane(toTarget, Vector3.up);
// 获取正前方的向量
var forward = command.Forward;
// 计算点积
var dotProduct = Vector3.Dot(toTarget.normalized, forward);
if (dotProduct < 0.8f) continue;
if (damaged.Contains(damageable.UnityEntity) || damageable.UnityEntity?.Id == command.PlayerId)
{
continue;
}
damaged.Add(damageable.Entity);
damaged.Add(damageable.UnityEntity);
var damageMsg =
new DamageMessage()
{
Initiator = UnityEntitiesService.Get(command.PlayerId) as IEntity,
Initiator = UnityEntitiesService.Get(command.PlayerId) as IUnityEntity,
DamageType = new MeleeDamageMessage
{
},
Target = damageable.Entity,
Target = damageable.UnityEntity,
Damage = command.Damage is 0 ? 64 : command.Damage,
Hit = damageable,
};
if (command.PlayerId !=default)
{
damageMsg.Initiator = UnityEntitiesService.Get(command.PlayerId) as IEntity;
damageMsg.Initiator = UnityEntitiesService.Get(command.PlayerId) as IUnityEntity;
}
damageService.Execute(damageMsg);

View File

@@ -20,7 +20,7 @@ namespace BITFALL.Entities.Player.Movement
{
[CustomType(typeof(IEntityMovement))]
[CustomType(typeof(IPlayerMovement))]
public class PlayerCharacterController : StateBasedPlayerComponent<IEntityMovementState>,IEntityMovement,IPlayerMovement
public class PlayerCharacterController : StateBasedPlayerBehavior<IEntityMovementState>,IEntityMovement,IPlayerMovement
{
[SerializeField] private CharacterActor actor;
[SerializeField] private Vector3 initialCameraPosition = new(0,0.11f,0.27f);
@@ -228,6 +228,7 @@ namespace BITFALL.Entities.Player.Movement
{
if (!x.TryGetComponent<OffMeshLink>(out var offMeshLink)) continue;
var toTarget = x.transform.position - transform.position;
toTarget = Vector3.ProjectOnPlane(toTarget, Vector3.up);
// 获取正前方的向量
@@ -361,7 +362,7 @@ namespace BITFALL.Entities.Player.Movement
case > 0:
break;
case < -16:
entity.Invoke<DamageMessage>(new DamageMessage()
UnityEntity.Invoke<DamageMessage>(new DamageMessage()
{
Damage = value < -30 ? int.MaxValue : (int)math.abs(value) * 2 ,
DamageType = new GravityDamage(),
@@ -370,8 +371,8 @@ namespace BITFALL.Entities.Player.Movement
position = actor.Position,
rotation = actor.Rotation
},
Initiator = entity,
Target = entity,
Initiator = UnityEntity,
Target = UnityEntity,
});
break;
}

View File

@@ -14,7 +14,7 @@ namespace BITFALL.Entities.Player.Movement.States
public bool Enabled { get; set; }
public virtual void Initialize()
{
characterController.entity.Inject(this);
characterController.UnityEntity.Inject(this);
}
public virtual void OnStateEntry(IState old)

View File

@@ -12,7 +12,7 @@ namespace BITFALL.Player.Animation
{
void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState);
}
public class PlayerAnimationController : StateBasedComponent<IPlayerAnimationState>
public class PlayerAnimationController : StateBasedBehavior<IPlayerAnimationState>
{
[SerializeField] internal UnityAnimator animator;
@@ -25,7 +25,7 @@ namespace BITFALL.Player.Animation
public override void OnAwake()
{
base.OnAwake();
_movement = entity.Get<IEntityMovement>();
_movement = UnityEntity.Get<IEntityMovement>();
_movement.OnStateChanged += OnMovementStateChanged;
}

View File

@@ -9,7 +9,7 @@ using UnityEngine;
namespace BITFALL.Player.Survival
{
public class PlayerEatService : EntityComponent
public class PlayerEatService : EntityBehavior
{
[Inject] private IPlayerSurvivalService _survival;
[Inject] private IEntityInventory _inventory;

View File

@@ -15,7 +15,7 @@ namespace BITFALL.Player.Survival
public string Message;
}
[CustomType(typeof(IPlayerSurvivalService))]
public class PlayerSurvivalService : EntityComponent, IPlayerSurvivalService
public class PlayerSurvivalService : EntityBehavior, IPlayerSurvivalService
{
public IPlayerSurvivalElement[] Elements { get; set; } = Array.Empty<IPlayerSurvivalElement>();
[SerializeReference, SubclassSelector] private IPlayerSurvivalElement[] initialElements = Array.Empty<IPlayerSurvivalElement>();
@@ -55,7 +55,7 @@ namespace BITFALL.Player.Survival
{
element = x,
},
Target = entity,
Target = UnityEntity,
Damage = 1,
});
}

View File

@@ -10,7 +10,8 @@
"GUID:7efac18f239530141802fb139776f333",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:ea5474181b324dd49a5976cd68f44f18",
"GUID:bea3628e8b592ae47ade218cb9ec98db"
"GUID:bea3628e8b592ae47ade218cb9ec98db",
"GUID:8d74bfb2f67c5c14a810215b78383d40"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using UnityEngine;
using Random = UnityEngine.Random;
namespace BITFALL.Props
{
public class Prop_Shield : MonoBehaviour,IDamagable
{
[SerializeField] private SpringEulerAngle spring=new();
[SerializeField] private Optional<int> maxSpring;
public IUnityEntity UnityEntity => null;
public Rigidbody Rigidbody => null;
private Vector3 initialEulerAngles;
private void Start()
{
initialEulerAngles = transform.localEulerAngles;
}
private void FixedUpdate()
{
spring.Update(Time.fixedDeltaTime,initialEulerAngles);
transform.localEulerAngles = spring.value;
}
public void GiveDamage(DamageMessage message)
{
var damage = message.Damage;
if (maxSpring.Allow)
{
damage = Mathf.Min(damage, maxSpring.Value);
}
spring.value =initialEulerAngles + new Vector3(
Random.Range(-damage, damage),
Random.Range(-damage, damage),
Random.Range(-damage, damage)
);
}
}
}

View File

@@ -26,7 +26,7 @@ namespace BITFALL.Props
{
damagable.GiveDamage(new DamageMessage()
{
Target = damagable.Entity,
Target = damagable.UnityEntity,
Damage = damage,
Location = new Location()
{

View File

@@ -5,7 +5,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BITKit;
using BITKit.Core.Entites;
using BITKit.Entities;
using BITKit.Entities.Player;
using BITKit.Events;
using BITKit.Game;

View File

@@ -3,7 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BITKit;
using BITKit.Core.Entites;
using BITKit.Entities;
using Unity.Mathematics;
using UnityEngine;

View File

@@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using BITKit.Entities;
using UnityEngine;
using IEntity = BITKit.Core.Entites.IEntity;
using IEntity = BITKit.Entities.IEntity;
namespace BITFALL.Scenes
{

View File

@@ -73,11 +73,11 @@ namespace BITFALL
{
playerService.OnPlayerInitialized -= OnStartLocalPlayer;
}
private void OnStartLocalPlayer(IEntity entity)
private void OnStartLocalPlayer(IUnityEntity unityEntity)
{
cache.Clear();
entity.Inject(this);
unityEntity.Inject(this);
_entityEquipment.OnEquip += OnEquip;
_entityEquipment.OnUnEquip += OnUnEquip;

View File

@@ -86,9 +86,9 @@ namespace BITFALL.UX
{
seleableLabel.SetActive(false);
}
private async void OnPlayerInitializedLocalPlayer(IEntity entity)
private async void OnPlayerInitializedLocalPlayer(IUnityEntity unityEntity)
{
entity.Inject(this);
unityEntity.Inject(this);
_health.OnSetAlive += OnSetAlive;
@@ -113,7 +113,7 @@ namespace BITFALL.UX
playerAvatarImage.SetTexture(avatar);
}
_equipService = entity.Get<IEquipService>();
_equipService = unityEntity.Get<IEquipService>();
armorBar.SetActive(_armor.TryGetCurrentArmor(out _));

View File

@@ -37,7 +37,7 @@ namespace BITFALL.UX
private IEntityInventory inventory;
[Inject]
private IEntityEquipmentContainer equipContainer;
private IEntity _entity;
private IUnityEntity _unityEntity;
protected override async void Awake()
{
base.Awake();
@@ -52,7 +52,7 @@ namespace BITFALL.UX
equipContainers.Add(x.Name, uxContainer);
element.RegisterCallback<MouseDownEvent>(mouseEvent =>
{
if(_entity is null) return;
if(_unityEntity is null) return;
switch (mouseEvent.button)
{
case 0:
@@ -83,13 +83,13 @@ namespace BITFALL.UX
playerService.OnPlayerDisposed -= OnPlayerDisposed;
playerService.OnPlayerInitialized -= OnPlayerInitializedLocalPlayer;
}
private void OnPlayerInitializedLocalPlayer(IEntity entity)
private void OnPlayerInitializedLocalPlayer(IUnityEntity unityEntity)
{
entity.Inject(this);
unityEntity.Inject(this);
itemContainers.Clear();
builder.Clear();
var weighted = entity.Get<IPlayerInventoryWeightable>();
var weighted = unityEntity.Get<IPlayerInventoryWeightable>();
weighted.OnWeighted += OnWeighted;
@@ -102,7 +102,7 @@ namespace BITFALL.UX
inventory.OnUsedItem += OnRemove;
inventory.OnSet += OnSet;
_entity = entity;
_unityEntity = unityEntity;
}

View File

@@ -2,7 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Player.Movement;
using BITKit.Core.Entites;
using BITKit.Entities;
using UnityEngine;
using UnityEngine.InputSystem;