tanghai пре 8 година
родитељ
комит
fa124da7b7

+ 1 - 0
.gitignore

@@ -40,3 +40,4 @@ _ReSharper.CSharp/
 /Excel/md5.txt
 /Release
 .idea/
+/Unity/Logs

+ 1 - 0
Server/App/Program.cs

@@ -98,6 +98,7 @@ namespace App
 						Game.Scene.AddComponent<RealmGateAddressComponent>();
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
 						Game.Scene.AddComponent<ConfigComponent>();
+						Game.Scene.AddComponent<ServerFrameComponent>();
 						break;
 					case AppType.Benchmark:
 						Game.Scene.AddComponent<NetOuterComponent>();

+ 2 - 2
Server/Hotfix/Handler/G2M_CreateUnitHandler.cs

@@ -11,7 +11,7 @@ namespace Hotfix
 			M2G_CreateUnit response = new M2G_CreateUnit();
 			try
 			{
-				Unit unit = EntityFactory.Create<Unit, UnitType>(UnitType.Hero);
+				Unit unit = EntityFactory.Create<Unit>();
 				await unit.AddComponent<ActorComponent, IEntityActorHandler>(new MapUnitEntityActorHandler()).AddLocation();
 				unit.AddComponent<UnitGateComponent, long>(message.GateSessionId);
 				Game.Scene.GetComponent<UnitComponent>().Add(unit);
@@ -28,7 +28,7 @@ namespace Hotfix
 					{
 						actorCreateUnits.Units.Add(new UnitInfo() {UnitId = u.Id, X = (int)(u.Position.X * 1000), Z = (int)(u.Position.Z * 1000) });
 					}
-
+					Log.Debug($"{MongoHelper.ToJson(actorCreateUnits)}");
 					MessageHelper.Broadcast(actorCreateUnits);
 				}
 			}

+ 10 - 2
Server/Hotfix/Other/EntityActorHandler.cs

@@ -4,7 +4,7 @@ using Model;
 namespace Hotfix
 {
     /// <summary>
-    /// gate session 收到的消息直接转发给客户端
+    /// gate session收到的消息直接转发给客户端
     /// </summary>
     public class GateSessionEntityActorHandler : IEntityActorHandler
     {
@@ -36,7 +36,15 @@ namespace Hotfix
         {
             if (message.AMessage is AFrameMessage aFrameMessage)
             {
-                Game.Scene.GetComponent<ServerFrameComponent>().Add(aFrameMessage);
+				// 客户端发送不需要设置Frame消息的id,在这里统一设置,防止客户端被破解发个假的id过来
+	            aFrameMessage.Id = entity.Id;
+				Game.Scene.GetComponent<ServerFrameComponent>().Add(aFrameMessage);
+	            ActorResponse response = new ActorResponse
+	            {
+		            RpcId = message.RpcId
+	            };
+	            session.Reply(response);
+				return;
             }
             await Game.Scene.GetComponent<ActorMessageDispatherComponent>().Handle(session, entity, message);
         }

+ 1 - 2
Server/Model/Component/ActorMessageDispatherComponent.cs

@@ -75,8 +75,7 @@ namespace Model
 		{
 			if (!this.handlers.TryGetValue(message.AMessage.GetType(), out IMActorHandler handler))
 			{
-				Log.Error($"not found message handler: {MongoHelper.ToJson(message)}");
-				return;
+				throw new Exception($"not found message handler: {MongoHelper.ToJson(message)}");
 			}
 			
 			await handler.Handle(session, entity, message);

+ 3 - 3
Unity/Assets/Editor/BuildEditor/BuildEditor.cs

@@ -59,7 +59,7 @@ namespace MyEditor
 			string[] levels2 = {
 				"Assets/Scenes/Init.unity",
 			};
-			BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/football.exe", BuildTarget.StandaloneWindows, option);
+			BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/et.exe", BuildTarget.StandaloneWindows, option);
 			Log.Info("打包完成");
 		}
 
@@ -71,7 +71,7 @@ namespace MyEditor
 			string[] levels2 = {
 				"Assets/Scenes/Init.unity",
 			};
-			BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/football.apk", BuildTarget.Android, option);
+			BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/et.apk", BuildTarget.Android, option);
 			Log.Info("打包完成");
 		}
 
@@ -81,7 +81,7 @@ namespace MyEditor
 			string[] levels2 = {
 				"Assets/Scenes/Init.unity",
 			};
-			BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/football.apk", BuildTarget.Android, option);
+			BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/et.apk", BuildTarget.Android, option);
 			Log.Info("打包APK完成");
 		}
 

+ 30 - 2
Unity/Assets/Res/Unit/Skeleton/Ani/Skeleton@Idle.FBX.meta

