Browse Source

修改了客户端中当前主角unit的存取方法(去掉Actor字眼,以免跟服务器Actor框架混淆)

大爷 2 years ago
parent
commit
33338c88f4

+ 2 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Scene/SceneChangeHelper.cs

@@ -18,7 +18,8 @@
             // 等待CreateMyUnit的消息
             Wait_CreateMyUnit waitCreateMyUnit = await clientScene.GetComponent<ObjectWait>().Wait<Wait_CreateMyUnit>();
             M2C_CreateMyUnit m2CCreateMyUnit = waitCreateMyUnit.Message;
-            Unit unit = UnitFactory.Create(currentScene, m2CCreateMyUnit.Unit, true);
+            var unit = UnitFactory.Create(currentScene, m2CCreateMyUnit.Unit, true);
+            unitComponent.MyUnitId = unit.Id;
 
             clientScene.RemoveComponent<AIComponent>();
             clientScene.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());

+ 5 - 2
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Unit/UnitFactory.cs

@@ -4,15 +4,18 @@ namespace ET.Client
 {
     public static class UnitFactory
     {
+        public static Unit MyUnit { get; set; }
         public static Unit Create(Scene currentScene, UnitInfo unitInfo, bool isActor = false)
         {
 			Log.Debug($"Create unit :{unitInfo.UnitId}@{unitInfo.Type}");
 	        UnitComponent unitComponent = currentScene.GetComponent<UnitComponent>();
 	        Unit unit = unitComponent.AddChildWithId<Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);
-			unit.IsActor = isActor;
 	        unit.Position = unitInfo.Position;
 	        unit.Forward = unitInfo.Forward;
-            unitComponent.Add(unit);
+            if(isActor)
+            {
+                MyUnit = unit;
+            }
 
             NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
 			foreach (var kv in unitInfo.KV)

+ 0 - 17
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Unit/UnitComponentSystem.cs

@@ -1,22 +1,5 @@
 namespace ET
 {
-	[ObjectSystem]
-	public class UnitComponentAwakeSystem : AwakeSystem<UnitComponent>
-	{
-		protected override void Awake(UnitComponent self)
-		{
-            UnitComponent.Instance = self;
-		}
-	}
-	
-	[ObjectSystem]
-	public class UnitComponentDestroySystem : DestroySystem<UnitComponent>
-	{
-		protected override void Destroy(UnitComponent self)
-		{
-		}
-	}
-
     [FriendOfAttribute(typeof(ET.UnitComponent))]
     public static class UnitComponentSystem
     {

+ 0 - 9
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Unit/UnitSystem.cs

@@ -8,13 +8,4 @@
             self.ConfigId = configId;
         }
     }
-
-    [ObjectSystem]
-    public class UnitDestroySystem : DestroySystem<Unit>
-    {
-        protected override void Destroy(Unit self)
-        {
-            //TODO: 
-        }
-    }
 }

+ 4 - 2
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/SceneChangeFinishEvent_CreateHUD.cs

@@ -17,7 +17,8 @@ namespace ET.Client
             var img = view.GetChild("img_direction");
             view.GetChild("btn_skill1").onClick.Add(() => {
                 Scene currentScene = scene.GetComponent<CurrentScenesComponent>().Scene;
-                var actor = currentScene.GetComponent<UnitComponent>().GetActor();
+                var component = currentScene.GetComponent<UnitComponent>();
+                var actor = component.GetChild<Unit>(component.MyUnitId);
                 if(actor != null)
                 {
                     actor.GetComponent<AnimatorComponent>().AppendCommand(AnimatorComponent.CommandType.Skill0);
@@ -25,7 +26,8 @@ namespace ET.Client
             });
             view.GetChild("btn_skill2").onClick.Add(() => {
                 Scene currentScene = scene.GetComponent<CurrentScenesComponent>().Scene;
-                var actor = currentScene.GetComponent<UnitComponent>().GetActor();
+                var component = currentScene.GetComponent<UnitComponent>();
+                var actor = component.GetChild<Unit>(component.MyUnitId);
                 if (actor != null)
                 {
                     actor.GetComponent<AnimatorComponent>().AppendCommand(AnimatorComponent.CommandType.Skill1);

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

@@ -20,7 +20,8 @@ namespace ET.Client
             unit.AddComponent<GameObjectComponent>().GameObject = go;
             var aniComp = unit.AddComponent<AnimatorComponent>();
 
-            if (unit.IsActor)
+            var unitComponent = scene.GetComponent<UnitComponent>();
+            if (unit.Id == unitComponent.MyUnitId)
             {
                 //相机跟随主角
                 //unit.AddComponent<CameraComponent>().Unit = unit;

+ 5 - 2
Unity/Assets/Scripts/Codes/Model/Client/Demo/Unit/PlayerComponent.cs

@@ -1,8 +1,11 @@
 namespace ET.Client
 {
     [ComponentOf(typeof(Scene))]
-    public class PlayerComponent: Entity, IAwake
+    public class PlayerComponent: Entity, IAwake, IDestroy
     {
         public long MyId { get; set; }
+
+        [StaticField]
+        public static PlayerComponent Instance;
     }
-}
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/Module/Unit/Unit.cs

@@ -6,7 +6,7 @@ namespace ET
 {
     [ChildOf(typeof(UnitComponent))]
     [DebuggerDisplay("ViewName,nq")]
-    public class Unit: Entity, IAwake<int>, IDestroy
+    public class Unit: Entity, IAwake<int>
     {
         public int ConfigId { get; set; } //配置表id
 

+ 2 - 3
Unity/Assets/Scripts/Codes/Model/Share/Module/Unit/UnitComponent.cs

@@ -1,9 +1,8 @@
 namespace ET
 {
 	[ComponentOf(typeof(Scene))]
-	public class UnitComponent: Entity, IAwake, IDestroy
+	public class UnitComponent: Entity, IAwake
 	{
-        [StaticField]
-        public static UnitComponent Instance;
+        public long MyUnitId { get; set; }
 	}
 }