tanghai 5 lat temu
rodzic
commit
8b4d081de2
25 zmienionych plików z 242 dodań i 130 usunięć
  1. 3 2
      Unity/Assets/Hotfix/Scene/SceneFactory.cs
  2. 1 1
      Unity/Assets/HotfixView/AppStart_Init.cs
  3. 44 0
      Unity/Assets/HotfixView/Module/UI/UIComponentSystem.cs
  4. 60 0
      Unity/Assets/HotfixView/Module/UI/UIEventComponentSystem.cs
  5. 11 0
      Unity/Assets/HotfixView/Scene/AfterCreateZoneScene_AddComponent.cs
  6. 1 3
      Unity/Assets/HotfixView/UI/UILoading/LoadingBeginEvent_CreateLoadingUI.cs
  7. 1 1
      Unity/Assets/HotfixView/UI/UILoading/LoadingFinishEvent_RemoveLoadingUI.cs
  8. 8 6
      Unity/Assets/HotfixView/UI/UILoading/UILoadingEvent.cs
  9. 0 1
      Unity/Assets/HotfixView/UI/UILobby/EnterMapFinish_RemoveLobbyUI.cs
  10. 1 2
      Unity/Assets/HotfixView/UI/UILobby/LoginFinish_CreateLobbyUI.cs
  11. 11 6
      Unity/Assets/HotfixView/UI/UILobby/UILobbyEvent.cs
  12. 27 0
      Unity/Assets/HotfixView/UI/UILogin/UILoginEvent.cs
  13. 0 30
      Unity/Assets/HotfixView/UI/UILogin/UILoginFactory.cs
  14. 1 0
      Unity/Assets/Model/Base/Entity/SceneType.cs
  15. 11 0
      Unity/Assets/Model/EventType.cs
  16. 12 3
      Unity/Assets/Model/Module/Config/ACategory.cs
  17. 8 0
      Unity/Assets/ModelView/Module/UI/AUIEvent.cs
  18. 2 33
      Unity/Assets/ModelView/Module/UI/UIComponent.cs
  19. 14 0
      Unity/Assets/ModelView/Module/UI/UIEventAttribute.cs
  20. 16 0
      Unity/Assets/ModelView/Module/UI/UIEventComponent.cs
  21. 0 15
      Unity/Assets/ModelView/Module/UI/UIFactoryAttribute.cs
  22. 0 21
      Unity/Assets/ModelView/Module/UI/UIViewComponent.cs
  23. 1 0
      Unity/Unity.Hotfix.csproj
  24. 6 4
      Unity/Unity.HotfixView.csproj
  25. 3 2
      Unity/Unity.ModelView.csproj

+ 3 - 2
Unity/Assets/HotfixView/Scene/SceneFactory.cs → Unity/Assets/Hotfix/Scene/SceneFactory.cs

@@ -2,14 +2,15 @@ namespace ET
 {
     public static class SceneFactory
     {
-        public static Scene CreateZoneScene(long id, int zone, string name)
+        public static async ETTask<Scene> CreateZoneScene(long id, int zone, string name)
         {
             Scene zoneScene = EntitySceneFactory.CreateScene(id, zone, SceneType.Zone, name, Game.Scene);
             
             zoneScene.AddComponent<NetOuterComponent>();
-            zoneScene.AddComponent<ResourcesComponent>();
             zoneScene.AddComponent<PlayerComponent>();
             zoneScene.AddComponent<UnitComponent>();
+
+            await Game.EventSystem.Publish(new EventType.AfterCreateZoneScene());
             
             return zoneScene;
         }

+ 1 - 1
Unity/Assets/HotfixView/AppStart_Init.cs

@@ -18,7 +18,7 @@ namespace ET
             Game.Scene.AddComponent<MessageDispatcherComponent>();
 
 
-            SceneFactory.CreateZoneScene(1, 0, "Game");
+            Scene zoneScene = await SceneFactory.CreateZoneScene(1, 0, "Game");
         }
     }
 }

