| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using ETModel;
- using MongoDB.Bson.Serialization.Attributes;
- namespace ETHotfix
- {
- [BsonIgnoreExtraElements]
- public abstract partial class Component : Object, IDisposable2
- {
- [BsonIgnore]
- public long InstanceId { get; private set; }
- [BsonIgnore]
- private bool isFromPool;
- [BsonIgnore]
- public bool IsFromPool
- {
- get
- {
- return this.isFromPool;
- }
- set
- {
- this.isFromPool = value;
- if (this.InstanceId == 0)
- {
- this.InstanceId = IdGenerater.GenerateId();
- Game.EventSystem.Add(this);
- }
- }
- }
- [BsonIgnore]
- public bool IsDisposed
- {
- get
- {
- return this.InstanceId == 0;
- }
- }
- [BsonIgnoreIfDefault]
- [BsonDefaultValue(0L)]
- [BsonElement]
- [BsonId]
- public long Id { get; set; }
- [BsonIgnore]
- public Component Parent { get; set; }
- public T GetParent<T>() where T : Component
- {
- return this.Parent as T;
- }
- [BsonIgnore]
- public Entity Entity
- {
- get
- {
- return this.Parent as Entity;
- }
- }
- protected Component()
- {
- this.InstanceId = IdGenerater.GenerateId();
- Game.EventSystem.Add(this);
- }
- protected Component(long instanceId)
- {
- this.InstanceId = instanceId;
- Game.EventSystem.Add(this);
- }
- public virtual void Dispose()
- {
- if (this.IsDisposed)
- {
- return;
- }
-
- Game.EventSystem.Remove(this.InstanceId);
- this.InstanceId = 0;
- if (this.IsFromPool)
- {
- Game.ObjectPool.Recycle(this);
- }
- }
- }
- }
|