Просмотр исходного кода

增加客户端ZoneScene管理组件

tanghai 4 лет назад
Родитель
Сommit
ca6ca881d2

+ 20 - 0
Unity/Assets/Hotfix/Scene/ZoneSceneFlagComponentSystem.cs

@@ -0,0 +1,20 @@
+namespace ET
+{
+    [ObjectSystem]
+    public class ZoneSceneFlagComponentDestroySystem: DestroySystem<ZoneSceneFlagComponent>
+    {
+        public override void Destroy(ZoneSceneFlagComponent self)
+        {
+            ZoneSceneManagerComponent.Instance.Remove(self.DomainZone());
+        }
+    }
+
+    [ObjectSystem]
+    public class ZoneSceneFlagComponentAwakeSystem: AwakeSystem<ZoneSceneFlagComponent>
+    {
+        public override void Awake(ZoneSceneFlagComponent self)
+        {
+            ZoneSceneManagerComponent.Instance.Add(self.GetParent<Scene>());
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Hotfix/Scene/ZoneSceneFlagComponentSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8b061d707010d4e7a88210329303ed2d
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 46 - 0
Unity/Assets/Hotfix/Scene/ZoneSceneManagerComponentSystem.cs

@@ -0,0 +1,46 @@
+using System;
+
+namespace ET
+{
+    [ObjectSystem]
+    public class ZoneSceneManagerComponentAwakeSystem: AwakeSystem<ZoneSceneManagerComponent>
+    {
+        public override void Awake(ZoneSceneManagerComponent self)
+        {
+            ZoneSceneManagerComponent.Instance = self;
+        }
+    }
+
+    [ObjectSystem]
+    public class ZoneSceneManagerComponentDestroySystem: DestroySystem<ZoneSceneManagerComponent>
+    {
+        public override void Destroy(ZoneSceneManagerComponent self)
+        {
+            self.ZoneScenes.Clear();
+        }
+    }
+
+    public static class ZoneSceneManagerComponentSystem
+    {
+        public static Scene ZoneScene(this Entity entity)
+        {
+            return ZoneSceneManagerComponent.Instance.Get(entity.DomainZone());
+        }
+        
+        public static void Add(this ZoneSceneManagerComponent self, Scene zoneScene)
+        {
+            self.ZoneScenes.Add(zoneScene.Zone, zoneScene);
+        }
+        
+        public static Scene Get(this ZoneSceneManagerComponent self, int zone)
+        {
+            self.ZoneScenes.TryGetValue(zone, out Scene scene);
+            return scene;
+        }
+        
+        public static void Remove(this ZoneSceneManagerComponent self, int zone)
+        {
+            self.ZoneScenes.Remove(zone);
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Hotfix/Scene/ZoneSceneManagerComponentSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c2423cb9483454d4a9dcca62dc958272
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

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

@@ -20,9 +20,11 @@ namespace ET
             
             Game.Scene.AddComponent<NetThreadComponent>();
 
+            Game.Scene.AddComponent<ZoneSceneManagerComponent>();
+
             ResourcesComponent.Instance.LoadBundle("unit.unity3d");
 
-            Scene zoneScene = await SceneFactory.CreateZoneScene(1, 1, "Game");
+            Scene zoneScene = await SceneFactory.CreateZoneScene(1, "Process");
 
             await Game.EventSystem.Publish(new EventType.AppStartInitFinish() { ZoneScene = zoneScene });
         }

+ 3 - 3
Unity/Assets/HotfixView/Scene/SceneFactory.cs

@@ -2,10 +2,10 @@ namespace ET
 {
     public static class SceneFactory
     {
-        public static async ETTask<Scene> CreateZoneScene(long id, int zone, string name)
+        public static async ETTask<Scene> CreateZoneScene(int zone, string name)
         {
-            Scene zoneScene = EntitySceneFactory.CreateScene(id, zone, SceneType.Zone, name, Game.Scene);
-            
+            Scene zoneScene = EntitySceneFactory.CreateScene(Game.IdGenerater.GenerateId(), zone, SceneType.Zone, name, Game.Scene);
+            zoneScene.AddComponent<ZoneSceneFlagComponent>();
             zoneScene.AddComponent<NetKcpComponent>();
             zoneScene.AddComponent<UnitComponent>();
             

+ 0 - 5
Unity/Assets/Model/Scene/SceneHelper.cs

@@ -11,10 +11,5 @@ namespace ET
         {
             return (Scene) entity.Domain;
         }
-        
-        public static Scene ZoneScene(this Entity entity)
-        {
-            return Game.Scene.Get(entity.DomainZone());
-        }
     }
 }

+ 8 - 0
Unity/Assets/Model/Scene/ZoneSceneFlagComponent.cs

@@ -0,0 +1,8 @@
+using System.Collections.Generic;
+
+namespace ET
+{
+    public class ZoneSceneFlagComponent: Entity
+    {
+    }
+}

+ 11 - 0
Unity/Assets/Model/Scene/ZoneSceneFlagComponent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8bf9ded844f734e0f96139486607da26
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 0
Unity/Assets/Model/Scene/ZoneSceneManagerComponent.cs

@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+
+namespace ET
+{
+    public class ZoneSceneManagerComponent: Entity
+    {
+        public static ZoneSceneManagerComponent Instance;
+        public Dictionary<int, Scene> ZoneScenes = new Dictionary<int, Scene>();
+    }
+}

+ 11 - 0
Unity/Assets/Model/Scene/ZoneSceneManagerComponent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: dff0dc04282044a00b49a830dfe34418
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 0
Unity/Unity.Hotfix.csproj

@@ -72,6 +72,8 @@
      <Compile Include="Assets\Hotfix\Unit\TurnComponentSystem.cs" />
      <Compile Include="Assets\Hotfix\Session\SessionComponentSystem.cs" />
      <Compile Include="Assets\Hotfix\Module\Message\SessionAcceptTimeoutComponentSystem.cs" />
+     <Compile Include="Assets\Hotfix\Scene\ZoneSceneFlagComponentSystem.cs" />
+     <Compile Include="Assets\Hotfix\Scene\ZoneSceneManagerComponentSystem.cs" />
      <None Include="Assets\Hotfix\Unity.Hotfix.asmdef" />
  <Reference Include="UnityEngine">
  <HintPath>/Applications/Unity/Hub/Editor/2020.2.2f1c1/Unity.app/Contents/Managed/UnityEngine/UnityEngine.dll</HintPath>

+ 2 - 0
Unity/Unity.Model.csproj

@@ -202,6 +202,8 @@
      <Compile Include="Assets\Model\Module\Network\AChannel.cs" />
      <Compile Include="Assets\Model\Unit\UnitPathComponent.cs" />
      <Compile Include="Assets\Model\Scene\SceneHelper.cs" />
+     <Compile Include="Assets\Model\Scene\ZoneSceneManagerComponent.cs" />
+     <Compile Include="Assets\Model\Scene\ZoneSceneFlagComponent.cs" />
      <None Include="Assets\Model\Unity.Model.asmdef" />
  <Reference Include="UnityEngine">
  <HintPath>/Applications/Unity/Hub/Editor/2020.2.2f1c1/Unity.app/Contents/Managed/UnityEngine/UnityEngine.dll</HintPath>