Переглянути джерело

修复CrossComponent的问题

tanghai 8 роки тому
батько
коміт
9fd95756a4

+ 13 - 15
Unity/Assets/Scripts/Component/CrossComponent.cs

@@ -4,17 +4,12 @@ using System.Collections.Generic;
 namespace Model
 {
 	[ObjectEvent]
-	public class CrossComponentEvent : ObjectEvent<CrossComponent>, IAwake, ILoad
+	public class CrossComponentEvent : ObjectEvent<CrossComponent>, IAwake
 	{
 		public void Awake()
 		{
 			this.Get().Awake();
 		}
-
-		public void Load()
-		{
-			this.Get().Load();
-		}
 	}
 
 	/// <summary>
@@ -26,35 +21,38 @@ namespace Model
 
 		public void Awake()
 		{
-			this.Load();
+			Load();
 		}
 
-		public void Load()
+		private void Load()
 		{
-			this.allEvents = new Dictionary<int, List<IInstanceMethod>>();
+			allEvents = new Dictionary<int, List<IInstanceMethod>>();
 
 			Type[] types = DllHelper.GetHotfixTypes();
 			foreach (Type type in types)
 			{
 				object[] attrs = type.GetCustomAttributes(typeof(CrossEventAttribute), false);
-
 				foreach (object attr in attrs)
 				{
 					CrossEventAttribute aEventAttribute = (CrossEventAttribute)attr;
+#if ILRuntime
 					IInstanceMethod method = new ILInstanceMethod(type, "Run");
-					if (!this.allEvents.ContainsKey(aEventAttribute.Type))
+#else
+					IInstanceMethod method = new MonoInstanceMethod(type, "Run");
+#endif
+					if (!allEvents.ContainsKey(aEventAttribute.Type))
 					{
-						this.allEvents.Add(aEventAttribute.Type, new List<IInstanceMethod>());
+						allEvents.Add(aEventAttribute.Type, new List<IInstanceMethod>());
 					}
-					this.allEvents[aEventAttribute.Type].Add(method);
+					allEvents[aEventAttribute.Type].Add(method);
 				}
 			}
 		}
 
-		public void Run(int type)
+		public void Run(CrossIdType type)
 		{
 			List<IInstanceMethod> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!allEvents.TryGetValue((int)type, out iEvents))
 			{
 				return;
 			}

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

@@ -67,6 +67,7 @@ namespace Model
 				Game.Scene.AddComponent<PlayerComponent>();
 				Game.Scene.AddComponent<UnitComponent>();
 				Game.Scene.AddComponent<ClientFrameComponent>();
+				Game.Scene.AddComponent<CrossComponent>();
 
 				// 进入热更新层
 				this.start.Run();