tanghai 5 лет назад
Родитель
Сommit
0dce8be3e4

+ 8 - 2
Unity/Assets/HotfixView/AppStart_Init.cs

@@ -11,14 +11,20 @@ namespace ET
             //await BundleHelper.DownloadBundle("1111");
 
             // 加载配置
-            Game.Scene.AddComponent<ResourcesComponent>().LoadBundle("config.unity3d");
+            Game.Scene.AddComponent<ResourcesComponent>();
+            
+            ResourcesComponent.Instance.LoadBundle("config.unity3d");
             Game.Scene.AddComponent<ConfigComponent>();
-            Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
+            ResourcesComponent.Instance.UnloadBundle("config.unity3d");
+            
             Game.Scene.AddComponent<OpcodeTypeComponent>();
             Game.Scene.AddComponent<MessageDispatcherComponent>();
+            Game.Scene.AddComponent<UIEventComponent>();
 
 
             Scene zoneScene = await SceneFactory.CreateZoneScene(1, 0, "Game");
+
+            await Game.EventSystem.Publish(new EventType.AppStartInitFinish() { ZoneScene = zoneScene });
         }
     }
 }

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

@@ -6,6 +6,7 @@ namespace ET
         {
             Scene zoneScene = args.ZoneScene;
             zoneScene.AddComponent<ResourcesComponent>();
+            zoneScene.AddComponent<UIComponent>();
         }
     }
 }

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

@@ -9,8 +9,9 @@ namespace ET
             zoneScene.AddComponent<NetOuterComponent>();
             zoneScene.AddComponent<PlayerComponent>();
             zoneScene.AddComponent<UnitComponent>();
-
-            await Game.EventSystem.Publish(new EventType.AfterCreateZoneScene());
+            
+            // UI层的初始化
+            await Game.EventSystem.Publish(new EventType.AfterCreateZoneScene() {ZoneScene = zoneScene});
             
             return zoneScene;
         }

+ 1 - 1
Unity/Assets/Hotfix/Scene/SceneFactory.cs.meta → Unity/Assets/HotfixView/Scene/SceneFactory.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 7cbe6b8dba0d1462e8ef45f7674b9794
+guid: 6132d5efb1bae460db2ef73d954f24e0
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 12
Unity/Assets/HotfixView/UI/UILogin/AfterCreateZoneScene_CreateLoginUI.cs

@@ -1,12 +0,0 @@
-
-
-namespace ET
-{
-	public class AfterCreateZoneScene_RemoveLoginUI: AEvent<EventType.AfterCreateZoneScene>
-	{
-		public override async ETTask Run(EventType.AfterCreateZoneScene args)
-		{
-			await UIHelper.Create(args.ZoneScene, UIType.UILogin);
-		}
-	}
-}

+ 12 - 0
Unity/Assets/HotfixView/UI/UILogin/AppStartInitFinish_CreateLoginUI.cs

@@ -0,0 +1,12 @@
+
+
+namespace ET
+{
+	public class AppStartInitFinish_RemoveLoginUI: AEvent<EventType.AppStartInitFinish>
+	{
+		public override async ETTask Run(EventType.AppStartInitFinish args)
+		{
+			await UIHelper.Create(args.ZoneScene, UIType.UILogin);
+		}
+	}
+}

+ 1 - 1
Unity/Assets/HotfixView/UI/UILogin/AfterCreateZoneScene_CreateLoginUI.cs.meta → Unity/Assets/HotfixView/UI/UILogin/AppStartInitFinish_CreateLoginUI.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: f86b269e7cff94f3cb2a36780d7a9f27
+guid: 8ca3bab3d15364846a895a2545184b52
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 1 - 1
Unity/Assets/HotfixView/UI/UILogin/UILoginComponentSystem.cs

@@ -10,7 +10,7 @@ namespace ET
 	{
 		public override void Awake(UILoginComponent self)
 		{
-			ReferenceCollector rc = self.GetParent<UI>().ViewGO.GetComponent<ReferenceCollector>();
+			ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
 			self.loginBtn = rc.Get<GameObject>("LoginBtn");
 			self.loginBtn.GetComponent<Button>().onClick.AddListener(self.OnLogin);
 			self.account = rc.Get<GameObject>("Account");

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

@@ -16,6 +16,11 @@
             public Scene LoginScene;
         }
 
+        public struct AppStartInitFinish
+        {
+            public Scene ZoneScene;
+        }
+
         public struct LoginFinish
         {
             public Scene ZoneScene;

+ 10 - 0
Unity/Assets/Model/Module/Resource/ResourcesComponent.cs

@@ -165,9 +165,19 @@ namespace ET
 		}
 	}
 	