+ 44 - 0
Unity/Assets/HotfixView/Module/UI/UIComponentSystem.cs

@@ -0,0 +1,44 @@
+using System.Collections.Generic;
+
+namespace ET
+{
+	public class UIComponentAwakeSystem : AwakeSystem<UIComponent>
+	{
+		public override void Awake(UIComponent self)
+		{
+		}
+	}
+	
+	/// <summary>
+	/// 管理Scene上的UI
+	/// </summary>
+	public static class UIComponentSystem
+	{
+		public static async ETTask Create(this UIComponent self, string uiType)
+		{
+			UI ui = await UIEventComponent.Instance.OnCreate(self, uiType);
+			
+			self.UIs.Add(uiType, ui);
+		}
+
+		public static void Remove(this UIComponent self, string uiType)
+		{
+			if (!self.UIs.TryGetValue(uiType, out UI ui))
+			{
+				return;
+			}
+			
+			UIEventComponent.Instance.OnRemove(self, uiType);
+			
+			self.UIs.Remove(uiType);
+			ui.Dispose();
+		}
+
+		public static UI Get(this UIComponent self, string name)
+		{
+			UI ui = null;
+			self.UIs.TryGetValue(name, out ui);
+			return ui;
+		}
+	}
+}

+ 60 - 0
Unity/Assets/HotfixView/Module/UI/UIEventComponentSystem.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace ET
+{
+	public class UIEventComponentAwakeSystem : AwakeSystem<UIEventComponent>
+	{
+		public override void Awake(UIEventComponent self)
+		{
+			UIEventComponent.Instance = self;
+
+			var uiEvents = Game.EventSystem.GetTypes(typeof (UIEventAttribute));
+			foreach (Type type in uiEvents)
+			{
+				object[] attrs = type.GetCustomAttributes(typeof(UIEventAttribute), false);
+				if (attrs.Length == 0)
+				{
+					continue;
+				}
+
+				UIEventAttribute uiEventAttribute = attrs[0] as UIEventAttribute;
+				AUIEvent aUIEvent = Activator.CreateInstance(type) as AUIEvent;
+				self.UIEvents.Add(uiEventAttribute.UIType, aUIEvent);
+			}
+		}
+	}
+	
+	/// <summary>
+	/// 管理所有UI GameObject 以及UI事件
+	/// </summary>
+	public static class UIEventComponentSystem
+	{
+		public static async ETTask<UI> OnCreate(this UIEventComponent self, UIComponent uiComponent, string uiType)
+		{
+			try
+			{
+				UI ui = await self.UIEvents[uiType].OnCreate(uiComponent);
+				return ui;
+			}
+			catch (Exception e)
+			{
+				throw new Exception($"on create ui error: {uiType}", e);
+			}
+		}
+		
+		public static void OnRemove(this UIEventComponent self, UIComponent uiComponent, string uiType)
+		{
+			try
+			{
+				self.UIEvents[uiType].OnRemove(uiComponent);
+			}
+			catch (Exception e)
+			{
+				throw new Exception($"on remove ui error: {uiType}", e);
+			}
+			
+		}
+	}
+}

+ 11 - 0
Unity/Assets/HotfixView/Scene/AfterCreateZoneScene_AddComponent.cs

@@ -0,0 +1,11 @@
+namespace ET
+{
+    public class AfterCreateZoneScene_AddComponent: AEvent<EventType.AfterCreateZoneScene>
+    {
+        public override async ETTask Run(EventType.AfterCreateZoneScene args)
+        {
+            Scene zoneScene = args.ZoneScene;
+            zoneScene.AddComponent<ResourcesComponent>();
+        }
+    }
+}

+ 1 - 3
Unity/Assets/HotfixView/UI/UILoading/LoadingBeginEvent_CreateLoadingUI.cs

