提交 129aae93 编写于 作者: T tanghai

让Component的id不进行序列化

上级 26436533
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "127.0.0.1", "Port" : 10000, "Host2" : null }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("98565862653976"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("98565862653977"), "Host" : "127.0.0.1", "Port" : 10001 }], "AppId" : 2, "AppType" : "Location", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "127.0.0.1", "Port" : 20001 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }], "AppId" : 3, "AppType" : "Realm", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "127.0.0.1", "Port" : 20002 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "127.0.0.1", "Port" : 10003, "Host2" : null }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "127.0.0.1", "Port" : 20003 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "127.0.0.1", "Port" : 10004, "Host2" : null }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "127.0.0.1", "Port" : 20004 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "127.0.0.1", "Port" : 10005, "Host2" : null }], "AppId" : 6, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "127.0.0.1", "Port" : 20005 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "127.0.0.1", "Port" : 10006, "Host2" : null }], "AppId" : 7, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("98565723062316"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("98565723062317"), "Host" : "127.0.0.1", "Port" : 20006 }], "AppId" : 8, "AppType" : "Map", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10000, "Host2" : null }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("98565862653976"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 10001 }], "AppId" : 2, "AppType" : "Location", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20001 }, { "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }], "AppId" : 3, "AppType" : "Realm", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20002 }, { "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10003, "Host2" : null }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20003 }, { "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10004, "Host2" : null }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20004 }, { "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10005, "Host2" : null }], "AppId" : 6, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20005 }, { "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10006, "Host2" : null }], "AppId" : 7, "AppType" : "Gate", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("98565723062316"), "components" : [{ "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20006 }], "AppId" : 8, "AppType" : "Map", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.12.112", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.12.188", "Port" : 10000 }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.12.112", "Port" : 20001 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.12.188", "Port" : 10001 }], "AppId" : 2, "AppType" : "Realm", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.12.112", "Port" : 20002 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.12.188", "Port" : 10002 }], "AppId" : 3, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.12.112", "Port" : 20003 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.12.188", "Port" : 10003 }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.12.112", "Port" : 20004 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.12.188", "Port" : 10004 }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.12.112", "Port" : 20005 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.12.188", "Port" : 10005 }], "AppId" : 6, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.12.112", "Port" : 20000 }, { "_t" : "OuterConfig", "Host" : "192.168.12.188", "Port" : 10000, "Host2" : null }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.12.112", "Port" : 20001 }, { "_t" : "OuterConfig", "Host" : "192.168.12.188", "Port" : 10001, "Host2" : null }], "AppId" : 2, "AppType" : "Realm", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.12.112", "Port" : 20002 }, { "_t" : "OuterConfig", "Host" : "192.168.12.188", "Port" : 10002, "Host2" : null }], "AppId" : 3, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.12.112", "Port" : 20003 }, { "_t" : "OuterConfig", "Host" : "192.168.12.188", "Port" : 10003, "Host2" : null }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.12.112", "Port" : 20004 }, { "_t" : "OuterConfig", "Host" : "192.168.12.188", "Port" : 10004, "Host2" : null }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.12.112", "Port" : 20005 }, { "_t" : "OuterConfig", "Host" : "192.168.12.188", "Port" : 10005, "Host2" : null }], "AppId" : 6, "AppType" : "Gate", "ServerIP" : "192.168.12.112" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.9.182", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.9.182", "Port" : 10000 }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.9.182", "Port" : 20001 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.9.182", "Port" : 10001 }], "AppId" : 2, "AppType" : "Realm", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.9.182", "Port" : 20002 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.9.182", "Port" : 10002 }], "AppId" : 3, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.9.182", "Port" : 20003 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.9.182", "Port" : 10003 }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.9.182", "Port" : 20004 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.9.182", "Port" : 10004 }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832366182402"), "Host" : "192.168.9.182", "Port" : 20005 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832366182403"), "Host" : "192.168.9.182", "Port" : 10005 }], "AppId" : 6, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.9.182", "Port" : 20000 }, { "_t" : "OuterConfig", "Host" : "192.168.9.182", "Port" : 10000, "Host2" : null }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.9.182", "Port" : 20001 }, { "_t" : "OuterConfig", "Host" : "192.168.9.182", "Port" : 10001, "Host2" : null }], "AppId" : 2, "AppType" : "Realm", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.9.182", "Port" : 20002 }, { "_t" : "OuterConfig", "Host" : "192.168.9.182", "Port" : 10002, "Host2" : null }], "AppId" : 3, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.9.182", "Port" : 20003 }, { "_t" : "OuterConfig", "Host" : "192.168.9.182", "Port" : 10003, "Host2" : null }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.9.182", "Port" : 20004 }, { "_t" : "OuterConfig", "Host" : "192.168.9.182", "Port" : 10004, "Host2" : null }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("96832366182401"), "components" : [{ "_t" : "InnerConfig", "Host" : "192.168.9.182", "Port" : 20005 }, { "_t" : "OuterConfig", "Host" : "192.168.9.182", "Port" : 10005, "Host2" : null }], "AppId" : 6, "AppType" : "Gate", "ServerIP" : "192.168.9.182" }
{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "components" : [{ "_t" : "OuterConfig", "_id" : NumberLong("98547768819755"), "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }, { "_t" : "InnerConfig", "_id" : NumberLong("98547768819756"), "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "HttpConfig", "_id" : NumberLong("98547768819757"), "Url" : "", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "_id" : NumberLong("98547768819758"), "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "components" : [{ "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }, { "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "HttpConfig", "Url" : "", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
......@@ -6,13 +6,13 @@ namespace Model
[BsonKnownTypes(typeof(RechargeRecord))]
[BsonKnownTypes(typeof(Recharge))]
[BsonKnownTypes(typeof(Location))]
public class DBEntity: Entity
public class EntityDB: Entity
{
protected DBEntity()
protected EntityDB()
{
}
protected DBEntity(long id): base(id)
protected EntityDB(long id): base(id)
{
}
}
......
namespace Model
{
// 充值流水
public sealed class RechargeRecord : DBEntity
public sealed class RechargeRecord : EntityDB
{
// 充值玩家
public int PlayerNO { get; set; }
......@@ -18,7 +18,7 @@
}
// 保存玩家充值记录, 每个玩家只有一条
public sealed class Recharge : DBEntity
public sealed class Recharge : EntityDB
{
public int CardNumber { get; set; }
......
namespace Model
{
public class Location: DBEntity
public class Location: EntityDB
{
public string Address;
......
......@@ -178,7 +178,7 @@
<Compile Include="Entity\Config\StartConfig.cs" />
<Compile Include="Entity\ActorProxy.cs" />
<Compile Include="Entity\SceneEntity.cs" />
<Compile Include="Entity\DBEntity.cs" />
<Compile Include="Entity\EntityDB.cs" />
<Compile Include="Entity\DBTask.cs" />
<Compile Include="Entity\DBTaskQueue.cs" />
<Compile Include="Entity\Game.cs" />
......
......@@ -2,9 +2,14 @@
namespace Model
{
[BsonIgnoreExtraElements]
[BsonKnownTypes(typeof(AConfigComponent))]
public abstract class Component: Disposer
{
[BsonId]
[BsonIgnore]
public sealed override long Id { get; set; }
[BsonIgnore]
public Entity Entity { get; set; }
......@@ -15,12 +20,9 @@ namespace Model
protected Component()
{
this.Id = IdGenerater.GenerateId();
}
protected Component(long id): base(id)
{
}
public T GetComponent<T>() where T : Component
{
return this.Entity.GetComponent<T>();
......
using System;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public abstract class Disposer : Object, IDisposable
{
protected Disposer() : base(IdGenerater.GenerateId())
{
ObjectEvents.Instance.Add(this);
}
protected Disposer(long id) : base(id)
[BsonIgnore]
public abstract long Id { get; set; }
protected Disposer()
{
ObjectEvents.Instance.Add(this);
}
......@@ -18,13 +17,5 @@ namespace Model
{
this.Id = 0;
}
public override void BeginInit()
{
}
public override void EndInit()
{
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public class Entity : Disposer
[BsonIgnoreExtraElements]
public class Entity : Disposer, ISupportInitialize
{
[BsonId]
[BsonElement(Order = 1)]
public sealed override long Id { get; set; }
[BsonIgnore]
public Entity Parent { get; set; }
public EntityType Type { get; set; }
[BsonElement]
[BsonIgnoreIfNull]
private HashSet<Component> components = new HashSet<Component>();
......@@ -21,10 +25,12 @@ namespace Model
protected Entity()
{
this.Id = IdGenerater.GenerateId();
}
protected Entity(long id) : base(id)
protected Entity(long id)
{
this.Id = id;
}
public override void Dispose()
......@@ -186,17 +192,14 @@ namespace Model
return this.componentDict.Values.ToArray();
}
public override void BeginInit()
public virtual void BeginInit()
{
base.BeginInit();
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
}
public override void EndInit()
public virtual void EndInit()
{
base.EndInit();
ObjectEvents.Instance.Add(this);
if (this.components != null && this.components.Count == 0)
......
using System.ComponentModel;
namespace Model
namespace Model
{
public abstract class Object: ISupportInitialize
public abstract class Object
{
public long Id { get; set; }
protected Object()
{
Id = IdGenerater.GenerateId();
}
protected Object(long id)
{
this.Id = id;
}
public virtual void BeginInit()
{
}
public virtual void EndInit()
{
}
}
}
\ No newline at end of file
namespace Hotfix
using Model;
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
{
public abstract class Component: Disposer
public abstract class Component : Disposer
{
public Entity Owner { get; set; }
[BsonId]
[BsonIgnore]
public sealed override long Id { get; set; }
public T GetOwner<T>() where T : Entity
{
return this.Owner as T;
}
[BsonIgnore]
public Entity Entity { get; set; }
protected Component()
public T GetEntity<T>() where T : Entity
{
return this.Entity as T;
}
protected Component(long id): base(id)
protected Component()
{
this.Id = IdGenerater.GenerateId();
}
public T GetComponent<T>() where T : Component
{
return this.Owner.GetComponent<T>();
return this.Entity.GetComponent<T>();
}
public override void Dispose()
......@@ -31,7 +36,7 @@
base.Dispose();
this.Owner.RemoveComponent(this.GetType());
this.Entity?.RemoveComponent(this.GetType());
}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ namespace Hotfix
public static T Create<T>(Entity entity) where T : Component
{
T disposer = (T)Activator.CreateInstance(typeof(T));
disposer.Owner = entity;
disposer.Entity = entity;
ObjectEvents.Instance.Awake(disposer);
return disposer;
}
......@@ -15,7 +15,7 @@ namespace Hotfix
public static T Create<T, A>(Entity entity, A a) where T : Component
{
T disposer = (T)Activator.CreateInstance(typeof(T));
disposer.Owner = entity;
disposer.Entity = entity;
ObjectEvents.Instance.Awake(disposer, a);
return disposer;
}
......@@ -23,7 +23,7 @@ namespace Hotfix
public static T Create<T, A, B>(Entity entity, A a, B b) where T : Component
{
T disposer = (T)Activator.CreateInstance(typeof(T));
disposer.Owner = entity;
disposer.Entity = entity;
ObjectEvents.Instance.Awake(disposer, a, b);
return disposer;
}
......@@ -31,7 +31,7 @@ namespace Hotfix
public static T Create<T, A, B, C>(Entity entity, A a, B b, C c) where T : Component
{
T disposer = (T)Activator.CreateInstance(typeof(T));
disposer.Owner = entity;
disposer.Entity = entity;
ObjectEvents.Instance.Awake(disposer, a, b, c);
return disposer;
}
......
using Model;
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
{
public abstract class Disposer: Object
public abstract class Disposer : Object, IDisposable2
{
protected Disposer(): base(IdGenerater.GenerateId())
{
ObjectEvents.Instance.Add(this);
}
[BsonIgnore]
public abstract long Id { get; set; }
protected Disposer(long id): base(id)
protected Disposer()
{
ObjectEvents.Instance.Add(this);
}
public override void Dispose()
public virtual void Dispose()
{
this.Id = 0;
}
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Model;
using MongoDB.Bson.Serialization.Attributes;
namespace Hotfix
{
public class Entity : Disposer
[BsonIgnoreExtraElements]
public class Entity : Disposer, ISupportInitialize
{
[BsonId]
[BsonElement(Order = 1)]
public sealed override long Id { get; set; }
[BsonIgnore]
public Entity Parent { get; set; }
public EntityType Type { get; set; }
[BsonElement]
[BsonIgnoreIfNull]
private HashSet<Component> components = new HashSet<Component>();
......@@ -22,10 +26,12 @@ namespace Hotfix
protected Entity()
{
this.Id = IdGenerater.GenerateId();
}
protected Entity(long id) : base(id)
protected Entity(long id)
{
this.Id = id;
}
public override void Dispose()
......@@ -186,5 +192,29 @@ namespace Hotfix
{
return this.componentDict.Values.ToArray();
}
public virtual void BeginInit()
{
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
}
public virtual void EndInit()
{
ObjectEvents.Instance.Add(this);
if (this.components != null && this.components.Count == 0)
{
this.components = null;
}
if (this.components != null)
{
foreach (Component component in this.components)
{
component.Entity = this;
this.componentDict.Add(component.GetType(), component);
}
}
}
}
}
\ No newline at end of file
using Model;
namespace Hotfix
namespace Hotfix
{
public interface IDisposable2
{
void Dispose();
}
public abstract class Object: IDisposable2
public abstract class Object
{
public long Id { get; set; }
protected Object()
{
Id = IdGenerater.GenerateId();
}
protected Object(long id)
{
this.Id = id;
}
public virtual void Dispose()
{
}
}
}
\ No newline at end of file
......@@ -91,7 +91,7 @@ namespace Hotfix
{
try
{
UI ui = UiTypes[type].Create(GetOwner<Scene>(), type, Root);
UI ui = UiTypes[type].Create(this.GetEntity<Scene>(), type, Root);
uis.Add(type, ui);
// 设置canvas
......
......@@ -21,7 +21,7 @@ namespace Hotfix
public void Awake()
{
ReferenceCollector rc = this.GetOwner<UI>().GameObject.GetComponent<ReferenceCollector>();
ReferenceCollector rc = this.GetEntity<UI>().GameObject.GetComponent<ReferenceCollector>();
loginBtn = rc.Get<GameObject>("LoginBtn");
loginBtn.GetComponent<Button>().onClick.Add(OnLogin);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册