@@ -86,7 +86,7 @@ ModelImporter:
     400078: //RootNode
     4300000: Object02
     4300002: Object01
-    7400000: Take 001
+    7400000: Idle
     9500000: //RootNode
     13700000: Object01
     13700002: Object02
@@ -113,7 +113,35 @@ ModelImporter:
     animationWrapMode: 0
     extraExposedTransformPaths: []
     extraUserProperties: []
-    clipAnimations: []
+    clipAnimations:
+    - serializedVersion: 16
+      name: Idle
+      takeName: Take 001
+      firstFrame: 0
+      lastFrame: 170
+      wrapMode: 0
+      orientationOffsetY: 0
+      level: 0
+      cycleOffset: 0
+      loop: 0
+      hasAdditiveReferencePose: 0
+      loopTime: 1
+      loopBlend: 0
+      loopBlendOrientation: 0
+      loopBlendPositionY: 0
+      loopBlendPositionXZ: 0
+      keepOriginalOrientation: 0
+      keepOriginalPositionY: 1
+      keepOriginalPositionXZ: 0
+      heightFromFeet: 0
+      mirror: 0
+      bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
+      curves: []
+      events: []
+      transformMask: []
+      maskType: 3
+      maskSource: {instanceID: 0}
+      additiveReferencePoseFrame: 0
     isReadable: 1
   meshes:
     lODScreenPercentages: []

+ 30 - 2
Unity/Assets/Res/Unit/Skeleton/Ani/Skeleton@Run.FBX.meta

@@ -86,7 +86,7 @@ ModelImporter:
     400078: //RootNode
     4300000: Object02
     4300002: Object01
-    7400000: Take 001
+    7400000: Run
     9500000: //RootNode
     13700000: Object01
     13700002: Object02
@@ -113,7 +113,35 @@ ModelImporter:
     animationWrapMode: 0
     extraExposedTransformPaths: []
     extraUserProperties: []
-    clipAnimations: []
+    clipAnimations:
+    - serializedVersion: 16
+      name: Run
+      takeName: Take 001
+      firstFrame: 0
+      lastFrame: 30
+      wrapMode: 0
+      orientationOffsetY: 0
+      level: 0
+      cycleOffset: 0
+      loop: 0
+      hasAdditiveReferencePose: 0
+      loopTime: 1
+      loopBlend: 0
+      loopBlendOrientation: 0
+      loopBlendPositionY: 0
+      loopBlendPositionXZ: 0
+      keepOriginalOrientation: 0
+      keepOriginalPositionY: 1
+      keepOriginalPositionXZ: 0
+      heightFromFeet: 0
+      mirror: 0
+      bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
+      curves: []
+      events: []
+      transformMask: []
+      maskType: 3
+      maskSource: {instanceID: 0}
+      additiveReferencePoseFrame: 0
     isReadable: 1
   meshes:
     lODScreenPercentages: []

+ 2 - 2
Unity/Assets/Scenes/Init.unity

@@ -122,7 +122,7 @@ GameObject:
   - component: {fileID: 29794236}
   m_Layer: 0
   m_Name: MainCamera
-  m_TagString: Untagged
+  m_TagString: MainCamera
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
@@ -133,7 +133,7 @@ AudioListener:
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 0}
   m_GameObject: {fileID: 29794235}
-  m_Enabled: 1
+  m_Enabled: 0
 --- !u!92 &29794237
 Behaviour:
   m_ObjectHideFlags: 0

+ 4 - 4
Unity/Assets/Scripts/Base/Log.cs

@@ -13,17 +13,17 @@ namespace Model
 #if UNITY_EDITOR
 		private static bool IsNeedFlush = true;
 #else
-		private static bool IsNeedFlush = false;
+		private static bool IsNeedFlush = true;
 #endif
 
 		static Log()
 		{
 			if (!Directory.Exists("../Logs"))
 			{
-				Directory.CreateDirectory("../Logs");
+				Directory.CreateDirectory("./Logs");
 			}
-			info = new StreamWriter("../Logs/Log-Client-Info.txt", false, Encoding.Unicode, 1024);
-			error = new StreamWriter("../Logs/Log-Client-Error.txt", false, Encoding.Unicode, 1024);
+			info = new StreamWriter("./Logs/Log-Client-Info.txt", false, Encoding.Unicode, 1024);
+			error = new StreamWriter("./Logs/Log-Client-Error.txt", false, Encoding.Unicode, 1024);
 		}
 
 		public static void Warning(string msg)

+ 19 - 6
Unity/Assets/Scripts/Component/OperaComponent.cs

