This commit is contained in:
CortexCore
2023-11-15 23:55:06 +08:00
parent 5446067f91
commit 70247f0242
82 changed files with 3271 additions and 579 deletions

View File

@@ -156,6 +156,21 @@ namespace BITKit.Entities
public void Invoke<T>(string key, T value) => genericEvent.Invoke<T>(key, value);
public void Invoke<T>() where T : new() => genericEvent.Invoke<T>();
public void RemoveListener<T>(string key, Action<T> action) => genericEvent.RemoveListener<T>(key, action);
public void SetDirect(int key, object value)
{
genericEvent.SetDirect(key, value);
}
public void GetDirect(int key, out object value)
{
genericEvent.GetDirect(key, out value);
}
public void GetDirect<T>(int key, out T value)
{
genericEvent.GetDirect(key, out value);
}
public T Get<T>(string key = Constant.System.Internal)
{
var value = genericEvent.Get<T>(key);

View File

@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.IO;
using BITKit.Entities;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace BITKit.Entities
{
/// <summary>Entity接口用于复杂实体</summary>
@@ -14,27 +13,27 @@ namespace BITKit.Entities
void AddService(object service);
void AddService(Type type, object service);
}
public class IEntityReader : NetMessageReader<IUnityEntity>
{
public override IUnityEntity ReadBinary(BinaryReader reader)
{
var id = reader.ReadInt32();
var path = reader.ReadString();
var entity = DI.Get<IEntitiesService>().Entities[id];
return (IUnityEntity)entity;
}
public override void WriteBinary(BinaryWriter writer, IUnityEntity value)
{
writer.Write(value.Id);
writer.Write(value.Id);
}
private IUnityEntity Create(int id, string path)
{
var entity = Addressables
.LoadAssetAsync<GameObject>(path)
.WaitForCompletion()
.GetComponent<IUnityEntity>();
return entity;
}
}
// public class IEntityReader : NetMessageReader<IUnityEntity>
// {
// public override IUnityEntity ReadBinary(BinaryReader reader)
// {
// var id = reader.ReadInt32();
// var path = reader.ReadString();
// var entity = DI.Get<IEntitiesService>().Entities[id];
// return (IUnityEntity)entity;
// }
// public override void WriteBinary(BinaryWriter writer, IUnityEntity value)
// {
// writer.Write(value.Id);
// writer.Write(value.Id);
// }
// private IUnityEntity Create(int id, string path)
// {
// var entity = Addressables
// .LoadAssetAsync<GameObject>(path)
// .WaitForCompletion()
// .GetComponent<IUnityEntity>();
// return entity;
// }
// }
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.Entities
{
public interface IdComponent
{
ulong Id { get; }
string Name { get; }
}
public class UnityIdComponent : EntityBehavior,IdComponent
{
[SerializeField] private ulong id;
[SerializeField] private string unityName;
public ulong Id => id;
public string Name => unityName;
public override void Initialize(IEntity _entity)
{
base.Initialize(_entity);
id = _entity.Id;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7deed5246427534489a19e5325df9a8d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: