Просмотр исходного кода

mono层和hotfix层分别创建一份Entity系统,只使用命名空间区分,可以随时将Entity和Component放在任何一层上面

tanghai 8 лет назад
Родитель
Сommit
4968032a64
100 измененных файлов с 1182 добавлено и 50 удалено
  1. 9 0
      Unity/Assets/Scripts/Component.meta
  2. 9 0
      Unity/Assets/Scripts/Component/Config.meta
  3. 1 1
      Unity/Assets/Scripts/Component/Config/ClientConfig.cs
  4. 12 0
      Unity/Assets/Scripts/Component/Config/ClientConfig.cs.meta
  5. 1 1
      Unity/Assets/Scripts/Component/Config/InnerConfig.cs
  6. 12 0
      Unity/Assets/Scripts/Component/Config/InnerConfig.cs.meta
  7. 1 1
      Unity/Assets/Scripts/Component/Config/OuterConfig.cs
  8. 12 0
      Unity/Assets/Scripts/Component/Config/OuterConfig.cs.meta
  9. 1 1
      Unity/Assets/Scripts/Component/Config/RunServerConfig.cs
  10. 12 0
      Unity/Assets/Scripts/Component/Config/RunServerConfig.cs.meta
  11. 126 0
      Unity/Assets/Scripts/Component/EventComponent.cs
  12. 12 0
      Unity/Assets/Scripts/Component/EventComponent.cs.meta
  13. 3 4
      Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
  14. 12 0
      Unity/Assets/Scripts/Component/MessageDispatherComponent.cs.meta
  15. 1 2
      Unity/Assets/Scripts/Component/NetInnerComponent.cs
  16. 12 0
      Unity/Assets/Scripts/Component/NetInnerComponent.cs.meta
  17. 1 3
      Unity/Assets/Scripts/Component/NetOuterComponent.cs
  18. 12 0
      Unity/Assets/Scripts/Component/NetOuterComponent.cs.meta
  19. 2 3
      Unity/Assets/Scripts/Component/NetworkComponent.cs
  20. 12 0
      Unity/Assets/Scripts/Component/NetworkComponent.cs.meta
  21. 105 0
      Unity/Assets/Scripts/Component/TimerComponent.cs
  22. 12 0
      Unity/Assets/Scripts/Component/TimerComponent.cs.meta
  23. 9 0
      Unity/Assets/Scripts/Config.meta
  24. 1 1
      Unity/Assets/Scripts/Config/ACategory.cs
  25. 0 0
      Unity/Assets/Scripts/Config/ACategory.cs.meta
  26. 2 2
      Unity/Assets/Scripts/Config/AConfig.cs
  27. 0 0
      Unity/Assets/Scripts/Config/AConfig.cs.meta
  28. 2 2
      Unity/Assets/Scripts/Config/AConfigComponent.cs
  29. 0 0
      Unity/Assets/Scripts/Config/AConfigComponent.cs.meta
  30. 1 1
      Unity/Assets/Scripts/Config/ConfigAttribute.cs
  31. 0 0
      Unity/Assets/Scripts/Config/ConfigAttribute.cs.meta
  32. 1 1
      Unity/Assets/Scripts/Config/ConfigHelper.cs
  33. 0 0
      Unity/Assets/Scripts/Config/ConfigHelper.cs.meta
  34. 1 1
      Unity/Assets/Scripts/Config/ICategory.cs
  35. 0 0
      Unity/Assets/Scripts/Config/ICategory.cs.meta
  36. 1 1
      Unity/Assets/Scripts/DllHelper.cs
  37. 12 0
      Unity/Assets/Scripts/DllHelper.cs.meta
  38. 9 0
      Unity/Assets/Scripts/Entity.meta
  39. 2 2
      Unity/Assets/Scripts/Entity/AssetBundleLoaderAsync.cs
  40. 12 0
      Unity/Assets/Scripts/Entity/AssetBundleLoaderAsync.cs.meta
  41. 9 0
      Unity/Assets/Scripts/Entity/Config.meta
  42. 1 1
      Unity/Assets/Scripts/Entity/Config/BuffConfig.cs
  43. 12 0
      Unity/Assets/Scripts/Entity/Config/BuffConfig.cs.meta
  44. 1 1
      Unity/Assets/Scripts/Entity/Config/StartConfig.cs
  45. 12 0
      Unity/Assets/Scripts/Entity/Config/StartConfig.cs.meta
  46. 28 0
      Unity/Assets/Scripts/Entity/Game.cs
  47. 12 0
      Unity/Assets/Scripts/Entity/Game.cs.meta
  48. 44 0
      Unity/Assets/Scripts/Entity/Scene.cs
  49. 12 0
      Unity/Assets/Scripts/Entity/Scene.cs.meta
  50. 2 3
      Unity/Assets/Scripts/Entity/Session.cs
  51. 12 0
      Unity/Assets/Scripts/Entity/Session.cs.meta
  52. 2 2
      Unity/Assets/Scripts/Entity/WWWAsync.cs
  53. 12 0
      Unity/Assets/Scripts/Entity/WWWAsync.cs.meta
  54. 9 0
      Unity/Assets/Scripts/Event.meta
  55. 15 0
      Unity/Assets/Scripts/Event/AEventAttribute.cs
  56. 12 0
      Unity/Assets/Scripts/Event/AEventAttribute.cs.meta
  57. 91 0
      Unity/Assets/Scripts/Event/Env.cs
  58. 12 0
      Unity/Assets/Scripts/Event/Env.cs.meta
  59. 10 0
      Unity/Assets/Scripts/Event/EnvKey.cs
  60. 12 0
      Unity/Assets/Scripts/Event/EnvKey.cs.meta
  61. 9 0
      Unity/Assets/Scripts/Event/EventAttribute.cs
  62. 12 0
      Unity/Assets/Scripts/Event/EventAttribute.cs.meta
  63. 18 0
      Unity/Assets/Scripts/Event/EventIdType.cs
  64. 12 0
      Unity/Assets/Scripts/Event/EventIdType.cs.meta
  65. 37 0
      Unity/Assets/Scripts/Event/IEvent.cs
  66. 12 0
      Unity/Assets/Scripts/Event/IEvent.cs.meta
  67. 1 1
      Unity/Assets/Scripts/Helper/GameObjectHelper.cs
  68. 12 0
      Unity/Assets/Scripts/Helper/GameObjectHelper.cs.meta
  69. 1 3
      Unity/Assets/Scripts/Helper/JsonHelper.cs
  70. 12 0
      Unity/Assets/Scripts/Helper/JsonHelper.cs.meta
  71. 1 1
      Unity/Assets/Scripts/Helper/ResourceHelper.cs
  72. 1 1
      Unity/Assets/Scripts/IL/ILBindingAttribute.cs
  73. 2 0
      Unity/Assets/Scripts/Init.cs
  74. 9 0
      Unity/Assets/Scripts/Message.meta
  75. 1 1
      Unity/Assets/Scripts/Message/AMHandler.cs
  76. 0 0
      Unity/Assets/Scripts/Message/AMHandler.cs.meta
  77. 1 1
      Unity/Assets/Scripts/Message/AMessage.cs
  78. 0 0
      Unity/Assets/Scripts/Message/AMessage.cs.meta
  79. 1 1
      Unity/Assets/Scripts/Message/AppType.cs
  80. 0 0
      Unity/Assets/Scripts/Message/AppType.cs.meta
  81. 1 1
      Unity/Assets/Scripts/Message/ErrorCode.cs
  82. 0 0
      Unity/Assets/Scripts/Message/ErrorCode.cs.meta
  83. 1 1
      Unity/Assets/Scripts/Message/IMHandler.cs
  84. 0 0
      Unity/Assets/Scripts/Message/IMHandler.cs.meta
  85. 1 1
      Unity/Assets/Scripts/Message/MessageAttribute.cs
  86. 0 0
      Unity/Assets/Scripts/Message/MessageAttribute.cs.meta
  87. 1 1
      Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs
  88. 0 0
      Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs.meta
  89. 1 1
      Unity/Assets/Scripts/Message/MessageInfo.cs
  90. 0 0
      Unity/Assets/Scripts/Message/MessageInfo.cs.meta
  91. 1 1
      Unity/Assets/Scripts/Message/OpcodeHelper.cs
  92. 0 0
      Unity/Assets/Scripts/Message/OpcodeHelper.cs.meta
  93. 1 1
      Unity/Assets/Scripts/Message/RpcException.cs
  94. 0 0
      Unity/Assets/Scripts/Message/RpcException.cs.meta
  95. 9 0
      Unity/Assets/Scripts/Object.meta
  96. 40 0
      Unity/Assets/Scripts/Object/Component.cs
  97. 12 0
      Unity/Assets/Scripts/Object/Component.cs.meta
  98. 21 0
      Unity/Assets/Scripts/Object/Disposer.cs
  99. 12 0
      Unity/Assets/Scripts/Object/Disposer.cs.meta
  100. 186 0
      Unity/Assets/Scripts/Object/Entity.cs

+ 9 - 0
Unity/Assets/Scripts/Component.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 2a558a9c1a99ead44867c6b71472566f
+folderAsset: yes
+timeCreated: 1498117616
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Component/Config.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: e98bd4118f88e1c428e3af0983722aa8
+folderAsset: yes
+timeCreated: 1498118075
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Component/Config/ClientConfig.cs → Unity/Assets/Scripts/Component/Config/ClientConfig.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	[BsonIgnoreExtraElements]
 	public class ClientConfig: AConfigComponent

+ 12 - 0
Unity/Assets/Scripts/Component/Config/ClientConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: befeb8cfbdbfc5b4ea5f967c200d4751
+timeCreated: 1498118076
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Component/Config/InnerConfig.cs → Unity/Assets/Scripts/Component/Config/InnerConfig.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	[BsonIgnoreExtraElements]
 	public class InnerConfig: AConfigComponent

+ 12 - 0
Unity/Assets/Scripts/Component/Config/InnerConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 35f166fd86ee5e44aaec9326bb0a5454
+timeCreated: 1498118076
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Component/Config/OuterConfig.cs → Unity/Assets/Scripts/Component/Config/OuterConfig.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	[BsonIgnoreExtraElements]
 	public class OuterConfig: AConfigComponent

+ 12 - 0
Unity/Assets/Scripts/Component/Config/OuterConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 31224cfdac2f28c42bd641d5a2e80fe8
+timeCreated: 1498118075
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Component/Config/RunServerConfig.cs → Unity/Assets/Scripts/Component/Config/RunServerConfig.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	[BsonIgnoreExtraElements]
 	public class RunServerConfig: AConfigComponent

+ 12 - 0
Unity/Assets/Scripts/Component/Config/RunServerConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: bceb49362f439a248b806059721da628
+timeCreated: 1498118076
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 126 - 0
Unity/Assets/Scripts/Component/EventComponent.cs

@@ -0,0 +1,126 @@
+using System;
+using System.Collections.Generic;
+using Model;
+
+namespace Model
+{
+	[EntityEvent(EntityEventId.EventComponent)]
+	public class EventComponent : Component, IAwake
+	{
+		private Dictionary<int, List<object>> allEvents;
+
+		public void Awake()
+		{
+			this.Load();
+		}
+
+		public void Load()
+		{
+			this.allEvents = new Dictionary<int, List<object>>();
+
+			Type[] types = DllHelper.GetAllTypes();
+			foreach (Type type in types)
+			{
+				object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
+
+				foreach (object attr in attrs)
+				{
+					EventAttribute aEventAttribute = (EventAttribute)attr;
+					object obj = Activator.CreateInstance(type);
+					if (!this.allEvents.ContainsKey(aEventAttribute.Type))
+					{
+						this.allEvents.Add(aEventAttribute.Type, new List<object>());
+					}
+					this.allEvents[aEventAttribute.Type].Add(obj);
+				}
+			}
+		}
+
+		public void Run(int type)
+		{
+			List<object> iEvents = null;
+			if (!this.allEvents.TryGetValue(type, out iEvents))
+			{
+				return;
+			}
+			foreach (object obj in iEvents)
+			{
+				try
+				{
+					IEvent iEvent = (IEvent)obj;
+					iEvent.Run();
+				}
+				catch (Exception e)
+				{
+					Log.Error(e.ToString());
+				}
+			}
+		}
+
+		public void Run<A>(int type, A a)
+		{
+			List<object> iEvents = null;
+			if (!this.allEvents.TryGetValue(type, out iEvents))
+			{
+				return;
+			}
+
+			foreach (object obj in iEvents)
+			{
+				try
+				{
+					IEvent<A> iEvent = (IEvent<A>)obj;
+					iEvent.Run(a);
+				}
+				catch (Exception err)
+				{
+					Log.Error(err.ToString());
+				}
+			}
+		}
+
+		public void Run<A, B>(int type, A a, B b)
+		{
+			List<object> iEvents = null;
+			if (!this.allEvents.TryGetValue(type, out iEvents))
+			{
+				return;
+			}
+
+			foreach (object obj in iEvents)
+			{
+				try
+				{
+					IEvent<A, B> iEvent = (IEvent<A, B>)obj;
+					iEvent.Run(a, b);
+				}
+				catch (Exception err)
+				{
+					Log.Error(err.ToString());
+				}
+			}
+		}
+
+		public void Run<A, B, C>(int type, A a, B b, C c)
+		{
+			List<object> iEvents = null;
+			if (!this.allEvents.TryGetValue(type, out iEvents))
+			{
+				return;
+			}
+
+			foreach (object obj in iEvents)
+			{
+				try
+				{
+					IEvent<A, B, C> iEvent = (IEvent<A, B, C>)obj;
+					iEvent.Run(a, b, c);
+				}
+				catch (Exception err)
+				{
+					Log.Error(err.ToString());
+				}
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Component/EventComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: fdeabd62f7ad9414fa74891de319729f
+timeCreated: 1498117617
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 3 - 4
Unity/Hotfix/Component/MessageDispatherComponent.cs → Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -1,14 +1,13 @@
 using System;
 using System.Collections.Generic;
-using Model;
 
-namespace Hotfix
+namespace Model
 {
 	/// <summary>
 	/// 消息分发组件
 	/// </summary>
-	[EntityEvent(EntityEventId.MessageDispatherComponent)]
-	public class MessageDispatherComponent: HotfixComponent, IAwake<AppType>, ILoad
+	[ObjectEvent(EntityEventId.MessageDispatherComponent)]
+	public class MessageDispatherComponent: Component, IAwake<AppType>, ILoad
 	{
 		private AppType AppType;
 		private Dictionary<ushort, List<IInstanceMethod>> handlers;

+ 12 - 0
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 8e97599ee372f6f40aaa5e743851a74c
+timeCreated: 1498117781
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 2
Unity/Hotfix/Component/NetInnerComponent.cs → Unity/Assets/Scripts/Component/NetInnerComponent.cs

@@ -1,7 +1,6 @@
 using System.Collections.Generic;
-using Model;
 
-namespace Hotfix
+namespace Model
 {
 	[EntityEvent(EntityEventId.NetInnerComponent)]
 	public class NetInnerComponent: NetworkComponent

+ 12 - 0
Unity/Assets/Scripts/Component/NetInnerComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1ab11b2f08956d1499373e40ab1eba6b
+timeCreated: 1498117616
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 3
Unity/Hotfix/Component/NetOuterComponent.cs → Unity/Assets/Scripts/Component/NetOuterComponent.cs

@@ -1,6 +1,4 @@
-using Model;
-
-namespace Hotfix
+namespace Model
 {
 	[EntityEvent(EntityEventId.NetOuterComponent)]
 	public class NetOuterComponent: NetworkComponent, IAwake, IAwake<string, int>, IUpdate

+ 12 - 0
Unity/Assets/Scripts/Component/NetOuterComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2540893057b627148a6fe09470765227
+timeCreated: 1498117616
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 3
Unity/Hotfix/Component/NetworkComponent.cs → Unity/Assets/Scripts/Component/NetworkComponent.cs

@@ -2,11 +2,10 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
-using Model;
 
-namespace Hotfix
+namespace Model
 {
-	public abstract class NetworkComponent: HotfixComponent
+	public abstract class NetworkComponent: Component
 	{
 		private AService Service;
 

+ 12 - 0
Unity/Assets/Scripts/Component/NetworkComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 151d2db7aab5bc8438bc039443ba0e3b
+timeCreated: 1498117616
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 105 - 0
Unity/Assets/Scripts/Component/TimerComponent.cs

@@ -0,0 +1,105 @@
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Model;
+
+namespace Model
+{
+	public class Timer
+	{
+		public long Id { get; set; }
+		public long Time { get; set; }
+		public TaskCompletionSource<bool> tcs;
+	}
+
+	[EntityEvent(EntityEventId.TimerComponent)]
+	public class TimerComponent: Component, IUpdate
+	{
+		private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
+
+		/// <summary>
+		/// key: time, value: timer id
+		/// </summary>
+		private readonly MultiMap<long, long> timeId = new MultiMap<long, long>();
+
+		private readonly Queue<long> timeoutTimer = new Queue<long>();
+
+		public void Update()
+		{
+			long timeNow = TimeHelper.Now();
+			foreach (long time in this.timeId.Keys)
+			{
+				if (time > timeNow)
+				{
+					break;
+				}
+				this.timeoutTimer.Enqueue(time);
+			}
+
+			while (this.timeoutTimer.Count > 0)
+			{
+				long key = this.timeoutTimer.Dequeue();
+				long[] timeOutId = this.timeId.GetAll(key);
+				foreach (long id in timeOutId)
+				{
+					Timer timer;
+					if (!this.timers.TryGetValue(id, out timer))
+					{
+						continue;
+					}
+					this.Remove(id);
+					timer.tcs.SetResult(true);
+				}
+			}
+		}
+
+		private void Remove(long id)
+		{
+			Timer timer;
+			if (!this.timers.TryGetValue(id, out timer))
+			{
+				return;
+			}
+			this.timers.Remove(id);
+			this.timeId.Remove(timer.Time, timer.Id);
+		}
+
+		public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
+		{
+			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
+			this.timers[timer.Id] = timer;
+			this.timeId.Add(timer.Time, timer.Id);
+			cancellationToken.Register(() => { this.Remove(timer.Id); });
+			return tcs.Task;
+		}
+
+		public Task WaitTillAsync(long tillTime)
+		{
+			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
+			this.timers[timer.Id] = timer;
+			this.timeId.Add(timer.Time, timer.Id);
+			return tcs.Task;
+		}
+
+		public Task WaitAsync(long time, CancellationToken cancellationToken)
+		{
+			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs };
+			this.timers[timer.Id] = timer;
+			this.timeId.Add(timer.Time, timer.Id);
+			cancellationToken.Register(() => { this.Remove(timer.Id); });
+			return tcs.Task;
+		}
+
+		public Task WaitAsync(long time)
+		{
+			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs };
+			this.timers[timer.Id] = timer;
+			this.timeId.Add(timer.Time, timer.Id);
+			return tcs.Task;
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Component/TimerComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2f4a73ac996f1404aa1866a86140fe38
+timeCreated: 1498117617
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Config.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: d574f09c5596d2440b51164c43606464
+folderAsset: yes
+timeCreated: 1498118203
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Config/ACategory.cs → Unity/Assets/Scripts/Config/ACategory.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 
-namespace Hotfix
+namespace Model
 {
 	/// <summary>
 	/// 管理该所有的配置

+ 0 - 0
Unity/Hotfix/Config/ACategory.cs.meta → Unity/Assets/Scripts/Config/ACategory.cs.meta


+ 2 - 2
Unity/Hotfix/Config/AConfig.cs → Unity/Assets/Scripts/Config/AConfig.cs

@@ -1,9 +1,9 @@
-namespace Hotfix
+namespace Model
 {
 	/// <summary>
 	/// 每个Config的基类
 	/// </summary>
-	public abstract class AConfig: HotfixEntity
+	public abstract class AConfig: Entity
 	{
 		protected AConfig(EntityType entityType): base(entityType)
 		{

+ 0 - 0
Unity/Hotfix/Config/AConfig.cs.meta → Unity/Assets/Scripts/Config/AConfig.cs.meta


+ 2 - 2
Unity/Hotfix/Config/AConfigComponent.cs → Unity/Assets/Scripts/Config/AConfigComponent.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	/// <summary>
 	/// 每个Config的基类
@@ -8,7 +8,7 @@ namespace Hotfix
 	[BsonKnownTypes(typeof (ClientConfig))]
 	[BsonKnownTypes(typeof (InnerConfig))]
 	[BsonKnownTypes(typeof (OuterConfig))]
-	public abstract class AConfigComponent: HotfixComponent
+	public abstract class AConfigComponent: Component
 	{
 	}
 }

+ 0 - 0
Unity/Hotfix/Config/AConfigComponent.cs.meta → Unity/Assets/Scripts/Config/AConfigComponent.cs.meta


+ 1 - 1
Unity/Hotfix/Config/ConfigAttribute.cs → Unity/Assets/Scripts/Config/ConfigAttribute.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Hotfix
+namespace Model
 {
 	[AttributeUsage(AttributeTargets.Class)]
 	public class ConfigAttribute: Attribute

+ 0 - 0
Unity/Hotfix/Config/ConfigAttribute.cs.meta → Unity/Assets/Scripts/Config/ConfigAttribute.cs.meta


+ 1 - 1
Unity/Hotfix/Config/ConfigHelper.cs → Unity/Assets/Scripts/Config/ConfigHelper.cs

@@ -2,7 +2,7 @@
 using Model;
 using UnityEngine;
 
-namespace Hotfix
+namespace Model
 {
 	public static class ConfigHelper
 	{

+ 0 - 0
Unity/Hotfix/Config/ConfigHelper.cs.meta → Unity/Assets/Scripts/Config/ConfigHelper.cs.meta


+ 1 - 1
Unity/Hotfix/Config/ICategory.cs → Unity/Assets/Scripts/Config/ICategory.cs

@@ -1,7 +1,7 @@
 using System;
 using System.ComponentModel;
 
-namespace Hotfix
+namespace Model
 {
 	public interface ICategory: ISupportInitialize
 	{

+ 0 - 0
Unity/Hotfix/Config/ICategory.cs.meta → Unity/Assets/Scripts/Config/ICategory.cs.meta


+ 1 - 1
Unity/Hotfix/DllHelper.cs → Unity/Assets/Scripts/DllHelper.cs

@@ -7,7 +7,7 @@ using ILRuntime.CLR.TypeSystem;
 using Model;
 using UnityEngine;
 
-namespace Hotfix
+namespace Model
 {
 	public static class DllHelper
 	{

+ 12 - 0
Unity/Assets/Scripts/DllHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 20fbd2b0398f14a4d89abd01726d5d25
+timeCreated: 1498118075
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Entity.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: d2b1f66f808fc9a4ba043d89e5d982f9
+folderAsset: yes
+timeCreated: 1498117616
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Unity/Hotfix/Entity/AssetBundleLoaderAsync.cs → Unity/Assets/Scripts/Entity/AssetBundleLoaderAsync.cs

@@ -1,9 +1,9 @@
 using System.Threading.Tasks;
 using UnityEngine;
 
-namespace Hotfix
+namespace Model
 {
-	public class AssetBundleLoaderAsync : HotfixEntity
+	public class AssetBundleLoaderAsync : Entity
 	{
 		private AssetBundle assetBundle;
 

+ 12 - 0
Unity/Assets/Scripts/Entity/AssetBundleLoaderAsync.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 3884a45c24f76244aa0697dcb9d95d15
+timeCreated: 1498117617
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Entity/Config.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 1136de56973a671409ed0bf599b1f478
+folderAsset: yes
+timeCreated: 1498118075
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Entity/Config/BuffConfig.cs → Unity/Assets/Scripts/Entity/Config/BuffConfig.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	[BsonIgnoreExtraElements]
 	public class BuffConfig: AConfig

+ 12 - 0
Unity/Assets/Scripts/Entity/Config/BuffConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 8433bdafcbe56e140b3fe0c93722e0cf
+timeCreated: 1498118076
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Entity/Config/StartConfig.cs → Unity/Assets/Scripts/Entity/Config/StartConfig.cs

@@ -1,7 +1,7 @@
 using MongoDB.Bson;
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Hotfix
+namespace Model
 {
 	public class StartConfig: AConfig
 	{

+ 12 - 0
Unity/Assets/Scripts/Entity/Config/StartConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c181dc38f15288746960812611a7767e
+timeCreated: 1498118076
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 28 - 0
Unity/Assets/Scripts/Entity/Game.cs

@@ -0,0 +1,28 @@
+namespace Model
+{
+	public static class Game
+	{
+		private static Scene scene;
+
+		public static Scene Scene
+		{
+			get
+			{
+				if (scene != null)
+				{
+					return scene;
+				}
+				scene = new Scene();
+				scene.AddComponent<EventComponent>();
+				scene.AddComponent<TimerComponent>();
+				return scene;
+			}
+		}
+		
+		public static void Close()
+		{
+			scene.Dispose();
+			scene = null;
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Entity/Game.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0e531b523752fbc4a837e52d4ba093dc
+timeCreated: 1498117616
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 44 - 0
Unity/Assets/Scripts/Entity/Scene.cs

@@ -0,0 +1,44 @@
+namespace Model
+{
+	public enum SceneType
+	{
+		Share,
+		Game,
+		Login,
+		Lobby,
+		Map,
+		Launcher,
+		Robot,
+		BehaviorTreeScene,
+		RobotClient,
+
+		Realm
+	}
+	
+	public sealed class Scene: Entity
+	{
+		public Scene Parent { get; set; }
+
+		public string Name { get; set; }
+
+		public SceneType SceneType { get; private set; }
+
+		public Scene(): base(EntityType.Scene)
+		{
+		}
+
+		public Scene(long id): base(id, EntityType.Scene)
+		{
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Entity/Scene.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 6a74878a3e383af45bac4995de1e0f53
+timeCreated: 1498117617
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 3
Unity/Hotfix/Entity/Session.cs → Unity/Assets/Scripts/Entity/Session.cs

@@ -2,13 +2,12 @@
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
-using LitJson;
 using Model;
 using MongoDB.Bson;
 
-namespace Hotfix
+namespace Model
 {
-	public sealed class Session : HotfixEntity
+	public sealed class Session : Entity
 	{
 		private static uint RpcId { get; set; }
 		private readonly NetworkComponent network;

+ 12 - 0
Unity/Assets/Scripts/Entity/Session.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 73d149d0c325fa24d91a94843bd520b8
+timeCreated: 1498117617
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Unity/Hotfix/Entity/WWWAsync.cs → Unity/Assets/Scripts/Entity/WWWAsync.cs

@@ -3,10 +3,10 @@ using System.Threading;
 using System.Threading.Tasks;
 using UnityEngine;
 
-namespace Hotfix
+namespace Model
 {
 	[EntityEvent(EntityEventId.WWWAsync)]
-	public class WWWAsync: HotfixEntity
+	public class WWWAsync: Entity
 	{
 		public WWW www;
 

+ 12 - 0
Unity/Assets/Scripts/Entity/WWWAsync.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 4d789ae4ba23a73469b228352499a1d0
+timeCreated: 1498117617
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Event.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: f4a531a7e2c04874fb0e829ae1773978
+folderAsset: yes
+timeCreated: 1498117616
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 15 - 0
Unity/Assets/Scripts/Event/AEventAttribute.cs

@@ -0,0 +1,15 @@
+using System;
+
+namespace Model
+{
+	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
+	public abstract class AEventAttribute: Attribute
+	{
+		public int Type { get; private set; }
+
+		protected AEventAttribute(int type)
+		{
+			this.Type = type;
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Event/AEventAttribute.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 288485f014836824b89d9a901bc5dcca
+timeCreated: 1477377275
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 91 - 0
Unity/Assets/Scripts/Event/Env.cs

@@ -0,0 +1,91 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Model
+{
+	public class Env
+	{
+		[BsonElement, BsonIgnoreIfNull]
+		private Dictionary<EnvKey, object> values = new Dictionary<EnvKey, object>();
+
+		public object this[EnvKey key]
+		{
+			get
+			{
+				return this.values[key];
+			}
+			set
+			{
+				if (this.values == null)
+				{
+					this.values = new Dictionary<EnvKey, object>();
+				}
+				this.values[key] = value;
+			}
+		}
+
+		public T Get<T>(EnvKey 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 Exception($"不能把{value.GetType()}转换为{typeof (T)}", e);
+			}
+		}
+
+		public void Set(EnvKey key, object obj)
+		{
+			if (this.values == null)
+			{
+				this.values = new Dictionary<EnvKey, object>();
+			}
+			this.values[key] = obj;
+		}
+
+		public bool ContainKey(EnvKey key)
+		{
+			if (this.values == null)
+			{
+				return false;
+			}
+			return this.values.ContainsKey(key);
+		}
+
+		public void Remove(EnvKey key)
+		{
+			if (this.values == null)
+			{
+				return;
+			}
+			this.values.Remove(key);
+			if (this.values.Count == 0)
+			{
+				this.values = null;
+			}
+		}
+
+		public void Add(EnvKey key, object value)
+		{
+			if (this.values == null)
+			{
+				this.values = new Dictionary<EnvKey, object>();
+			}
+			this.values[key] = value;
+		}
+
+		public IEnumerator GetEnumerator()
+		{
+			return this.values.GetEnumerator();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Event/Env.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 414e43d5bdd3d75458b86b1cf07ad175
+timeCreated: 1477377275
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 0
Unity/Assets/Scripts/Event/EnvKey.cs

@@ -0,0 +1,10 @@
+namespace Model
+{
+	/// <summary>
+	/// 一般使用事件名+变量名
+	/// </summary>
+	public enum EnvKey
+	{
+		ChannelError
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Event/EnvKey.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c6db3274f6a56f44eaaa14e0f2eecf54
+timeCreated: 1476427109
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Event/EventAttribute.cs

@@ -0,0 +1,9 @@
+namespace Model
+{
+	public class EventAttribute: AEventAttribute
+	{
+		public EventAttribute(int type): base(type)
+		{
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Event/EventAttribute.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 46c83a3a046e502409ed650e1f3bc238
+timeCreated: 1477377275
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 18 - 0
Unity/Assets/Scripts/Event/EventIdType.cs

@@ -0,0 +1,18 @@
+namespace Model
+{
+	public static class EventIdType
+	{
+		public const int InitSceneStart = 1;
+
+		public const int BehaviorTreeRunTreeEvent = 2;
+		public const int BehaviorTreeOpenEditor = 3;
+		public const int BehaviorTreeClickNode = 4;
+		public const int BehaviorTreeAfterChangeNodeType = 5;
+		public const int BehaviorTreeCreateNode = 6;
+		public const int BehaviorTreePropertyDesignerNewCreateClick = 7;
+		public const int BehaviorTreeMouseInNode = 8;
+		public const int BehaviorTreeConnectState = 9;
+		public const int BehaviorTreeReplaceClick = 10;
+		public const int BehaviorTreeRightDesignerDrag = 11;
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Event/EventIdType.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 50aff527fd963e44fbce24e2ef3c1287
+timeCreated: 1476421726
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 37 - 0
Unity/Assets/Scripts/Event/IEvent.cs

@@ -0,0 +1,37 @@
+namespace Model
+{
+	public interface IEvent
+	{
+		void Run();
+	}
+
+	public interface IEvent<in A>
+	{
+		void Run(A uid);
+	}
+
+	public interface IEvent<in A, in B>
+	{
+		void Run(A a, B b);
+	}
+
+	public interface IEvent<in A, in B, in C>
+	{
+		void Run(A a, B b, C c);
+	}
+
+	public interface IEvent<in A, in B, in C, in D>
+	{
+		void Run(A a, B b, C c, D d);
+	}
+
+	public interface IEvent<in A, in B, in C, in D, in E>
+	{
+		void Run(A a, B b, C c, D d, E e);
+	}
+
+	public interface IEvent<in A, in B, in C, in D, in E, in F>
+	{
+		void Run(A a, B b, C c, D d, E e, F f);
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Event/IEvent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: dab16cc3acc616f4880a9cd714ba9be0
+timeCreated: 1477377275
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Helper/GameObjectHelper.cs → Unity/Assets/Scripts/Helper/GameObjectHelper.cs

@@ -1,7 +1,7 @@
 using System;
 using UnityEngine;
 
-namespace Hotfix
+namespace Model
 {
 	public static class GameObjectHelper
 	{

+ 12 - 0
Unity/Assets/Scripts/Helper/GameObjectHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: aae5801bb8dddb648b2347dc09067765
+timeCreated: 1498118314
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 3
Unity/Hotfix/Helper/JsonHelper.cs → Unity/Assets/Scripts/Helper/JsonHelper.cs

@@ -1,8 +1,6 @@
 using System;
-using LitJson;
-using Model;
 
-namespace Hotfix
+namespace Model
 {
 	public static class JsonHelper
 	{

+ 12 - 0
Unity/Assets/Scripts/Helper/JsonHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 25b701814ea3740488abe9098cd34040
+timeCreated: 1498118586
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Assets/Scripts/Helper/ResourceHelper.cs

@@ -5,7 +5,7 @@ namespace Model
 {
 	public static class ResourceHelper
 	{
-		public static Object LoadResource(string bundleName, string prefab)
+		public static UnityEngine.Object LoadResource(string bundleName, string prefab)
 		{
 			string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleName.ToLower() + ".unity3d", prefab);
 			UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath(realPath[0], typeof(GameObject));

+ 1 - 1
Unity/Assets/Scripts/IL/ILBindingAttribute.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Hotfix
+namespace Model
 {
 	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
 	public class ILBindingAttribute : Attribute

+ 2 - 0
Unity/Assets/Scripts/Init.cs

@@ -50,6 +50,8 @@ namespace Model
 
 		private void Update()
 		{
+			ObjectEvents.Instance.Update();
+
 			this.AppDomain.Invoke(this.update, null, this.param0);
 		}
 

+ 9 - 0
Unity/Assets/Scripts/Message.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 2fafa040b653b9847a9348a31a0233af
+folderAsset: yes
+timeCreated: 1498117781
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Hotfix/Message/AMHandler.cs → Unity/Assets/Scripts/Message/AMHandler.cs

@@ -1,7 +1,7 @@
 using System;
 using Model;
 
-namespace Hotfix
+namespace Model
 {
 	public abstract class AMHandler<Message>: IMHandler where Message : AMessage
 	{

+ 0 - 0
Unity/Hotfix/Message/AMHandler.cs.meta → Unity/Assets/Scripts/Message/AMHandler.cs.meta


+ 1 - 1
Unity/Hotfix/Message/AMessage.cs → Unity/Assets/Scripts/Message/AMessage.cs

@@ -1,4 +1,4 @@
-namespace Hotfix
+namespace Model
 {
 	public abstract class AMessage
 	{

+ 0 - 0
Unity/Hotfix/Message/AMessage.cs.meta → Unity/Assets/Scripts/Message/AMessage.cs.meta


+ 1 - 1
Unity/Hotfix/Message/AppType.cs → Unity/Assets/Scripts/Message/AppType.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Hotfix
+namespace Model
 {
 	[Flags]
 	public enum AppType

+ 0 - 0
Unity/Hotfix/Message/AppType.cs.meta → Unity/Assets/Scripts/Message/AppType.cs.meta


+ 1 - 1
Unity/Hotfix/Message/ErrorCode.cs → Unity/Assets/Scripts/Message/ErrorCode.cs

@@ -1,4 +1,4 @@
-namespace Hotfix
+namespace Model
 {
 	public static class ErrorCode
 	{

+ 0 - 0
Unity/Hotfix/Message/ErrorCode.cs.meta → Unity/Assets/Scripts/Message/ErrorCode.cs.meta


+ 1 - 1
Unity/Hotfix/Message/IMHandler.cs → Unity/Assets/Scripts/Message/IMHandler.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Hotfix
+namespace Model
 {
 	public interface IMHandler
 	{

+ 0 - 0
Unity/Hotfix/Message/IMHandler.cs.meta → Unity/Assets/Scripts/Message/IMHandler.cs.meta


+ 1 - 1
Unity/Hotfix/Message/MessageAttribute.cs → Unity/Assets/Scripts/Message/MessageAttribute.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Hotfix
+namespace Model
 {
 	public class MessageAttribute: Attribute
 	{

+ 0 - 0
Unity/Hotfix/Message/MessageAttribute.cs.meta → Unity/Assets/Scripts/Message/MessageAttribute.cs.meta


+ 1 - 1
Unity/Hotfix/Message/MessageHandlerAttribute.cs → Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Hotfix
+namespace Model
 {
 	/// <summary>
 	/// 搭配MessageComponent用来分发消息

+ 0 - 0
Unity/Hotfix/Message/MessageHandlerAttribute.cs.meta → Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs.meta


+ 1 - 1
Unity/Hotfix/Message/MessageInfo.cs → Unity/Assets/Scripts/Message/MessageInfo.cs

@@ -1,4 +1,4 @@
-namespace Hotfix
+namespace Model
 {
 	public class MessageInfo
 	{

+ 0 - 0
Unity/Hotfix/Message/MessageInfo.cs.meta → Unity/Assets/Scripts/Message/MessageInfo.cs.meta


+ 1 - 1
Unity/Hotfix/Message/OpcodeHelper.cs → Unity/Assets/Scripts/Message/OpcodeHelper.cs

@@ -1,6 +1,6 @@
 using System.Collections.Generic;
 
-namespace Hotfix
+namespace Model
 {
 	public static class OpcodeHelper
 	{

+ 0 - 0
Unity/Hotfix/Message/OpcodeHelper.cs.meta → Unity/Assets/Scripts/Message/OpcodeHelper.cs.meta


+ 1 - 1
Unity/Hotfix/Message/RpcException.cs → Unity/Assets/Scripts/Message/RpcException.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Hotfix
+namespace Model
 {
 	/// <summary>
 	/// RPC异常,带ErrorCode

+ 0 - 0
Unity/Hotfix/Message/RpcException.cs.meta → Unity/Assets/Scripts/Message/RpcException.cs.meta


+ 9 - 0
Unity/Assets/Scripts/Object.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 600c9bb417aba1641897df52e4ea0eeb
+folderAsset: yes
+timeCreated: 1498116852
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 40 - 0
Unity/Assets/Scripts/Object/Component.cs

@@ -0,0 +1,40 @@
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Model
+{
+	public abstract class Component: Disposer
+	{
+		[BsonIgnore]
+		public Entity Owner { get; set; }
+
+		public T GetOwner<T>() where T : Entity
+		{
+			return this.Owner as T;
+		}
+
+		protected Component()
+		{
+		}
+
+		protected Component(long id): base(id)
+		{
+		}
+
+		public T GetComponent<T>() where T : Component
+		{
+			return this.Owner.GetComponent<T>();
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+
+			this.Owner.RemoveComponent(this.GetType());
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Object/Component.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 596cc447d1a588e47b6105622727b588
+timeCreated: 1498116852
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 21 - 0
Unity/Assets/Scripts/Object/Disposer.cs

@@ -0,0 +1,21 @@
+namespace Model
+{
+	public abstract class Disposer: Object
+	{
+		protected Disposer(): base(IdGenerater.GenerateId())
+		{
+			ObjectEvents.Instance.Add(this);
+		}
+
+		protected Disposer(long id): base(id)
+		{
+			ObjectEvents.Instance.Add(this);
+		}
+
+		public override void Dispose()
+		{
+			this.Id = 0;
+			ObjectEvents.Instance.Remove(this);
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Object/Disposer.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 785b1815942ba374b9cea238401cd506
+timeCreated: 1498116853
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 186 - 0
Unity/Assets/Scripts/Object/Entity.cs

@@ -0,0 +1,186 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Model
+{
+	public class Entity: Disposer
+	{
+		public EntityType Type { get; set; }
+		
+		private HashSet<Component> components = new HashSet<Component>();
+		
+		private readonly Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
+
+		protected Entity()
+		{
+			this.Type = EntityType.None;
+		}
+
+		protected Entity(EntityType entityType)
+		{
+			this.Type = entityType;
+		}
+
+		protected Entity(long id, EntityType entityType): base(id)
+		{
+			this.Type = entityType;
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+
+			foreach (Component component in this.GetComponents())
+			{
+				try
+				{
+					component.Dispose();
+				}
+				catch (Exception e)
+				{
+					Log.Error(e.ToString());
+				}
+			}
+		}
+
+		public K AddComponent<K>() where K : Component, new()
+		{
+			K component = (K) Activator.CreateInstance(typeof (K));
+			component.Owner = this;
+			if (this.componentDict.ContainsKey(component.GetType()))
+			{
+				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
+			}
+			if (this.components == null)
+			{
+				this.components = new HashSet<Component>();
+			}
+			this.components.Add(component);
+			this.componentDict.Add(component.GetType(), component);
+			IAwake awake = component as IAwake;
+			awake?.Awake();
+			return component;
+		}
+
+		public K AddComponent<K, P1>(P1 p1) where K : Component, new()
+		{
+			K component = (K) Activator.CreateInstance(typeof (K));
+			component.Owner = this;
+
+			if (this.componentDict.ContainsKey(component.GetType()))
+			{
+				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
+			}
+
+			if (this.components == null)
+			{
+				this.components = new HashSet<Component>();
+			}
+
+			this.components.Add(component);
+			this.componentDict.Add(component.GetType(), component);
+			IAwake<P1> awake = component as IAwake<P1>;
+			awake?.Awake(p1);
+			return component;
+		}
+
+		public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
+		{
+			K component = (K) Activator.CreateInstance(typeof (K));
+			component.Owner = this;
+
+			if (this.componentDict.ContainsKey(component.GetType()))
+			{
+				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
+			}
+
+			if (this.components == null)
+			{
+				this.components = new HashSet<Component>();
+			}
+
+			this.components.Add(component);
+			this.componentDict.Add(component.GetType(), component);
+			IAwake<P1, P2> awake = component as IAwake<P1, P2>;
+			awake?.Awake(p1, p2);
+			return component;
+		}
+
+		public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
+		{
+			K component = (K) Activator.CreateInstance(typeof (K));
+			component.Owner = this;
+
+			if (this.componentDict.ContainsKey(component.GetType()))
+			{
+				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
+			}
+
+			if (this.components == null)
+			{
+				this.components = new HashSet<Component>();
+			}
+
+			this.components.Add(component);
+			this.componentDict.Add(component.GetType(), component);
+			IAwake<P1, P2, P3> awake = component as IAwake<P1, P2, P3>;
+			awake?.Awake(p1, p2, p3);
+			return component;
+		}
+
+		public void RemoveComponent<K>() where K : Component
+		{
+			Component component;
+			if (!this.componentDict.TryGetValue(typeof (K), out component))
+			{
+				return;
+			}
+
+			this.components.Remove(component);
+			this.componentDict.Remove(typeof (K));
+			if (this.components.Count == 0)
+			{
+				this.components = null;
+			}
+			component.Dispose();
+		}
+
+		public void RemoveComponent(Type type)
+		{
+			Component component;
+			if (!this.componentDict.TryGetValue(type, out component))
+			{
+				return;
+			}
+
+			this.components.Remove(component);
+			this.componentDict.Remove(type);
+			if (this.components.Count == 0)
+			{
+				this.components = null;
+			}
+			component.Dispose();
+		}
+
+		public K GetComponent<K>() where K : Component
+		{
+			Component component;
+			if (!this.componentDict.TryGetValue(typeof (K), out component))
+			{
+				return default(K);
+			}
+			return (K) component;
+		}
+
+		public Component[] GetComponents()
+		{
+			return components.ToArray();
+		}
+	}
+}

Некоторые файлы не были показаны из-за большого количества измененных файлов