浏览代码

直接await AsyncOperation

tanghai 3 年之前
父节点
当前提交
1740431036

+ 0 - 56
Codes/HotfixView/Client/Demo/Scene/SceneChangeComponentSystem.cs

@@ -1,56 +0,0 @@
-using UnityEngine.SceneManagement;
-
-namespace ET.Client
-{
-    [FriendOf(typeof(SceneChangeComponent))]
-    public static class SceneChangeComponentSystem
-    {
-        public class SceneChangeComponentUpdateSystem: UpdateSystem<SceneChangeComponent>
-        {
-            public override void Update(SceneChangeComponent self)
-            {
-                if (!self.loadMapOperation.isDone)
-                {
-                    return;
-                }
-
-                if (self.tcs == null)
-                {
-                    return;
-                }
-            
-                ETTask tcs = self.tcs;
-                self.tcs = null;
-                tcs.SetResult();
-            }
-        }
-	
-    
-        public class SceneChangeComponentDestroySystem: DestroySystem<SceneChangeComponent>
-        {
-            public override void Destroy(SceneChangeComponent self)
-            {
-                self.loadMapOperation = null;
-                self.tcs = null;
-            }
-        }
-        
-        public static async ETTask ChangeSceneAsync(this SceneChangeComponent self, string sceneName)
-        {
-            self.tcs = ETTask.Create(true);
-            // 加载map
-            self.loadMapOperation = SceneManager.LoadSceneAsync(sceneName);
-            //this.loadMapOperation.allowSceneActivation = false;
-            await self.tcs;
-        }
-        
-        public static int Process(this SceneChangeComponent self)
-        {
-            if (self.loadMapOperation == null)
-            {
-                return 0;
-            }
-            return (int)(self.loadMapOperation.progress * 100);
-        }
-    }
-}

+ 3 - 12
Codes/HotfixView/Client/Demo/Scene/SceneChangeStart_AddComponent.cs

@@ -1,3 +1,5 @@
+using UnityEngine.SceneManagement;
+
 namespace ET.Client
 {
     [Event(SceneType.Client)]
@@ -11,18 +13,7 @@ namespace ET.Client
             await ResourcesComponent.Instance.LoadBundleAsync($"{currentScene.Name}.unity3d");
             // 切换到map场景
 
-            SceneChangeComponent sceneChangeComponent = null;
-            try
-            {
-                sceneChangeComponent = Game.Scene.AddComponent<SceneChangeComponent>();
-                {
-                    await sceneChangeComponent.ChangeSceneAsync(currentScene.Name);
-                }
-            }
-            finally
-            {
-                sceneChangeComponent?.Dispose();
-            }
+            await SceneManager.LoadSceneAsync(currentScene.Name);
 			
 
             currentScene.AddComponent<OperaComponent>();

+ 0 - 11
Codes/ModelView/Client/Demo/Scene/SceneChangeComponent.cs

@@ -1,11 +0,0 @@
-using UnityEngine;
-
-namespace ET.Client
-{
-    [ComponentOf(typeof(Scene))]
-    public class SceneChangeComponent: Entity, IAwake, IUpdate, IDestroy
-    {
-        public AsyncOperation loadMapOperation;
-        public ETTask tcs;
-    }
-}