1
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
// }
|
||||
// }
|
||||
}
|
26
Src/Unity/Scripts/Entity/Core/UnityIdComponent.cs
Normal file
26
Src/Unity/Scripts/Entity/Core/UnityIdComponent.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Src/Unity/Scripts/Entity/Core/UnityIdComponent.cs.meta
Normal file
11
Src/Unity/Scripts/Entity/Core/UnityIdComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7deed5246427534489a19e5325df9a8d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user