1
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Entities.Player
|
||||
{
|
||||
public class LocalPlayerBehavior : EntityBehavior
|
||||
public class LocalPlayerBehavior : EntityBehavior,IEntityBinaryComponent
|
||||
{
|
||||
public int Id { get; }= new ConstantHash(nameof(LocalPlayerBehavior));
|
||||
|
||||
private IEntityPlayerComponent[] playerComponents;
|
||||
private CancellationTokenSource initializeCancellationTokenSource;
|
||||
private CancellationTokenSource disposeCancellationTokenSource;
|
||||
|
||||
public override async void OnStart()
|
||||
{
|
||||
initializeCancellationTokenSource = new CancellationTokenSource();
|
||||
@@ -51,5 +55,13 @@ namespace BITKit.Entities.Player
|
||||
disposeCancellationTokenSource.Dispose();
|
||||
UnityPlayerServiceService.UnRegister((Entity)UnityEntity);
|
||||
}
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
public void Deserialize(BinaryReader reader)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
Src/Unity/Scripts/Entity/Player/ProxyPlayerComponent.cs
Normal file
36
Src/Unity/Scripts/Entity/Player/ProxyPlayerComponent.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Entities.Player
|
||||
{
|
||||
public class ProxyPlayerComponent : EntityBehavior,IEntityBinaryComponent
|
||||
{
|
||||
public int Id { get; } = new ConstantHash(nameof(LocalPlayerBehavior));
|
||||
private readonly IntervalUpdate _timeout = new(8);
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
_timeout.Reset();
|
||||
}
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
}
|
||||
public void Deserialize(BinaryReader reader)
|
||||
{
|
||||
reader.ReadInt32();
|
||||
_timeout.Reset();
|
||||
}
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
base.OnUpdate(deltaTime);
|
||||
if (_timeout.AllowUpdate)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Src/Unity/Scripts/Entity/Player/ProxyPlayerComponent.cs.meta
Normal file
11
Src/Unity/Scripts/Entity/Player/ProxyPlayerComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e25b0e453185f74428146cbe5a5f99fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -36,6 +37,9 @@ namespace BITKit.Entities.Player
|
||||
remove => stateMachine.OnStateChanged -= value;
|
||||
}
|
||||
|
||||
public event Action<T> OnStateRegistered;
|
||||
public event Action<T> OnStateUnRegistered;
|
||||
|
||||
public IDictionary<Type, T> StateDictionary => stateMachine.StateDictionary;
|
||||
|
||||
void IStateMachine<T>.Initialize()
|
||||
@@ -62,5 +66,16 @@ namespace BITKit.Entities.Player
|
||||
{
|
||||
stateMachine.TransitionState(state);
|
||||
}
|
||||
public virtual void Register(T newState)=>StateMachineUtils.Register(this,newState);
|
||||
public virtual void UnRegister(T newState)=>StateMachineUtils.UnRegister(this,newState);
|
||||
void IStateMachine<T>.InvokeOnStateRegistered(T state)
|
||||
{
|
||||
OnStateRegistered?.Invoke(state);
|
||||
}
|
||||
|
||||
void IStateMachine<T>.InvokeOnStateUnRegistered(T state)
|
||||
{
|
||||
OnStateUnRegistered?.Invoke(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user