2023-06-05 19:57:17 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2023-06-29 14:57:11 +08:00
|
|
|
|
using BITKit.Core.Entites;
|
2023-06-05 19:57:17 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
|
namespace BITKit.Entities
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Entity接口,用于复杂实体</summary>
|
2023-06-29 14:57:11 +08:00
|
|
|
|
public interface IEntity :BITKit.Core.Entites.IEntity,IGenericEvent<string>, IDatabase, IProcessor, ICallback
|
2023-06-05 19:57:17 +08:00
|
|
|
|
{
|
|
|
|
|
IEntityComponent[] entityComponents { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public class IEntityReader : NetMessageReader<IEntity>
|
|
|
|
|
{
|
|
|
|
|
public override IEntity ReadBinary(BinaryReader reader)
|
|
|
|
|
{
|
|
|
|
|
var id = reader.ReadInt32();
|
|
|
|
|
var path = reader.ReadString();
|
2023-06-29 14:57:11 +08:00
|
|
|
|
var entity = DI.Get<IEntitiesService>().Entities[id];
|
|
|
|
|
return (IEntity)entity;
|
2023-06-05 19:57:17 +08:00
|
|
|
|
}
|
|
|
|
|
public override void WriteBinary(BinaryWriter writer, IEntity value)
|
|
|
|
|
{
|
|
|
|
|
writer.Write(value.Id);
|
2023-08-23 01:59:26 +08:00
|
|
|
|
writer.Write(value.Id);
|
2023-06-05 19:57:17 +08:00
|
|
|
|
}
|
2023-08-23 01:59:26 +08:00
|
|
|
|
private IEntity Create(int id, string path)
|
2023-06-05 19:57:17 +08:00
|
|
|
|
{
|
|
|
|
|
var entity = Addressables
|
|
|
|
|
.LoadAssetAsync<GameObject>(path)
|
|
|
|
|
.WaitForCompletion()
|
|
|
|
|
.GetComponent<IEntity>();
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|