From d668c194aba14e69941b8eed3eec8eb0ecb011bb Mon Sep 17 00:00:00 2001 From: tanghai Date: Tue, 27 Sep 2016 18:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=AE=BE=E8=AE=A1=E4=BA=86En?= =?UTF-8?q?tity=E7=9A=84=E5=B1=82=E6=AC=A1=E5=85=B3=E7=B3=BBapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Unity/Assets/Res/Code/Controller.dll.bytes | Bin 7168 -> 0 bytes .../Assets/Res/Code/Controller.dll.bytes.meta | 4 - .../Assets/Res/Code/Controller.dll.mdb.bytes | Bin 613 -> 0 bytes .../Res/Code/Controller.dll.mdb.bytes.meta | 8 -- Unity/Assets/Scripts/Base/Object/Entity.cs | 80 ++++++++++++- Unity/Assets/Scripts/Base/Object/Object.cs | 108 ++---------------- Unity/Assets/Scripts/Component/Scene.cs | 79 +------------ Unity/Assets/Scripts/Other/Env.cs | 87 +++++++++++++- 8 files changed, 173 insertions(+), 193 deletions(-) delete mode 100644 Unity/Assets/Res/Code/Controller.dll.bytes delete mode 100644 Unity/Assets/Res/Code/Controller.dll.bytes.meta delete mode 100644 Unity/Assets/Res/Code/Controller.dll.mdb.bytes delete mode 100644 Unity/Assets/Res/Code/Controller.dll.mdb.bytes.meta diff --git a/Unity/Assets/Res/Code/Controller.dll.bytes b/Unity/Assets/Res/Code/Controller.dll.bytes deleted file mode 100644 index b9ac54f4c2f4cf717ae53a5a4ed3af2fff107ebb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7168 zcmeHL3v64}8UD}pBdOcEvC|ajBQ<@1Xor?8&DNZo5Zwf(uA}PiFV(A?8Hu! zAx%QlCUNZhpZ|6K|3CkE-E;f*eSsWA{u~h;9XPrjat$Odz3VvxXgrYXLK#4d~fG*Y;>2V1VW})=K z?si7niJs&{Tv!eeEdXzEJ<;+DWgkWdh$_qEm7uql(IHzKwL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zZn)0SM|qFZc~8gBg`Z<^q__{BBhm lweofi$WSAG^7ADp>7y)|(EN?`!5Mq@~ezMl?N}i3>wd#-@c8 zGn2-!IcY5zp|ojb(y5fl7=t34jU|Nk5sfAQ_%IS<>aB?DAn00~_C)Vx8`fkO;OPRKp&mSGYo2Y`) zHK=QV&y~6AMn|;`KLEeM3v~kwU@sy?wS`D^kOQ;;#O2MGNT7uP1*wm^@U<7C4%(Eh zlpy6GFHjHE6l`&lDj9#_^vd7Ry+Y&^C^`f> components = new HashSet>(); - private Dictionary> componentDict = new Dictionary>(); + [BsonIgnore] + public T Parent { get; set; } + public string Name { get; } + + [BsonElement, BsonIgnoreIfNull] + private Dictionary idChildren; + + [BsonElement, BsonIgnoreIfNull] + private Dictionary nameChildren; + protected Entity() { + this.Name = ""; ObjectManager.Add(this); } - protected Entity(long id): base(id) + protected Entity(string name) { + this.Name = name; + ObjectManager.Add(this); + } + + protected Entity(long id, string name): base(id) + { + this.Name = name; ObjectManager.Add(this); } @@ -28,6 +45,59 @@ namespace Base return MongoHelper.FromBson(MongoHelper.ToBson(this)); } + + public int Count + { + get + { + return this.idChildren.Count; + } + } + + public void Add(T t) + { + t.Parent = (T)this; + if (this.idChildren == null) + { + this.idChildren = new Dictionary(); + this.nameChildren = new Dictionary(); + } + this.idChildren.Add(t.Id, t); + this.nameChildren.Add(t.Name, t); + } + + private void Remove(T t) + { + this.idChildren.Remove(t.Id); + this.nameChildren.Remove(t.Name); + if (this.idChildren.Count == 0) + { + this.idChildren = null; + this.nameChildren = null; + } + t.Dispose(); + } + + public void Remove(long id) + { + T t; + if (!this.idChildren.TryGetValue(id, out t)) + { + return; + } + this.Remove(t); + } + + public void Remove(string name) + { + T t; + if (!this.nameChildren.TryGetValue(name, out t)) + { + return; + } + this.Remove(t); + } + public override void Dispose() { if (this.Id == 0) @@ -37,6 +107,11 @@ namespace Base base.Dispose(); + foreach (T t in this.idChildren.Values.ToArray()) + { + t.Dispose(); + } + foreach (Component component in this.GetComponents()) { try @@ -48,6 +123,7 @@ namespace Base Log.Error(e.ToString()); } } + this.Parent?.Remove(this.Id); ObjectManager.Remove(this.Id); } diff --git a/Unity/Assets/Scripts/Base/Object/Object.cs b/Unity/Assets/Scripts/Base/Object/Object.cs index acfbdf04..7d1fb7c5 100644 --- a/Unity/Assets/Scripts/Base/Object/Object.cs +++ b/Unity/Assets/Scripts/Base/Object/Object.cs @@ -1,29 +1,16 @@ using System; -using System.Collections; -using System.Collections.Generic; using System.ComponentModel; using MongoDB.Bson.Serialization.Attributes; namespace Base { - public abstract class Object: ISupportInitialize, IDisposable, IEnumerable + public abstract class Object: IDisposable, ISupportInitialize { public static ObjectManager ObjectManager = new ObjectManager(); [BsonId] public long Id { get; private set; } - public Dictionary Values - { - get - { - return values; - } - } - - [BsonElement, BsonIgnoreIfNull] - private Dictionary values = new Dictionary(); - protected Object() { Id = IdGenerater.GenerateId(); @@ -34,106 +21,27 @@ namespace Base this.Id = id; } - public virtual void BeginInit() - { - if (this.values == null) - { - this.values = new Dictionary(); - } - } - - public virtual void EndInit() - { - if (this.values.Count == 0) - { - this.values = null; - } - } - - public object this[string key] - { - get - { - return this.values[key]; - } - set - { - if (this.values == null) - { - this.values = new Dictionary(); - } - this.values[key] = value; - } - } - - public T Get(string key) - { - if (this.values == null || !this.values.ContainsKey(key)) - { - return default(T); - } - object value = values[key]; - return (T)value; - } - - public void Set(string key, object obj) - { - if (this.values == null) - { - this.values = new Dictionary(); - } - this.values[key] = obj; - } - - public bool ContainKey(string key) + public bool IsDisposed() { - if (this.values == null) - { - return false; - } - return this.values.ContainsKey(key); + return this.Id == 0; } - public void Remove(string key) + public virtual void Dispose() { - if (this.values == null) + if (this.Id == 0) { return; } - this.values.Remove(key); - if (this.values.Count == 0) - { - this.values = null; - } - } - - public void Add(string key, object value) - { - if (this.values == null) - { - this.values = new Dictionary(); - } - this.values[key] = value; - } - public IEnumerator GetEnumerator() - { - return this.values.GetEnumerator(); + this.Id = 0; } - public bool IsDisposed() + public virtual void BeginInit() { - return this.Id == 0; } - public virtual void Dispose() + public virtual void EndInit() { - if (this.Id == 0) - { - return; - } - - this.Id = 0; } } } \ No newline at end of file diff --git a/Unity/Assets/Scripts/Component/Scene.cs b/Unity/Assets/Scripts/Component/Scene.cs index 3594a8cc..840cff4e 100644 --- a/Unity/Assets/Scripts/Component/Scene.cs +++ b/Unity/Assets/Scripts/Component/Scene.cs @@ -18,88 +18,13 @@ namespace Base public sealed class Scene: Entity { - public Scene Parent { get; set; } - - public string Name { get; set; } - public SceneType SceneType { get; } - private readonly Dictionary Children = new Dictionary(); - - private readonly Dictionary> SceneTypeChildren = new Dictionary>(); - - public Scene(string name, SceneType sceneType) + public Scene(string name, SceneType sceneType): base(name) { - this.Name = name; this.SceneType = sceneType; } - public int Count - { - get - { - return this.Children.Count; - } - } - - public void Add(Scene scene) - { - scene.Parent = this; - this.Children.Add(scene.Id, scene); - HashSet listScene; - if (!this.SceneTypeChildren.TryGetValue(scene.SceneType, out listScene)) - { - listScene = new HashSet(); - this.SceneTypeChildren.Add(scene.SceneType, listScene); - } - listScene.Add(scene); - } - - public Scene Get(SceneType sceneType) - { - HashSet scenes; - if (!this.SceneTypeChildren.TryGetValue(sceneType, out scenes)) - { - return null; - } - if (scenes.Count == 0) - { - return null; - } - return scenes.First(); - } - - public void Remove(SceneType sceneType) - { - HashSet scenes; - if (!this.SceneTypeChildren.TryGetValue(sceneType, out scenes)) - { - return; - } - foreach (Scene scene in scenes) - { - Children.Remove(scene.Id); - scene.Dispose(); - } - this.SceneTypeChildren.Remove(sceneType); - } - - public void Remove(long id) - { - Scene scene; - if (!this.Children.TryGetValue(id, out scene)) - { - return; - } - HashSet scenes; - if (!this.SceneTypeChildren.TryGetValue(scene.SceneType, out scenes)) - { - return; - } - scenes.Remove(scene); - scene.Dispose(); - } - public override void Dispose() { if (this.Id == 0) @@ -108,8 +33,6 @@ namespace Base } base.Dispose(); - - this.Parent?.Remove(this.Id); } } } \ No newline at end of file diff --git a/Unity/Assets/Scripts/Other/Env.cs b/Unity/Assets/Scripts/Other/Env.cs index 279eacaa..6829ad43 100644 --- a/Unity/Assets/Scripts/Other/Env.cs +++ b/Unity/Assets/Scripts/Other/Env.cs @@ -1,6 +1,91 @@ -namespace Base +using System; +using System.Collections; +using System.Collections.Generic; +using MongoDB.Bson.Serialization.Attributes; + +namespace Base { public class Env: Object { + [BsonElement, BsonIgnoreIfNull] + private Dictionary values = new Dictionary(); + + public object this[string key] + { + get + { + return this.values[key]; + } + set + { + if (this.values == null) + { + this.values = new Dictionary(); + } + this.values[key] = value; + } + } + + public T Get(string key) + { + if (this.values == null || !this.values.ContainsKey(key)) + { + return default(T); + } + object value = values[key]; + try + { + return (T)value; + } + catch (InvalidCastException e) + { + throw new GameException($"不能把{value.GetType()}转换为{typeof(T)}", e); + } + } + + public void Set(string key, object obj) + { + if (this.values == null) + { + this.values = new Dictionary(); + } + this.values[key] = obj; + } + + public bool ContainKey(string key) + { + if (this.values == null) + { + return false; + } + return this.values.ContainsKey(key); + } + + public void Remove(string key) + { + if (this.values == null) + { + return; + } + this.values.Remove(key); + if (this.values.Count == 0) + { + this.values = null; + } + } + + public void Add(string key, object value) + { + if (this.values == null) + { + this.values = new Dictionary(); + } + this.values[key] = value; + } + + public IEnumerator GetEnumerator() + { + return this.values.GetEnumerator(); + } } } \ No newline at end of file -- GitLab