breakpoint
This commit is contained in:
@@ -32,8 +32,8 @@ namespace BITKit.Entities
|
||||
if (id != value)
|
||||
{
|
||||
id = value;
|
||||
EntitiesManager.Dictionary.TryRemove(id, out var _);
|
||||
EntitiesManager.GetOrAdd(id, x => this);
|
||||
UnityEntitiesManager.Dictionary.TryRemove(id, out var _);
|
||||
UnityEntitiesManager.GetOrAdd(id, x => this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,12 +48,12 @@ namespace BITKit.Entities
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnAwake());
|
||||
entityComponents.ForEach(x => x.OnStart());
|
||||
EntitiesManager.Dictionary.AddOrUpdate(id, (x) => this, (x1, x2) => this);
|
||||
UnityEntitiesManager.Dictionary.AddOrUpdate(id, (x) => this, (x1, x2) => this);
|
||||
}
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnDestroyComponent());
|
||||
EntitiesManager.Dictionary.TryRemove(id, out var _);
|
||||
UnityEntitiesManager.Dictionary.TryRemove(id, out var _);
|
||||
}
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
@@ -21,7 +21,7 @@ namespace BITKit.Entities
|
||||
{
|
||||
var id = reader.ReadInt32();
|
||||
var path = reader.ReadString();
|
||||
var entity = EntitiesManager.GetOrAdd(id, _id => Create(id, path));
|
||||
var entity = UnityEntitiesManager.GetOrAdd(id, _id => Create(id, path));
|
||||
return entity;
|
||||
}
|
||||
public override void WriteBinary(BinaryWriter writer, IEntity value)
|
||||
|
@@ -5,17 +5,21 @@ using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using BITKit;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public class EntitiesManager
|
||||
public interface IEntitesManager
|
||||
{
|
||||
|
||||
}
|
||||
public class UnityEntitiesManager:MonoBehaviour
|
||||
{
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void Reload()
|
||||
{
|
||||
Dictionary.Clear();
|
||||
}
|
||||
public static ConcurrentDictionary<int, IEntity> Dictionary = new();
|
||||
public static Func<int, IEntity> CreateFactory;
|
||||
public static readonly ConcurrentDictionary<int, IEntity> Dictionary = new();
|
||||
public static IEntity Get(int id)
|
||||
{
|
||||
if (Dictionary.TryGetValue(id, out var entity))
|
||||
@@ -29,8 +33,16 @@ namespace BITKit.Entities
|
||||
}
|
||||
public static IEntity GetOrAdd(int id)
|
||||
{
|
||||
return GetOrAdd(id, CreateFactory);
|
||||
var instance = Instantiate(Singleton.prefab);
|
||||
instance.Id = id;
|
||||
return GetOrAdd(id,x=>instance);
|
||||
}
|
||||
public static IEntity GetOrAdd(int id, Func<int, IEntity> createFacotry) => Dictionary.GetOrAdd(id, createFacotry);
|
||||
private static UnityEntitiesManager Singleton;
|
||||
public Entity prefab;
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user