@@ -2,13 +2,11 @@
 
 namespace ET
 {
-    [Event()]
     public class LoadingBeginEvent_CreateLoadingUI : AEvent<EventType.LoadingBegin>
     {
         public override async ETTask Run(EventType.LoadingBegin args)
         {
-            UI ui = UILoadingFactory.Create(args.Scene);
-			Game.Scene.GetComponent<UIComponent>().Add(ui);
+            await args.Scene.GetComponent<UIComponent>().Create(UIType.UILoading);
         }
     }
 }

+ 1 - 1
Unity/Assets/HotfixView/UI/UILoading/LoadingFinishEvent_RemoveLoadingUI.cs

@@ -4,7 +4,7 @@
     {
         public override async ETTask Run(EventType.LoadingFinish args)
         {
-			Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILoading);
+            args.Scene.GetComponent<UIComponent>().Remove(UIType.UILoading);
         }
     }
 }

+ 8 - 6
Unity/Assets/HotfixView/UI/UILoading/UILoadingFactory.cs → Unity/Assets/HotfixView/UI/UILoading/UILoadingEvent.cs

@@ -3,16 +3,17 @@ using UnityEngine;
 
 namespace ET
 {
-    public static class UILoadingFactory
+	[UIEvent(UIType.UILoading)]
+    public class UILoadingEvent: AUIEvent
     {
-        public static UI Create(Entity domain)
+        public override async ETTask<UI> OnCreate(UIComponent uiComponent)
         {
 	        try
 	        {
 				GameObject bundleGameObject = ((GameObject)Resources.Load("KV")).Get<GameObject>(UIType.UILoading);
 				GameObject go = UnityEngine.Object.Instantiate(bundleGameObject);
 				go.layer = LayerMask.NameToLayer(LayerNames.UI);
-				UI ui = EntityFactory.Create<UI, string, GameObject>(domain, UIType.UILoading, go);
+				UI ui = EntityFactory.Create<UI, string, GameObject>(uiComponent.Domain, UIType.UILoading, go);
 
 				ui.AddComponent<UILoadingComponent>();
 				return ui;
@@ -24,8 +25,9 @@ namespace ET
 	        }
 		}
 
-	    public static void Remove(string type)
-	    {
-	    }
+        public override void OnRemove(UIComponent uiComponent)
+        {
+	        uiComponent.Remove(UIType.UILoading);
+        }
     }
 }

+ 0 - 1
Unity/Assets/HotfixView/UI/UILobby/EnterMapFinish_RemoveLobbyUI.cs

@@ -5,7 +5,6 @@
 		public override async ETTask Run(EventType.EnterMapFinish args)
 		{
 			Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILobby);
-			Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle(UIType.UILobby.StringToAB());
 		}
 	}
 }

+ 1 - 2
Unity/Assets/HotfixView/UI/UILobby/LoginFinish_CreateLobbyUI.cs

@@ -6,8 +6,7 @@ namespace ET
 	{
 		public override async ETTask Run(EventType.LoginFinish args)
 		{
-			UI ui = UILobbyFactory.Create();
-			Game.Scene.GetComponent<UIComponent>().Add(ui);
+			await Game.Scene.GetComponent<UIComponent>().Create(UIType.UILobby);
 		}
 	}
 }

+ 11 - 6
Unity/Assets/HotfixView/UI/UILobby/UILobbyFactory.cs → Unity/Assets/HotfixView/UI/UILobby/UILobbyEvent.cs

@@ -1,12 +1,12 @@
 using System;
