This commit is contained in:
CortexCore
2024-06-18 17:57:21 +08:00
parent 82294e44ee
commit d3fd104900
10 changed files with 105 additions and 43 deletions

View File

@@ -18,9 +18,12 @@ namespace BITKit.Entities
public class Entity : MonoBehaviour, IUnityEntity
{
private readonly GenericEvent genericEvent = new();
public int Id { get; set; }
[SerializeField,ReadOnly] private int id;
public int Id
{
get => id;
set => id = value;
}
public CancellationToken CancellationToken { get; private set; }
public IEntityBehavior[] Behaviors { get;private set; }
public IEntityComponent[] Components => Behaviors.Cast<IEntityComponent>().ToArray();
@@ -251,18 +254,18 @@ namespace BITKit.Entities
public void Set<T>(T value) => genericEvent.Set<T>(value);
public void Set<T>(string key = Constant.System.Internal, T value = default) => genericEvent.Set<T>(key, value);
}
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(Entity))]
public class EntityInspector : BITInspector<Entity>
{
public override VisualElement CreateInspectorGUI()
{
FillDefaultInspector();
CreateSubTitle("Identity");
var idLabel = root.Create<Label>();
idLabel.text = agent.Id.ToString();
return root;
}
}
#endif
// #if UNITY_EDITOR
// [UnityEditor.CustomEditor(typeof(Entity))]
// public class EntityInspector : BITInspector<Entity>
// {
// public override VisualElement CreateInspectorGUI()
// {
// FillDefaultInspector();
// CreateSubTitle("Identity");
// var idLabel = root.Create<Label>();
// idLabel.text = agent.Id.ToString();
// return root;
// }
// }
// #endif
}

View File

@@ -9,6 +9,14 @@ namespace BITKit.Entities
[CustomType(typeof(IEntityBinaryHeader))]
public class EntityBinaryHeader : EntityBehavior,IEntityBinaryHeader
{
[Header(Constant.Header.Debug)]
[SerializeField]
[ReadOnly]private Vector2 traffic;
[SerializeField]
[ReadOnly]private string upTraffic;
[SerializeField]
[ReadOnly]private string downTraffic;
public int Id => (int)Entity.Id;
public IDictionary<int, IEntityBinaryComponent> ComponentDictionary { get; } =
new Dictionary<int, IEntityBinaryComponent>();
@@ -44,7 +52,9 @@ namespace BITKit.Entities
var bytes = ms.ToArray();
writer.Write(bytes.Length);
writer.Write(bytes);
traffic.x += bytes.Length;
}
upTraffic = NetUtils.GetFileSize((long)traffic.x);
}
public void Deserialize(BinaryReader reader)
{
@@ -67,7 +77,9 @@ namespace BITKit.Entities
using var binaryReader = new BinaryReader(stream);
//BIT4Log.Log<EntityBinaryHeader>($"id:{id},length:{length},bytes:\n{JsonHelper.Get(bytes)}");
ComponentDictionary[id].Deserialize(binaryReader);
traffic.y += length;
}
downTraffic = NetUtils.GetFileSize((long)traffic.y);
}
}
}