@@ -3,28 +3,41 @@
 namespace Model
 {
     [ObjectEvent]
-    public class OperaComponentEvent : ObjectEvent<OperaComponent>, IUpdate
+    public class OperaComponentEvent : ObjectEvent<OperaComponent>, IUpdate, IAwake
     {
         public void Update()
         {
             this.Get().Update();
         }
+
+	    public void Awake()
+	    {
+		    this.Get().Awake();
+	    }
     }
 
     public class OperaComponent: Component
     {
         public Vector3 ClickPoint;
 
+	    public int mapMask;
+
+	    public void Awake()
+	    {
+		    this.mapMask = LayerMask.GetMask("Map");
+	    }
+
         public void Update()
         {
-            if (Input.GetMouseButtonUp(0))
+            if (Input.GetMouseButtonDown(1))
             {
                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 RaycastHit hit;
-                Physics.Raycast(ray, out hit, 1000);
-                this.ClickPoint = hit.point;
-                Log.Debug($"click {this.ClickPoint}");
-                SessionComponent.Instance.Session.Send(new Frame_ClickMap() {X = (int)(this.ClickPoint.x * 1000), Z = (int)(this.ClickPoint.z * 1000)});
+	            if (Physics.Raycast(ray, out hit, 1000, this.mapMask))
+	            {
+					this.ClickPoint = hit.point;
+		            SessionComponent.Instance.Session.Send(new Frame_ClickMap() { X = (int)(this.ClickPoint.x * 1000), Z = (int)(this.ClickPoint.z * 1000) });
+				}
             }
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Entity/Message/OuterMessage.cs

@@ -90,7 +90,7 @@ namespace Model
 	[Message(Opcode.Actor_CreateUnits)]
 	public class Actor_CreateUnits : AActorMessage
 	{
-		public List<UnitInfo> Units;
+		public List<UnitInfo> Units = new List<UnitInfo>();
 	}
 
 	public struct FrameMessageInfo

+ 3 - 3
Unity/Assets/Scripts/Entity/Session.cs

@@ -143,7 +143,7 @@ namespace Model
 						tcs.SetException(new RpcException(response.Error, response.Message));
 						return;
 					}
-					//Log.Debug($"recv: {response.ToJson()}");
+					Log.Debug($"recv: {MongoHelper.ToJson(response)}");
 					tcs.SetResult(response);
 				}
 				catch (Exception e)
@@ -176,7 +176,7 @@ namespace Model
 						tcs.SetException(new RpcException(response.Error, response.Message));
 						return;
 					}
-					//Log.Debug($"recv: {JsonHelper.ToJson(response)}");
+					Log.Debug($"recv: {MongoHelper.ToJson(response)}");
 					tcs.SetResult(response);
 				}
 				catch (Exception e)
@@ -208,7 +208,7 @@ namespace Model
 
 		private void SendMessage(object message)
 		{
-			//Log.Debug($"send: {message.ToJson()}");
+			Log.Debug($"send: {MongoHelper.ToJson(message)}");
 			ushort opcode = this.network.Entity.GetComponent<OpcodeTypeComponent>().GetOpcode(message.GetType());
 			opcode = NetworkHelper.HostToNetworkOrder(opcode);
 			byte[] opcodeBytes = BitConverter.GetBytes(opcode);

+ 2 - 9
Unity/Assets/Scripts/Entity/Unit.cs

@@ -9,25 +9,18 @@ namespace Model
 	}
 
 	[ObjectEvent]
-	public class UnitEvent : ObjectEvent<Unit>, IAwake<UnitType>
+	public class UnitEvent : ObjectEvent<Unit>
 	{
-		public void Awake(UnitType unitType)
-		{
-			this.Get().Awake(unitType);
-		}
 	}
 
 	public sealed class Unit: Entity
 	{
-		public UnitType UnitType { get; private set; }
-
 		public VInt3 IntPos;
 
 		public GameObject GameObject;
 		
-		public void Awake(UnitType unitType)
+		public void Awake()
 		{
-			this.UnitType = unitType;
 		}
 
 		public Vector3 Position

+ 6 - 4
Unity/Assets/Scripts/Factory/UnitFactory.cs

@@ -8,10 +8,12 @@ namespace Model
         {
             UnitComponent unitComponent = Game.Scene.GetComponent<UnitComponent>();
             GameObject prefab = ((GameObject) Resources.Load("Unit")).Get<GameObject>("Skeleton");
-            Unit unit = EntityFactory.CreateWithId<Unit>(id);
-            unit.GameObject = UnityEngine.Object.Instantiate(prefab);
-
-	        unit.AddComponent<AnimatorComponent>();
+            
+	        Unit unit = EntityFactory.CreateWithId<Unit>(id);
+	        unit.GameObject = UnityEngine.Object.Instantiate(prefab);
+	        GameObject parent = GameObject.Find($"/Global/Unit");
+	        unit.GameObject.transform.SetParent(parent.transform, false);
+			unit.AddComponent<AnimatorComponent>();
 	        unit.AddComponent<MoveComponent>();
 
             unitComponent.Add(unit);

+ 8 - 0
Unity/Assets/Scripts/Handler/Actor_CreateUnitsHandler.cs

@@ -7,8 +7,14 @@ namespace Model
 	{
 		protected override void Run(Actor_CreateUnits message)
 		{
+			UnitComponent unitComponent = Game.Scene.GetComponent<UnitComponent>();
+			
 			foreach (UnitInfo unitInfo in message.Units)
 			{
+				if (unitComponent.Get(unitInfo.UnitId) != null)
+				{
+					continue;
+				}
 				Unit unit = UnitFactory.Create(unitInfo.UnitId);
 				unit.Position = new Vector3(unitInfo.X / 1000f, 0, unitInfo.Z / 1000f);
 				unit.IntPos = new VInt3(unitInfo.X, 0, unitInfo.Z);
@@ -18,6 +24,8 @@ namespace Model
 					Game.Scene.GetComponent<CameraComponent>().Unit = unit;
 				}
 			}
+
+			Game.Scene.AddComponent<OperaComponent>();
 		}
 	}
 }