-
 using UnityEngine;
 
 namespace ET
 {
-    public static class UILobbyFactory
+	[UIEvent(UIType.UILobby)]
+    public class UILobbyEvent: AUIEvent
     {
-        public static UI Create()
+        public override async ETTask<UI> OnCreate(UIComponent uiComponent)
         {
 	        try
 	        {
@@ -14,9 +14,9 @@ namespace ET
 		        resourcesComponent.LoadBundle(UIType.UILobby.StringToAB());
 				GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(UIType.UILobby.StringToAB(), UIType.UILobby);
 				GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
-		        UI ui = EntityFactory.Create<UI, string, GameObject>(Game.Scene, UIType.UILobby, gameObject);
-
-				ui.AddComponent<UILobbyComponent>();
+		        UI ui = EntityFactory.Create<UI, string, GameObject>(uiComponent.Domain, UIType.UILobby, gameObject);
+		        
+		        ui.AddComponent<UILobbyComponent>();
 				return ui;
 	        }
 	        catch (Exception e)
@@ -25,5 +25,10 @@ namespace ET
 		        return null;
 	        }
 		}
+
+        public override void OnRemove(UIComponent uiComponent)
+        {
+	        uiComponent.Remove(UIType.UILobby);
+        }
     }
 }

+ 27 - 0
Unity/Assets/HotfixView/UI/UILogin/UILoginEvent.cs

@@ -0,0 +1,27 @@
+using System;
+using UnityEngine;
+
+namespace ET
+{
+    [UIEvent(UIType.UILogin)]
+    public class UILoginEvent: AUIEvent
+    {
+        public override async ETTask<UI> OnCreate(UIComponent uiComponent)
+        {
+            ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
+            await resourcesComponent.LoadBundleAsync(UIType.UILogin.StringToAB());
+            GameObject bundleGameObject = (GameObject) resourcesComponent.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);
+            GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
+
+            UI ui = EntityFactory.Create<UI, string, GameObject>(uiComponent.Domain, UIType.UILogin, gameObject);
+
+            ui.AddComponent<UILoginComponent>();
+            return ui;
+        }
+
+        public override void OnRemove(UIComponent uiComponent)
+        {
+            uiComponent.Remove(UIType.UILogin);
+        }
+    }
+}

+ 0 - 30
Unity/Assets/HotfixView/UI/UILogin/UILoginFactory.cs

@@ -1,30 +0,0 @@
-using System;
-
-using UnityEngine;
-
-namespace ET
-{
-    public static class UILoginFactory
-    {
-        public static UI Create()
-        {
-	        try
-	        {
-				ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
-				resourcesComponent.LoadBundle(UIType.UILogin.StringToAB());
-				GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);
-				GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
-
-		        UI ui = EntityFactory.Create<UI, string, GameObject>(Game.Scene, UIType.UILogin, gameObject);
-
-				ui.AddComponent<UILoginComponent>();
-				return ui;
-	        }
-	        catch (Exception e)
-	        {
-				Log.Error(e);
-		        return null;
-	        }
-		}
-    }
-}

+ 1 - 0
Unity/Assets/Model/Base/Entity/SceneType.cs

@@ -13,5 +13,6 @@
 		// 客户端Model层
 		Client = 30,
 		Zone = 31,
+		Login = 32,
 	}
 }

+ 11 - 0
Unity/Assets/Model/EventType.cs

@@ -5,6 +5,16 @@
         public struct AppStart
         {
         }