+	public class ResourcesComponentAwakeSystem: AwakeSystem<ResourcesComponent>
+	{
+		public override void Awake(ResourcesComponent self)
+		{
+			ResourcesComponent.Instance = self;
+		}
+	}
+	
 
 	public class ResourcesComponent : Entity
 	{
+		public static ResourcesComponent Instance;
+		
 		public static AssetBundleManifest AssetBundleManifestObject { get; set; }
 
 		private readonly Dictionary<string, Dictionary<string, UnityEngine.Object>> resourceCache = new Dictionary<string, Dictionary<string, UnityEngine.Object>>();

+ 1 - 1
Unity/Assets/Model/Unit/TurnComponent.cs

@@ -43,7 +43,7 @@ namespace ET
 		/// </summary>
 		public void Turn2D(Vector3 dir, float turnTime = 0.1f)
 		{
-			Vector3 nexpos = this.GetParent<Unit>().ViewGO.transform.position + dir;
+			Vector3 nexpos = this.GetParent<Unit>().GameObject.transform.position + dir;
 			Turn(nexpos, turnTime);
 		}
 

+ 5 - 1
Unity/Assets/Model/Unit/Unit.cs

@@ -1,10 +1,14 @@
-using Quaternion = UnityEngine.Quaternion;
+using UnityEngine;
+using Quaternion = UnityEngine.Quaternion;
 using Vector3 = UnityEngine.Vector3;
 
 namespace ET
 {
 	public sealed class Unit: Entity
 	{
+		// 先放这里,去掉ViewGO,后面挪到显示层
+		public GameObject GameObject;
+		
 		public int ConfigId;
 
 		public UnitConfig Config

+ 11 - 11
Unity/Assets/ModelView/Module/UI/UI.cs

@@ -21,11 +21,11 @@ namespace ET
 		
 		public string Name { get; private set; }
 
-		public Dictionary<string, UI> children = new Dictionary<string, UI>();
+		public Dictionary<string, UI> nameChildren = new Dictionary<string, UI>();
 		
 		public void Awake(string name, GameObject gameObject)
 		{
-			this.children.Clear();
+			this.nameChildren.Clear();
 			gameObject.AddComponent<ComponentView>().Component = this;
 			gameObject.layer = LayerMask.NameToLayer(LayerNames.UI);
 			this.Name = name;
@@ -41,45 +41,45 @@ namespace ET
 			
 			base.Dispose();
 
-			foreach (UI ui in this.children.Values)
+			foreach (UI ui in this.nameChildren.Values)
 			{
 				ui.Dispose();
 			}
 			
-			UnityEngine.Object.Destroy(this.ViewGO);
-			children.Clear();
+			UnityEngine.Object.Destroy(this.GameObject);
+			this.nameChildren.Clear();
 		}
 
 		public void SetAsFirstSibling()
 		{
-			this.ViewGO.transform.SetAsFirstSibling();
+			this.GameObject.transform.SetAsFirstSibling();
 		}
 
 		public void Add(UI ui)
 		{
-			this.children.Add(ui.Name, ui);
+			this.nameChildren.Add(ui.Name, ui);
 			ui.Parent = this;
 		}
 
 		public void Remove(string name)
 		{
 			UI ui;
-			if (!this.children.TryGetValue(name, out ui))
+			if (!this.nameChildren.TryGetValue(name, out ui))
 			{
 				return;
 			}
-			this.children.Remove(name);
+			this.nameChildren.Remove(name);
 			ui.Dispose();
 		}
 
 		public UI Get(string name)
 		{
 			UI child;
-			if (this.children.TryGetValue(name, out child))
+			if (this.nameChildren.TryGetValue(name, out child))
 			{
 				return child;
 			}
-			GameObject childGameObject = this.ViewGO.transform.Find(name)?.gameObject;
+			GameObject childGameObject = this.GameObject.transform.Find(name)?.gameObject;
 			if (childGameObject == null)
 			{
 				return null;

+ 1 - 1
Unity/Assets/ModelView/Unit/AnimatorComponent.cs

@@ -40,7 +40,7 @@ namespace ET
 
 		public void Awake()
 		{
-			Animator animator = this.GetParent<Unit>().ViewGO.GetComponent<Animator>();
+			Animator animator = this.GetParent<Unit>().GameObject.GetComponent<Animator>();
 
 			if (animator == null)
 			{

+ 0 - 1
Unity/Unity.Hotfix.csproj

@@ -65,7 +65,6 @@
      <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" />

+ 2 - 1
Unity/Unity.HotfixView.csproj

@@ -63,6 +63,7 @@
      <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\Scene\SceneFactory.cs" />
      <Compile Include="Assets\HotfixView\UI\UIHelper.cs" />
      <Compile Include="Assets\HotfixView\UI\UILoading\LoadingBeginEvent_CreateLoadingUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILoading\LoadingFinishEvent_RemoveLoadingUI.cs" />
@@ -72,7 +73,7 @@
      <Compile Include="Assets\HotfixView\UI\UILobby\LoginFinish_CreateLobbyUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILobby\UILobbyComponentSystem.cs" />
      <Compile Include="Assets\HotfixView\UI\UILobby\UILobbyEvent.cs" />
-     <Compile Include="Assets\HotfixView\UI\UILogin\AfterCreateZoneScene_CreateLoginUI.cs" />
+     <Compile Include="Assets\HotfixView\UI\UILogin\AppStartInitFinish_CreateLoginUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILogin\LoginFinish_RemoveLoginUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILogin\UILoginComponentSystem.cs" />
      <Compile Include="Assets\HotfixView\UI\UILogin\UILoginEvent.cs" />