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

去掉从Game.Scene直接Get Scene,应该使用domain来获得

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

+ 1 - 6
Server/Hotfix/Demo/C2G_LoginGateHandler.cs

@@ -8,12 +8,7 @@ namespace ET
 	{
 		protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
 		{
-			Scene scene = Game.Scene.Get(request.GateId);
-			if (scene == null)
-			{
-				return;
-			}
-			
+			Scene scene = session.DomainScene();
 			string account = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
 			if (account == null)
 			{

+ 1 - 1
Server/Hotfix/Demo/SessionPlayerComponentSystem.cs

@@ -8,7 +8,7 @@ namespace ET
 		{
 			// 发送断线消息
 			ActorLocationSenderComponent.Instance.Send(self.Player.UnitId, new G2M_SessionDisconnect());
-			Game.Scene.GetComponent<PlayerComponent>()?.Remove(self.Player.Id);
+			self.Domain.GetComponent<PlayerComponent>()?.Remove(self.Player.Id);
 		}
 	}
 }

+ 1 - 1
Server/Hotfix/Scene/SceneFactory.cs

@@ -32,7 +32,7 @@ namespace ET
                     break;
                 case SceneType.Map:
                     scene.AddComponent<UnitComponent>();
-                    scene.AddComponent<RecastPathComponent>();
+                    //scene.AddComponent<RecastPathComponent>();
                     break;
                 case SceneType.Location:
                     scene.AddComponent<LocationComponent>();

+ 0 - 6
Server/Hotfix/Scene/SceneHelper.cs

@@ -1,6 +0,0 @@
-namespace ET
-{
-    public static class SceneHelper
-    {
-    }
-}

+ 1 - 1
Server/Model/Demo/GateSessionKeyComponent.cs

@@ -26,7 +26,7 @@ namespace ET
 
 		private async ETVoid TimeoutRemoveKey(long key)
 		{
-			await Game.Scene.GetComponent<TimerComponent>().WaitAsync(20000);
+			await TimerComponent.Instance.WaitAsync(20000);
 			this.sessionKey.Remove(key);
 		}
 	}

+ 1 - 3
Server/Model/Demo/MoveComponent.cs

@@ -34,8 +34,6 @@ namespace ET
             
             this.needTime = (long)(distance / this.Speed * 1000);
             
