1
This commit is contained in:
@@ -81,8 +81,8 @@ namespace BITKit.Entities
|
||||
{
|
||||
public override DamageMessage ReadBinary(BinaryReader reader)
|
||||
{
|
||||
UnityEntitiesService.TryGetEntity(reader.ReadUInt64(),out var initiator);
|
||||
UnityEntitiesService.TryGetEntity(reader.ReadUInt64(),out var target);
|
||||
UnityEntitiesService.TryGetEntity(reader.ReadInt32(),out var initiator);
|
||||
UnityEntitiesService.TryGetEntity(reader.ReadInt32(),out var target);
|
||||
return new DamageMessage()
|
||||
{
|
||||
Initiator = initiator as Entity,
|
||||
|
@@ -3,7 +3,9 @@ using System.Collections.Generic;
|
||||
using BITFALL.Rig;
|
||||
using BITKit.Entities;
|
||||
using Cysharp.Threading.Tasks.Triggers;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
@@ -14,6 +16,7 @@ namespace BITKit
|
||||
[SerializeField] private EntityHitbox[] hitboxes;
|
||||
|
||||
[SerializeReference,SubclassSelector] private IReference[] tagReferences;
|
||||
#if UNITY_EDITOR
|
||||
[BIT]
|
||||
private void Build()
|
||||
{
|
||||
@@ -73,5 +76,6 @@ namespace BITKit
|
||||
}
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ namespace BITKit.Entities
|
||||
private readonly GenericEvent genericEvent = new();
|
||||
|
||||
|
||||
public ulong Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public CancellationToken CancellationToken { get; private set; }
|
||||
public IEntityBehavior[] Behaviors { get;private set; }
|
||||
public IEntityComponent[] Components => Behaviors.Cast<IEntityComponent>().ToArray();
|
||||
@@ -131,7 +131,7 @@ namespace BITKit.Entities
|
||||
private void Awake()
|
||||
{
|
||||
if (Id.IsDefault())
|
||||
Id = (ulong)Guid.NewGuid().GetHashCode();
|
||||
Id = GetInstanceID();
|
||||
CancellationToken = gameObject.GetCancellationTokenOnDestroy();
|
||||
Set(CancellationToken);
|
||||
}
|
||||
|
@@ -38,10 +38,10 @@ public class UnityEntitiesServiceSingleton:IEntitiesService
|
||||
|
||||
public CancellationToken CancellationToken => UnityEntitiesService.CancellationToken;
|
||||
|
||||
public IEntity Get(ulong id) => UnityEntitiesService.Get(id);
|
||||
public bool TryGetEntity(ulong id, out IEntity entity) => UnityEntitiesService.TryGetEntity(id, out entity);
|
||||
public IEntity Get(int id) => UnityEntitiesService.Get(id);
|
||||
public bool TryGetEntity(int id, out IEntity entity) => UnityEntitiesService.TryGetEntity(id, out entity);
|
||||
|
||||
public IEntity GetOrAdd(ulong id, Func<ulong, IEntity> factory)=>UnityEntitiesService.GetOrAdd(id,factory);
|
||||
public IEntity GetOrAdd(int id, Func<int, IEntity> factory)=>UnityEntitiesService.GetOrAdd(id,factory);
|
||||
|
||||
|
||||
public IEntity[] Query<T>()
|
||||
@@ -85,7 +85,7 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
return false;
|
||||
}
|
||||
public static CancellationToken CancellationToken;
|
||||
private static readonly ConcurrentDictionary<ulong,IEntity> Dictionary=new();
|
||||
private static readonly ConcurrentDictionary<int,IEntity> Dictionary=new();
|
||||
private static readonly Queue<IEntity> RegisterQueue = new();
|
||||
private static readonly Queue<IEntity> UnRegisterQueue = new();
|
||||
private void Awake()
|
||||
@@ -126,18 +126,18 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
}
|
||||
|
||||
CancellationToken IEntitiesService.CancellationToken => CancellationToken;
|
||||
public static IEntity Get(ulong id)=>Dictionary[id];
|
||||
IEntity IEntitiesService.Get(ulong id)=>Get(id);
|
||||
public static bool TryGetEntity(ulong id, out IEntity entity)
|
||||
public static IEntity Get(int id)=>Dictionary[id];
|
||||
IEntity IEntitiesService.Get(int id)=>Get(id);
|
||||
public static bool TryGetEntity(int id, out IEntity entity)
|
||||
{
|
||||
return Dictionary.TryGetValue(id, out entity);
|
||||
}
|
||||
bool IEntitiesService.TryGetEntity(ulong id, out IEntity entity)=>TryGetEntity(id,out entity);
|
||||
public static IEntity GetOrAdd(ulong id, Func<ulong, IEntity> factory)
|
||||
bool IEntitiesService.TryGetEntity(int id, out IEntity entity)=>TryGetEntity(id,out entity);
|
||||
public static IEntity GetOrAdd(int id, Func<int, IEntity> factory)
|
||||
{
|
||||
return Dictionary.GetOrAdd(id, factory);
|
||||
}
|
||||
IEntity IEntitiesService.GetOrAdd(ulong id, Func<ulong, IEntity> factory)=>GetOrAdd(id,factory);
|
||||
IEntity IEntitiesService.GetOrAdd(int id, Func<int, IEntity> factory)=>GetOrAdd(id,factory);
|
||||
|
||||
IEntity[] IEntitiesService.Query<T>()=>Query<T>();
|
||||
public static IEntity[] Query<T>()
|
||||
|
@@ -7,14 +7,14 @@ namespace BITKit.Entities
|
||||
{
|
||||
public interface IdComponent
|
||||
{
|
||||
ulong Id { get; }
|
||||
int Id { get; }
|
||||
string Name { get; }
|
||||
}
|
||||
public class UnityIdComponent : EntityBehavior,IdComponent
|
||||
{
|
||||
[SerializeField] private ulong id;
|
||||
[SerializeField] private int id;
|
||||
[SerializeField] private string unityName;
|
||||
public ulong Id => id;
|
||||
public int Id => id;
|
||||
public string Name => unityName;
|
||||
public override void Initialize(IEntity _entity)
|
||||
{
|
||||
|
@@ -19,7 +19,7 @@ namespace BITKit.Entities
|
||||
public struct EntitiesNetSyncBatchCommand
|
||||
{
|
||||
public int Length;
|
||||
public ulong[] Ids;
|
||||
public int[] Ids;
|
||||
public ulong[] AddressablePaths;
|
||||
public EntitiesNetSyncCommand[] Commands;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace BITKit.Entities
|
||||
{
|
||||
using var ms = new MemoryStream(obj.Data);
|
||||
using var reader = new BinaryReader(ms);
|
||||
var id = reader.ReadUInt64();
|
||||
var id = reader.ReadInt32();
|
||||
var path = reader.ReadUInt64();
|
||||
entitiesService.GetOrAdd(id, x => AddEntity(id, path)).TryGetComponent<IEntityBinaryHeader>(out var header);
|
||||
header.Deserialize(reader);
|
||||
@@ -100,7 +100,7 @@ namespace BITKit.Entities
|
||||
header.Deserialize(reader);
|
||||
}
|
||||
}
|
||||
private static IEntity AddEntity(ulong id,ulong addressableId)
|
||||
private static IEntity AddEntity(int id,ulong addressableId)
|
||||
{
|
||||
var entity = AddressableHelper.Get<GameObject>(addressableId);
|
||||
var instance = Instantiate(entity).GetComponent<Entity>();
|
||||
@@ -146,7 +146,7 @@ namespace BITKit.Entities
|
||||
var batchCommand = new EntitiesNetSyncBatchCommand()
|
||||
{
|
||||
Length = headers.Length,
|
||||
Ids = new ulong[headers.Length],
|
||||
Ids = new int[headers.Length],
|
||||
AddressablePaths = new ulong[headers.Length],
|
||||
Commands = new EntitiesNetSyncCommand[headers.Length]
|
||||
};
|
||||
|
@@ -15,8 +15,8 @@ namespace BITKit.Entities.Player
|
||||
[SerializeField] private MonoStateMachine<T> stateMachine;
|
||||
public override void OnAwake()
|
||||
{
|
||||
stateMachine?.Initialize();
|
||||
base.OnAwake();
|
||||
stateMachine?.Initialize();
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
|
Reference in New Issue
Block a user