1
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Player.Camera",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:a45ea9d98164db34f9c3c360d07b4ab2",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:7efac18f239530141802fb139776f333"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 638f6e16b87ad5c4b8898803586edd2f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,3 +1,4 @@
|
||||
using BITKit.Entities.Player;
|
||||
using UnityEngine;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
@@ -8,14 +9,10 @@ namespace BITKit.Entities
|
||||
public Behaviour deathCamera;
|
||||
[Header(Constant.Header.Reference)]
|
||||
[SerializeReference, SubclassSelector] public IReference _onSetAlive;
|
||||
|
||||
public override void OnPlayerInitialized()
|
||||
public override void OnAwake()
|
||||
{
|
||||
OnSetAlive(true);
|
||||
}
|
||||
public override void OnPlayerDispose()
|
||||
{
|
||||
aliveCamera.enabled = deathCamera.enabled = false;
|
||||
var heal = entity.Get<IHealth>();
|
||||
heal.OnSetAlive += OnSetAlive;
|
||||
}
|
||||
private void OnSetAlive(bool alive)
|
||||
{
|
||||
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Player.Character",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:7efac18f239530141802fb139776f333"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05850b7e403af6d48bc240ab3c2bc8f4
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,26 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
namespace BITKit.Entities
|
||||
namespace BITKit.Entities.Player.Character
|
||||
{
|
||||
public class EntityCharacter : EntityPlayerComponent
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
public List<Renderer> fpvRenderer = new();
|
||||
public List<Renderer> tpvRenderer = new();
|
||||
[SerializeField] private Renderer[] fpvRenderer = Array.Empty<Renderer>();
|
||||
[SerializeField] private Renderer[] tpvRenderer = Array.Empty<Renderer>();
|
||||
[Header(Constant.Header.Reference)]
|
||||
[SerializeReference, SubclassSelector] public References _isAlive;
|
||||
[SerializeReference, SubclassSelector] public References _getDamage;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
entity.AddListener<bool>(nameof(OnSetAlive), OnSetAlive);
|
||||
entity.AddListener<int>(nameof(OnSetHP), OnSetHP);
|
||||
var heal = entity.Get<IHealth>();
|
||||
heal.OnSetAlive += OnSetAlive;
|
||||
heal.OnSetHealthPoint += OnSetHP;
|
||||
}
|
||||
|
||||
public override void OnPlayerInitialized()
|
||||
{
|
||||
|
||||
OnSetAlive(true);
|
||||
}
|
||||
|
||||
|
@@ -62,6 +62,18 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
public interface IEntityMovement:IStateMachine<IEntityMovementState>
|
||||
{
|
||||
/// <summary>
|
||||
/// 视角中心,通常是摄像机的位置
|
||||
/// </summary>
|
||||
Vector3 ViewCenter { get; }
|
||||
/// <summary>
|
||||
/// 视角旋转,通常是摄像机的旋转
|
||||
/// </summary>
|
||||
Quaternion ViewRotation { get; }
|
||||
/// <summary>
|
||||
/// 基于运动的速度,是相对于标准化移动速度的相对速度
|
||||
/// </summary>
|
||||
Vector3 LocomotionBasedVelocity { get; }
|
||||
/// <summary>
|
||||
/// 世界空间的速度
|
||||
/// </summary>
|
||||
@@ -71,6 +83,10 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
Vector3 GroundVelocity { get; }
|
||||
/// <summary>
|
||||
/// 旋转速度
|
||||
/// </summary>
|
||||
Vector3 AngularVelocity { get; }
|
||||
/// <summary>
|
||||
/// 是否在地面上
|
||||
/// </summary>
|
||||
bool IsGrounded { get; }
|
||||
@@ -92,8 +108,16 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
void Movement(InputAction.CallbackContext context);
|
||||
|
||||
/// <summary>
|
||||
/// 执行命令
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
void ExecuteCommand<T>(T command=default);
|
||||
/// <summary>
|
||||
/// 执行命令的回调
|
||||
/// </summary>
|
||||
event Action<object> OnCommand;
|
||||
}
|
||||
public interface IEntityMovementState:IState
|
||||
{
|
||||
@@ -103,79 +127,4 @@ namespace BITKit.Entities
|
||||
void AfterUpdateMovement(float deltaTime);
|
||||
void ExecuteCommand<T>(T command);
|
||||
}
|
||||
public interface IPlayerMovementCommand{}
|
||||
[Serializable]
|
||||
public class MonoMovementProxy:IEntityMovement
|
||||
{
|
||||
[SerializeField] private MonoBehaviour monoBehaviour;
|
||||
private IEntityMovement _entityMovementImplementation=>monoBehaviour as IEntityMovement;
|
||||
|
||||
public Vector3 Velocity => _entityMovementImplementation.Velocity;
|
||||
|
||||
public Vector3 GroundVelocity => _entityMovementImplementation.GroundVelocity;
|
||||
|
||||
public bool IsGrounded => _entityMovementImplementation.IsGrounded;
|
||||
|
||||
public void SyncMovement(Vector3 velocity, Vector3 position, Quaternion rotation, bool isGrounded)
|
||||
{
|
||||
_entityMovementImplementation.SyncMovement(velocity, position, rotation, isGrounded);
|
||||
}
|
||||
|
||||
public void Movement(Vector3 relativeVector)
|
||||
{
|
||||
_entityMovementImplementation.Movement(relativeVector);
|
||||
}
|
||||
|
||||
public void Movement(InputAction.CallbackContext context)
|
||||
{
|
||||
_entityMovementImplementation.Movement(context);
|
||||
}
|
||||
|
||||
public void ExecuteCommand<T>(T command)=>_entityMovementImplementation.ExecuteCommand(command);
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => _entityMovementImplementation.Enabled;
|
||||
set => _entityMovementImplementation.Enabled = value;
|
||||
}
|
||||
|
||||
public IEntityMovementState CurrentState
|
||||
{
|
||||
get => _entityMovementImplementation.CurrentState;
|
||||
set => _entityMovementImplementation.CurrentState = value;
|
||||
}
|
||||
|
||||
public event Action<IEntityMovementState, IEntityMovementState> OnStateChanged
|
||||
{
|
||||
add => _entityMovementImplementation.OnStateChanged += value;
|
||||
remove => _entityMovementImplementation.OnStateChanged -= value;
|
||||
}
|
||||
|
||||
public IDictionary<Type, IEntityMovementState> StateDictionary => _entityMovementImplementation.StateDictionary;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_entityMovementImplementation.Initialize();
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
_entityMovementImplementation.UpdateState();
|
||||
}
|
||||
|
||||
public void DisposeState()
|
||||
{
|
||||
_entityMovementImplementation.DisposeState();
|
||||
}
|
||||
|
||||
public void TransitionState<State>() where State : IEntityMovementState
|
||||
{
|
||||
_entityMovementImplementation.TransitionState<State>();
|
||||
}
|
||||
|
||||
public void TransitionState(IEntityMovementState state)
|
||||
{
|
||||
_entityMovementImplementation.TransitionState(state);
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,8 +13,13 @@ namespace BITKit
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
#endregion
|
||||
#region 接口实现
|
||||
|
||||
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;
|
||||
@@ -53,6 +58,8 @@ namespace BITKit
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public event Action<object> OnCommand;
|
||||
|
||||
public void OnSetAlive(bool alive)
|
||||
{
|
||||
switch (alive)
|
||||
|
@@ -27,7 +27,9 @@ namespace BITKit.Entities
|
||||
public virtual void OnAwake() {Initialize();}
|
||||
public virtual void OnStart() { }
|
||||
public virtual void OnUpdate(float deltaTime) { }
|
||||
public virtual void PlayAudio(string name) { }
|
||||
public virtual void PlayAudio(string eventName) { }
|
||||
public virtual void EquipEvent(string eventName){}
|
||||
public virtual void AnimationEvent(string eventName){}
|
||||
}
|
||||
public class EntityEquipment : EntityComponent
|
||||
{
|
||||
|
@@ -43,7 +43,7 @@ namespace BITKit.Entities
|
||||
int MaxHealthPoint { get; set; }
|
||||
bool IsAlive { get; }
|
||||
}
|
||||
|
||||
[CustomType(typeof(IHealth))]
|
||||
public class EntityHealth : EntityComponent, IHealth
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
@@ -70,14 +70,6 @@ namespace BITKit.Entities
|
||||
set => maxHealthPoint = value;
|
||||
}
|
||||
public bool IsAlive { get; private set; }
|
||||
|
||||
public override void Initialize(IEntity _entity)
|
||||
{
|
||||
base.Initialize(_entity);
|
||||
_entity.Set<IHealth>(this);
|
||||
_entity.Set(this);
|
||||
}
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
entity.AddListener<DamageMessage>(OnDamage);
|
||||
@@ -98,9 +90,6 @@ namespace BITKit.Entities
|
||||
{
|
||||
OnSetAliveInternal(IsAlive = _isAlive);
|
||||
}
|
||||
|
||||
//entity.Invoke<int>(_onSetHP, newHP);
|
||||
//entity.Set<int>("HP", newHP);
|
||||
foreach (var x in entity.GetCallbacks<IHealthCallback>())
|
||||
{
|
||||
x.OnSetHP(newHP);
|
||||
@@ -116,20 +105,17 @@ namespace BITKit.Entities
|
||||
|
||||
private void OnSetAliveInternal(bool alive)
|
||||
{
|
||||
IsAlive = alive;
|
||||
foreach (var x in entity.GetCallbacks<IHealthCallback>())
|
||||
{
|
||||
x.OnSetAlive(alive);
|
||||
}
|
||||
|
||||
foreach (var x in additiveCallback)
|
||||
{
|
||||
x.OnSetAlive(alive);
|
||||
}
|
||||
|
||||
//entity.Invoke<bool>(_onSetAlive, alive);
|
||||
//entity.Set<bool>(_isAlive, alive);
|
||||
onSetAlive.Invoke(alive);
|
||||
OnSetAlive?.Invoke(alive);
|
||||
onSetAlive.Invoke(alive);
|
||||
}
|
||||
|
||||
private void AddHP(int hp)
|
||||
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Player.Interactive",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e144f3bb79485843b0a2df56bef0900
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
namespace BITKit.Entities
|
||||
namespace BITKit.Entities.Player
|
||||
{
|
||||
public class EntityInteractive : EntityPlayerComponent
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace BITKit.Entities
|
||||
private IntervalUpdate cd = new(0.08f);
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (Physics.Raycast(cameraTransform.position,cameraTransform.forward, out var raycastHit, distance, layerMask))
|
||||
if (Physics.Raycast(cameraTransform.position,cameraTransform.forward, out var raycastHit, distance, layerMask,QueryTriggerInteraction.Collide))
|
||||
{
|
||||
if (raycastHit.transform.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace BITKit.Entities
|
||||
}
|
||||
public void Interactive(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.interaction is not TapInteraction || !context.performed) return;
|
||||
if (context.interaction is not PressInteraction || !context.performed) return;
|
||||
var _selected = selected;
|
||||
if (_selected is not MonoBehaviour monoBehaviour) return;
|
||||
if (monoBehaviour.TryGetComponentAny<IAction>(out var action))
|
||||
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"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
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be39401f40b20344a8e59d5ddab532bc
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b5481cf34bf4a145898ac81e58abf8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Physics"
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3de65b07192e7d49bad7b4032d681de
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Entities.Physics
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体物理接口
|
||||
/// </summary>
|
||||
public interface IEntityPhysics
|
||||
{
|
||||
Vector3 Center { get; }
|
||||
bool IsPhysics { get; }
|
||||
Vector3 Velocity { get; set; }
|
||||
Action<bool> OnSetPhysics { get; set; }
|
||||
void AddForce(Vector3 force, ForceMode mode = ForceMode.Force);
|
||||
void AddTorque(Vector3 torque, ForceMode mode = ForceMode.Force);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecf777fa24b00f5428d1e768c080b324
|
||||
guid: 3d2b4cbe319042c42a1d9c2b825a499e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,32 +1,74 @@
|
||||
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
|
||||
{
|
||||
public class EntityPhysics : EntityComponent, IHealthCallback
|
||||
[CustomType(typeof(IEntityPhysics))]
|
||||
public class EntityPhysics : EntityComponent,IEntityPhysics, IHealthCallback
|
||||
{
|
||||
public Animator animator;
|
||||
public Rigidbody[] rigidbodies;
|
||||
public Collider[] ragdollColliders;
|
||||
public override void OnStart()
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private Rigidbody[] rigidbodies;
|
||||
[SerializeField] private Collider[] ragdollColliders;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
private CancellationToken _cancellationToken;
|
||||
public override void OnAwake()
|
||||
{
|
||||
entity.RegisterCallback<IHealthCallback>(this);
|
||||
_cancellationToken = entity.Get<CancellationToken>();
|
||||
}
|
||||
void IHealthCallback.OnSetAlive(bool alive)
|
||||
async void IHealthCallback.OnSetAlive(bool alive)
|
||||
{
|
||||
if(animator)
|
||||
animator.enabled = alive;
|
||||
rigidbodies.ForEach(x =>
|
||||
IsPhysics = !alive;
|
||||
if (animator)
|
||||
animator.enabled = alive;
|
||||
try
|
||||
{
|
||||
x.isKinematic = alive;
|
||||
});
|
||||
ragdollColliders.ForEach(x =>
|
||||
await Task.Delay(10, _cancellationToken);
|
||||
rigidbodies.ForEach(x => { x.isKinematic = alive; });
|
||||
ragdollColliders.ForEach(x => { x.enabled = !alive; });
|
||||
OnSetPhysics?.Invoke(!alive);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
x.enabled = !alive;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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,56 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public class LocalPlayerComponent : EntityComponent
|
||||
{
|
||||
public override Type BaseType => typeof(LocalPlayerComponent);
|
||||
private IEntityPlayerComponent[] playerComponents;
|
||||
private CancellationTokenSource initializeCancellationTokenSource;
|
||||
private CancellationTokenSource disposeCancellationTokenSource;
|
||||
public override async void OnStart()
|
||||
{
|
||||
initializeCancellationTokenSource = new CancellationTokenSource();
|
||||
disposeCancellationTokenSource = new CancellationTokenSource();
|
||||
playerComponents = GetComponentsInChildren<IEntityPlayerComponent>(true);
|
||||
|
||||
IEntity.OnPlayerInitializedLocalPlayer.Invoke(entity);
|
||||
|
||||
foreach (var x in playerComponents)
|
||||
{
|
||||
x.OnPlayerInitialize();
|
||||
}
|
||||
foreach (var x in playerComponents)
|
||||
{
|
||||
initializeCancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
await x.OnPlayerInitializedAsync(initializeCancellationTokenSource.Token);
|
||||
}
|
||||
foreach (var x in playerComponents)
|
||||
{
|
||||
x.OnPlayerInitialized();
|
||||
}
|
||||
}
|
||||
public override async void OnDestroyComponent()
|
||||
{
|
||||
initializeCancellationTokenSource?.Cancel();
|
||||
foreach (var x in playerComponents)
|
||||
{
|
||||
x.OnPlayerDispose();
|
||||
}
|
||||
foreach (var x in playerComponents)
|
||||
{
|
||||
disposeCancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
await x.OnPlayerDisposeAsync(disposeCancellationTokenSource.Token);
|
||||
}
|
||||
foreach (var x in playerComponents)
|
||||
{
|
||||
x.OnPlayerDisposed();
|
||||
}
|
||||
disposeCancellationTokenSource.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user