Browse Source

修复了进入战斗场景Map1过程的各种问题

大爷 2 years ago
parent
commit
a809c178c4

+ 2 - 3
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Login/EnterMapHelper.cs

@@ -13,9 +13,8 @@ namespace ET.Client
                 clientScene.GetComponent<PlayerComponent>().MyId = g2CEnterMap.MyId;
                 
                 // 等待场景切换完成
-                await clientScene.GetComponent<ObjectWait>().Wait<Wait_SceneChangeFinish>();
-                
-                EventSystem.Instance.Publish(clientScene, new EventType.EnterMapFinish());
+                //await clientScene.GetComponent<ObjectWait>().Wait<Wait_SceneChangeFinish>();
+                //EventSystem.Instance.Publish(clientScene, new EventType.EnterMapFinish());
             }
             catch (Exception e)
             {

+ 0 - 5
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Scene/SceneChangeHelper.cs

@@ -22,11 +22,6 @@
             unitComponent.Add(unit);
             
             clientScene.RemoveComponent<AIComponent>();
-            
-            EventSystem.Instance.Publish(currentScene, new EventType.SceneChangeFinish());
-
-            // 通知等待场景切换的协程
-            clientScene.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
         }
     }
 }

+ 2 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Unit/M2C_CreateUnitsHandler.cs

@@ -12,9 +12,10 @@
 			{
 				if (unitComponent.Get(unitInfo.UnitId) != null)
 				{
+					Log.Debug($"ignore exist unit: {unitInfo.UnitId}");
 					continue;
 				}
-				Unit unit = UnitFactory.Create(currentScene, unitInfo);
+				UnitFactory.Create(currentScene, unitInfo);
 			}
 			await ETTask.CompletedTask;
 		}

+ 7 - 6
Unity/Assets/Scripts/Codes/HotfixView/Client/Demo/Unit/AfterUnitCreate_CreateUnitView.cs

@@ -10,13 +10,14 @@ namespace ET.Client
             Unit unit = args.Unit;
             // Unit View层
             // 这里可以改成异步加载,demo就不搞了
-            GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset("Unit.unity3d", "Unit");
-            GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
+            Log.Debug("===after create unit, to load model");
+            //GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset("Unit.unity3d", "Unit");
+            //GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
 	        
-            GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalComponent.Instance.Unit, true);
-            go.transform.position = unit.Position;
-            unit.AddComponent<GameObjectComponent>().GameObject = go;
-            unit.AddComponent<AnimatorComponent>();
+            //GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalComponent.Instance.Unit, true);
+            //go.transform.position = unit.Position;
+            //unit.AddComponent<GameObjectComponent>().GameObject = go;
+            //unit.AddComponent<AnimatorComponent>();
             await ETTask.CompletedTask;
         }
     }

+ 2 - 2
Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/AfterCreateCurrentScene_AddComponent.cs

@@ -5,8 +5,8 @@ namespace ET.Client
     {
         protected override async ETTask Run(Scene scene, EventType.AfterCreateCurrentScene args)
         {
-            scene.AddComponent<UIComponent>();
-            scene.AddComponent<ResourcesLoaderComponent>();
+            //scene.AddComponent<UIComponent>();
+            //scene.AddComponent<ResourcesLoaderComponent>();
             await ETTask.CompletedTask;
         }
     }

+ 15 - 7
Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/SceneChangeStart_AddComponent.cs

@@ -1,3 +1,5 @@
+using Cysharp.Threading.Tasks;
+using FairyGUI;
 using UnityEngine.SceneManagement;
 
 namespace ET.Client
@@ -7,16 +9,22 @@ namespace ET.Client
     {
         protected override async ETTask Run(Scene scene, EventType.SceneChangeStart args)
         {
+            UIHelper.Create("Loading").Coroutine();
             Scene currentScene = scene.CurrentScene();
-            
-            // 加载场景资源
-            //await ResourcesComponent.Instance.LoadBundleAsync($"{currentScene.Name}.unity3d");
-            // 切换到map场景
-
-            await SceneManager.LoadSceneAsync(currentScene.Name);
-			
+            var scnName = currentScene.Name;
+            Log.Debug($"loading scene: {scnName}.");
+            // 加载场景资源 & 加载
+            var task = await YooAssetProxy.LoadSceneAsync("Scene_" + scnName);
+            Log.Debug($"scene({task.SceneObject.name}) load finished.");
 
+            await TimerComponent.Instance.WaitAsync(3000);
+            UIHelper.Remove("Lobby");
+            UIHelper.SetVisible("Loading", false);
             currentScene.AddComponent<OperaComponent>();
+
+            // 通知等待场景切换的协程
+            //scene.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
+            //EventSystem.Instance.Publish(scene, new EventType.SceneChangeFinish());
         }
     }
 }

+ 2 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/UIHelp/SceneChangeFinishEvent_CreateUIHelp.cs

@@ -5,7 +5,8 @@
     {
         protected override async ETTask Run(Scene scene, EventType.SceneChangeFinish args)
         {
-            await UIHelper.Create(scene, UIType.UIHelp, UILayer.Mid);
+            Log.Debug("===Scene changefinish, to create ui");
+            await ETTask.CompletedTask;
         }
     }
 }

+ 38 - 7
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/UIHelper.cs

@@ -1,16 +1,47 @@
-namespace ET.Client
+using FairyGUI;
+using System.Runtime.Remoting.Lifetime;
+using UnityEngine;
+
+namespace ET.Client
 {
     public static class UIHelper
     {
-        public static async ETTask<UI> Create(Scene scene, string uiType, UILayer uiLayer)
+        public static async ETTask<GObject> Create(string uiName)
         {
-            return await scene.GetComponent<UIComponent>().Create(uiType, uiLayer);
+            var ass = await YooAssetProxy.LoadAssetAsync<TextAsset>($"FGUI_{uiName}_fui");
+            UIPackage.AddPackage(ass.GetAssetObject<TextAsset>().bytes, uiName, LoadPackageInternalAsync);
+            var view = UIPackage.CreateObject(uiName, uiName).asCom;
+            view.name = uiName;
+            GRoot.inst.AddChild(view);
+            return view;
         }
-        
-        public static async ETTask Remove(Scene scene, string uiType)
+
+        private static async void LoadPackageInternalAsync(string name,string extension, System.Type type, PackageItem item)
         {
-            scene.GetComponent<UIComponent>().Remove(uiType);
-            await ETTask.CompletedTask;
+            var tex = await YooAssetProxy.LoadAssetAsync<Texture>($"FGUI_{name}");
+            item.owner.SetItemAsset(item, tex.GetAsset<Texture>(), DestroyMethod.Unload);
+        }
+
+        public static bool Remove(string uiName, bool release = true)
+        {
+            var view = GRoot.inst.GetChild(uiName);
+            if (view != null)
+            {
+                GRoot.inst.RemoveChild(view, release);
+                return true;
+            }
+            return false;
+        }
+
+        public static bool SetVisible(string uiName, bool flag)
+        {
+            var view = GRoot.inst.GetChild(uiName);
+            if (view != null)
+            {
+                view.visible = flag;
+                return true;
+            }
+            return false;
         }
     }
 }