+ 17 - 0
Unity/Assets/Scripts/Handler/Frame_ClickMapHandler.cs

@@ -0,0 +1,17 @@
+using UnityEngine;
+
+namespace Model
+{
+	[MessageHandler(Opcode.Frame_ClickMap)]
+	public class Frame_ClickMapHandler : AMHandler<Frame_ClickMap>
+	{
+		protected override void Run(Frame_ClickMap message)
+		{
+			Unit unit = Game.Scene.GetComponent<UnitComponent>().Get(message.Id);
+			MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
+			Vector3 dest = new Vector3(message.X / 1000f, 0, message.Z / 1000f);
+			moveComponent.MoveToDest(dest, 1);
+			moveComponent.Turn2D(dest - unit.Position);
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Handler/Frame_ClickMapHandler.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0a3b051014f045a4a99326f1c047933f
+timeCreated: 1506307390
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Assets/Scripts/Init.cs

@@ -66,6 +66,7 @@ namespace Model
 				Game.Scene.AddComponent<ConfigComponent>();
 				Game.Scene.AddComponent<PlayerComponent>();
 				Game.Scene.AddComponent<UnitComponent>();
+				Game.Scene.AddComponent<ClientFrameComponent>();
 
 				// 进入热更新层
 				this.start.Run();

+ 0 - 9
Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs

@@ -82,15 +82,6 @@ namespace Hotfix
 			try
 			{
 				G2C_EnterMap g2CEnterMap = await SessionComponent.Instance.Session.Call<G2C_EnterMap>(new C2G_EnterMap());
-				UnitFactory.Create(g2CEnterMap.UnitId);
-
-				if (g2CEnterMap.Count < 1)
-				{
-					this.enterMap.SetActive(false);
-					this.text.text = $"房间中已有:{g2CEnterMap.Count}人";
-					return;
-				}
-				
 				Hotfix.Scene.GetComponent<UIComponent>().Remove(UIType.Lobby);
 			}
 			catch (Exception e)

+ 5 - 0
Unity/Hotfix/UI/UILogin/Component/UILoginComponent.cs

@@ -42,6 +42,11 @@ namespace Hotfix
 				G2C_LoginGate g2CLoginGate = await SessionComponent.Instance.Session.Call<G2C_LoginGate>(new C2G_LoginGate(r2CLogin.Key));
 				Log.Info("登陆gate成功!");
 
+				// 创建Player
+				Player player = Model.EntityFactory.CreateWithId<Player>(g2CLoginGate.PlayerId);
+				PlayerComponent playerComponent = Game.Scene.GetComponent<PlayerComponent>();
+				playerComponent.MyPlayer = player;
+
 				Hotfix.Scene.GetComponent<UIComponent>().Create(UIType.Lobby);
 				Hotfix.Scene.GetComponent<UIComponent>().Remove(UIType.Login);
 			}

+ 1 - 0
Unity/Unity.csproj

@@ -553,6 +553,7 @@
     <Compile Include="Assets\Scripts\Factory\PlayerFactory.cs" />
     <Compile Include="Assets\Scripts\Factory\UnitFactory.cs" />
     <Compile Include="Assets\Scripts\Handler\Actor_CreateUnitsHandler.cs" />
+    <Compile Include="Assets\Scripts\Handler\Frame_ClickMapHandler.cs" />
     <Compile Include="Assets\Scripts\Handler\Actor_TestHandler.cs" />
     <Compile Include="Assets\Scripts\Helper\ActionHelper.cs" />
     <Compile Include="Assets\Scripts\Helper\DllHelper.cs" />