-            TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
-            
             // 协程如果取消,将算出玩家的真实位置,赋值给玩家
             cancellationToken?.Add(() =>
             {
@@ -54,7 +52,7 @@ namespace ET
             while (true)
             {
                 //新版TimerComponent实现不同于5.0的TimerComponent,需要自己判断是取消还是自然结束,并且return,否则将不会取消任务,并可能会造成cancellationToken泄漏
-                if (!await timerComponent.WaitAsync(50, cancellationToken))
+                if (!await TimerComponent.Instance.WaitAsync(50, cancellationToken))
                 {
                     return;
                 }

+ 15 - 0
Server/Model/Scene/SceneHelper.cs

@@ -0,0 +1,15 @@
+namespace ET
+{
+    public static class SceneHelper
+    {
+        public static int DomainZone(this Entity entity)
+        {
+            return ((Scene) entity.Domain)?.Zone ?? 0;
+        }
+
+        public static Scene DomainScene(this Entity entity)
+        {
+            return (Scene) entity.Domain;
+        }
+    }
+}

+ 2 - 2
Unity/Assets/Hotfix/Unit/M2C_CreateUnitsHandler.cs

@@ -8,7 +8,7 @@ namespace ET
 	{
 		protected override async ETVoid Run(Session session, M2C_CreateUnits message)
 		{	
-			UnitComponent unitComponent = Game.Scene.Get(1).GetComponent<UnitComponent>();
+			UnitComponent unitComponent = session.Domain.GetComponent<UnitComponent>();
 			
 			foreach (UnitInfo unitInfo in message.Units)
 			{
@@ -16,7 +16,7 @@ namespace ET
 				{
 					continue;
 				}
-				Unit unit = UnitFactory.Create(Game.Scene, unitInfo.UnitId);
+				Unit unit = UnitFactory.Create(session.Domain, unitInfo.UnitId);
 				unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
 			}
 

+ 1 - 1
Unity/Assets/Hotfix/Unit/UnitFactory.cs

@@ -14,7 +14,7 @@ namespace ET
 
 	        Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit});
 	        
-	        UnitComponent unitComponent = Game.Scene.Get(1).GetComponent<UnitComponent>();
+	        UnitComponent unitComponent = domain.GetComponent<UnitComponent>();
             unitComponent.Add(unit);
             return unit;
         }

+ 2 - 2
Unity/Assets/HotfixView/Opera/OperaComponentSystem.cs

@@ -33,7 +33,7 @@ namespace ET
                     self.frameClickMap.X = self.ClickPoint.x;
                     self.frameClickMap.Y = self.ClickPoint.y;
                     self.frameClickMap.Z = self.ClickPoint.z;
-                    self.ZoneScene().GetComponent<SessionComponent>().Session.Send(self.frameClickMap);
+                    self.DomainScene().GetComponent<SessionComponent>().Session.Send(self.frameClickMap);
 
                     // 测试actor rpc消息
                     self.TestActor().Coroutine();
@@ -45,7 +45,7 @@ namespace ET
         {
             try
             {
-                M2C_TestActorResponse response = (M2C_TestActorResponse)await self.ZoneScene().GetComponent<SessionComponent>().Session.Call(
+                M2C_TestActorResponse response = (M2C_TestActorResponse)await self.Domain.GetComponent<SessionComponent>().Session.Call(
                     new C2M_TestActorRequest() { Info = "actor rpc request" });
                 Log.Info(response.Info);
             }

+ 0 - 10
Unity/Assets/HotfixView/Scene/SceneHelper.cs

@@ -1,10 +0,0 @@
-namespace ET
-{
-    public static class SceneHelper
-    {
-        public static Scene ZoneScene(this Entity entity)
-        {
-            return Game.Scene.Get(entity.DomainZone());
-        }
-    }
-}

+ 1 - 2
Unity/Assets/HotfixView/UI/UILoading/UILoadingComponentSystem.cs

@@ -20,11 +20,10 @@ namespace ET
 		
         public async ETVoid StartAsync(UILoadingComponent self)
         {
-            TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
             long instanceId = self.InstanceId;
             while (true)
             {
-                await timerComponent.WaitAsync(1000);
+                await TimerComponent.Instance.WaitAsync(1000);
 
                 if (self.InstanceId != instanceId)
                 {

+ 2 - 2
Unity/Assets/HotfixView/UI/UILobby/EnterMapFinish_RemoveLobbyUI.cs

@@ -5,13 +5,13 @@
 		protected override async ETTask Run(EventType.EnterMapFinish args)
 		{
 			// 加载场景资源
-			await Game.Scene.GetComponent<ResourcesComponent>().LoadBundleAsync("map.unity3d");
+			await ResourcesComponent.Instance.LoadBundleAsync("map.unity3d");
 			// 切换到map场景
 			using (SceneChangeComponent sceneChangeComponent = Game.Scene.AddComponent<SceneChangeComponent>())
 			{
 				await sceneChangeComponent.ChangeSceneAsync("Map");
 			}
-            Game.Scene.Get(1).AddComponent<OperaComponent>();
+            args.ZoneScene.AddComponent<OperaComponent>();
             await UIHelper.Remove(args.ZoneScene, UIType.UILobby);
 		}
 	}

+ 1 - 2
Unity/Assets/HotfixView/Unit/AfterUnitCreate_CreateUnitView.cs

@@ -7,8 +7,7 @@ namespace ET
         protected override async ETTask Run(EventType.AfterUnitCreate args)
         {
             // Unit View层
-            ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
-            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
+            GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset("Unit.unity3d", "Unit");
             GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
 	        
             GameObject go = UnityEngine.Object.Instantiate(prefab);

+ 0 - 13
Unity/Assets/Model/Core/Entity/Scene.cs

@@ -95,17 +95,4 @@
             }
         }
     }
-
-    public static class SceneEx
-    {
-        public static int DomainZone(this Entity entity)
-        {
-            return ((Scene) entity.Domain)?.Zone ?? 0;
-        }
-
-        public static Scene DomainScene(this Entity entity)
-        {
-            return (Scene) entity.Domain;
-        }
-    }
 }

+ 1 - 1
Unity/Assets/Model/Module/NetworkTCP/TChannel.cs

@@ -392,7 +392,7 @@ namespace ET
 
 		private void OnError(int error)
 		{
-			Log.Error($"TChannel error: {error} {this.RemoteAddress}");
+			Log.Info($"TChannel OnError: {error} {this.RemoteAddress}");
 			
 			long channelId = this.Id;
 			

+ 8 - 0
Unity/Assets/Model/Scene.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: da44f331d6f7c4109be8c2a5f7672697
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

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

@@ -0,0 +1,20 @@
+namespace ET
+{
+    public static class SceneHelper
+    {
+        public static int DomainZone(this Entity entity)
+        {
+            return ((Scene) entity.Domain)?.Zone ?? 0;
+        }
+
+        public static Scene DomainScene(this Entity entity)
+        {
+            return (Scene) entity.Domain;
+        }
+        
+        public static Scene ZoneScene(this Entity entity)
+        {
+            return Game.Scene.Get(entity.DomainZone());
+        }
+    }
+}

+ 1 - 1
Unity/Assets/HotfixView/Scene/SceneHelper.cs.meta → Unity/Assets/Model/Scene/SceneHelper.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 6fb064924cd4a4931b7173149810fee1
+guid: fb19b78af7c6247eda3a57d99d387695
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 1
Unity/Unity.HotfixView.csproj

@@ -58,7 +58,6 @@
      <Compile Include="Assets\HotfixView\UI\UILoading\LoadingFinishEvent_RemoveLoadingUI.cs" />
      <Compile Include="Assets\HotfixView\UI\UILobby\UILobbyComponentSystem.cs" />
      <Compile Include="Assets\HotfixView\Unit\AfterUnitCreate_CreateUnitView.cs" />
-     <Compile Include="Assets\HotfixView\Scene\SceneHelper.cs" />
      <Compile Include="Assets\HotfixView\Module\UI\UIComponentSystem.cs" />
      <Compile Include="Assets\HotfixView\Module\UI\UIEventComponentSystem.cs" />
      <Compile Include="Assets\HotfixView\UI\UILogin\UILoginEvent.cs" />

+ 1 - 0
Unity/Unity.Model.csproj

@@ -201,6 +201,7 @@
      <Compile Include="Assets\Model\Module\NetworkTCP\TChannel.cs" />
      <Compile Include="Assets\Model\Module\Network\AChannel.cs" />
      <Compile Include="Assets\Model\Unit\UnitPathComponent.cs" />
+     <Compile Include="Assets\Model\Scene\SceneHelper.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>