+        
+        public struct AfterCreateZoneScene
+        {
+            public Scene ZoneScene;
+        }
+        
+        public struct AfterCreateLoginScene
+        {
+            public Scene LoginScene;
+        }
 
         public struct LoginFinish
         {
@@ -17,6 +27,7 @@
 
         public struct LoadingFinish
         {
+            public Scene Scene;
         }
 
         public struct EnterMapFinish

+ 12 - 3
Unity/Assets/Model/Module/Config/ACategory.cs

@@ -1,12 +1,21 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 
 namespace ET
 {
-	public abstract class ACategory : Object
+	public abstract class ACategory: ISupportInitialize
 	{
 		public abstract Type ConfigType { get; }
+
+		public virtual void BeginInit()
+		{
+		}
+
+		public virtual void EndInit()
+		{
+		}
 	}
 
 	/// <summary>
@@ -17,7 +26,7 @@ namespace ET
 	{
 		protected Dictionary<long, T> dict;
 
-		public override void BeginInit()
+		public virtual void BeginInit()
 		{
 			this.dict = new Dictionary<long, T>();
 
@@ -50,7 +59,7 @@ namespace ET
 			}
 		}
 
-		public override void EndInit()
+		public virtual void EndInit()
 		{
 		}
 

+ 8 - 0
Unity/Assets/ModelView/Module/UI/AUIEvent.cs

@@ -0,0 +1,8 @@
+namespace ET
+{
+    public abstract class AUIEvent
+    {
+        public abstract ETTask<UI> OnCreate(UIComponent uiComponent);
+        public abstract void OnRemove(UIComponent uiComponent);
+    }
+}

+ 2 - 33
Unity/Assets/ModelView/Module/UI/UIComponent.cs

@@ -2,42 +2,11 @@
 
 namespace ET
 {
-	
-	public class UIComponentAwakeSystem : AwakeSystem<UIComponent>
-	{
-		public override void Awake(UIComponent self)
-		{
-		}
-	}
-	
 	/// <summary>
-	/// 管理所有UI
+	/// 管理Scene上的UI
 	/// </summary>
 	public class UIComponent: Entity
 	{
-		public Dictionary<string, UI> uis = new Dictionary<string, UI>();
-
-		public void Add(UI ui)
-		{
-			this.uis.Add(ui.Name, ui);
-			ui.Parent = this;
-		}
-
-		public void Remove(string name)
-		{
-			if (!this.uis.TryGetValue(name, out UI ui))
-			{
-				return;
-			}
-			this.uis.Remove(name);
-			ui.Dispose();
-		}
-
-		public UI Get(string name)
-		{
-			UI ui = null;
-			this.uis.TryGetValue(name, out ui);
-			return ui;
-		}
+		public Dictionary<string, UI> UIs = new Dictionary<string, UI>();
 	}
 }

+ 14 - 0
Unity/Assets/ModelView/Module/UI/UIEventAttribute.cs

@@ -0,0 +1,14 @@
+using System;
+
+namespace ET
+{
+    public class UIEventAttribute: Attribute
+    {
+        public string UIType { get; }
+
+        public UIEventAttribute(string uiType)
+        {
+            this.UIType = uiType;
+        }
+    }
+}

+ 16 - 0
Unity/Assets/ModelView/Module/UI/UIEventComponent.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace ET
+{
+	/// <summary>
+	/// 管理所有UI GameObject
+	/// </summary>
+	public class UIEventComponent: Entity
+	{
+		public static UIEventComponent Instance;
+		
+		public Dictionary<string, AUIEvent> UIEvents = new Dictionary<string, AUIEvent>();
+	}
+}

+ 0 - 15
Unity/Assets/ModelView/Module/UI/UIFactoryAttribute.cs

@@ -1,15 +0,0 @@
-using System;
-
-namespace ET
-{
-	[AttributeUsage(AttributeTargets.Class)]
-	public class UIFactoryAttribute: BaseAttribute
-	{
-		public string Type { get; }
-
-		public UIFactoryAttribute(string type)
-		{
-			this.Type = type;
-		}
-	}
-}

+ 0 - 21
Unity/Assets/ModelView/Module/UI/UIViewComponent.cs

@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using UnityEngine;
-
-namespace ET
-{
-	
-	public class UIViewComponentAwakeSystem : AwakeSystem<UIViewComponent>
-	{
-		public override void Awake(UIViewComponent self)
-		{
-		}
-	}
-	
-	/// <summary>
-	/// 管理所有UI
-	/// </summary>
-	public class UIViewComponent: Entity
-	{
-	}
-}

+ 1 - 0
Unity/Unity.Hotfix.csproj

@@ -65,6 +65,7 @@
      <Compile Include="Assets\Hotfix\Move\M2C_PathfindingResultHandler.cs" />
      <Compile Include="Assets\Hotfix\Scene\LoginHelper.cs" />
      <Compile Include="Assets\Hotfix\Scene\MapHelper.cs" />
+     <Compile Include="Assets\Hotfix\Scene\SceneFactory.cs" />
      <Compile Include="Assets\Hotfix\Unit\M2C_CreateUnitsHandler.cs" />
      <Compile Include="Assets\Hotfix\Unit\PlayerFactory.cs" />
      <Compile Include="Assets\Hotfix\Unit\UnitFactory.cs" />

+ 6 - 4
Unity/Unity.HotfixView.csproj

@@ -60,18 +60,20 @@
   <ItemGroup>
      <Compile Include="Assets\HotfixView\AppStart_Init.cs" />
      <Compile Include="Assets\HotfixView\Module\Resource\GameObjectHelper.cs" />
-     <Compile Include="Assets\HotfixView\Scene\SceneFactory.cs" />
+     <Compile Include="Assets\HotfixView\Module\UI\UIComponentSystem.cs" />
+     <Compile Include="Assets\HotfixView\Module\UI\UIEventComponentSystem.cs" />
+     <Compile Include="Assets\HotfixView\Scene\AfterCreateZoneScene_AddComponent.cs" />
      <Compile Include="Assets\HotfixView\UI\UILoading\LoadingBeginEvent_CreateLoadingUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILoading\LoadingFinishEvent_RemoveLoadingUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILoading\UILoadingComponentSystem.cs" />
-     <Compile Include="Assets\HotfixView\UI\UILoading\UILoadingFactory.cs" />
+     <Compile Include="Assets\HotfixView\UI\UILoading\UILoadingEvent.cs" />
      <Compile Include="Assets\HotfixView\UI\UILobby\EnterMapFinish_RemoveLobbyUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILobby\LoginFinish_CreateLobbyUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILobby\UILobbyComponentSystem.cs" />
-     <Compile Include="Assets\HotfixView\UI\UILobby\UILobbyFactory.cs" />
+     <Compile Include="Assets\HotfixView\UI\UILobby\UILobbyEvent.cs" />
      <Compile Include="Assets\HotfixView\UI\UILogin\LoginFinish_RemoveLoginUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILogin\UILoginComponentSystem.cs" />
-     <Compile Include="Assets\HotfixView\UI\UILogin\UILoginFactory.cs" />
+     <Compile Include="Assets\HotfixView\UI\UILogin\UILoginEvent.cs" />
      <Compile Include="Assets\HotfixView\Unit\AfterUnitCreate_CreateUnitView.cs" />
      <None Include="Assets\HotfixView\Unity.HotfixView.asmdef" />
  <Reference Include="UnityEditor.UI">

+ 3 - 2
Unity/Unity.ModelView.csproj

@@ -61,13 +61,14 @@
      <Compile Include="Assets\ModelView\Camera\CameraComponent.cs" />
      <Compile Include="Assets\ModelView\GizmosDebug.cs" />
      <Compile Include="Assets\ModelView\Init.cs" />
+     <Compile Include="Assets\ModelView\Module\UI\AUIEvent.cs" />
      <Compile Include="Assets\ModelView\Module\UI\CanvasConfig.cs" />
      <Compile Include="Assets\ModelView\Module\UI\LayerNames.cs" />
      <Compile Include="Assets\ModelView\Module\UI\UI.cs" />
+     <Compile Include="Assets\ModelView\Module\UI\UIEventAttribute.cs" />
      <Compile Include="Assets\ModelView\Module\UI\UIComponent.cs" />
-     <Compile Include="Assets\ModelView\Module\UI\UIFactoryAttribute.cs" />
      <Compile Include="Assets\ModelView\Module\UI\UIType.cs" />
-     <Compile Include="Assets\ModelView\Module\UI\UIViewComponent.cs" />
+     <Compile Include="Assets\ModelView\Module\UI\UIEventComponent.cs" />
      <Compile Include="Assets\ModelView\Opera\OperaComponent.cs" />
      <Compile Include="Assets\ModelView\ReferenceCollector.cs" />
      <Compile Include="Assets\ModelView\Scene\SceneChangeComponent.cs" />