Parcourir la source

增加法术支持

大爷 il y a 2 ans
Parent
commit
786028a67b

+ 0 - 8
Unity/Assets/Scripts/Codes/Hotfix/Client/Unit.meta

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

+ 29 - 13
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr_Update.cs

@@ -1,4 +1,6 @@
-using CommonLang.Geometry;
+using CommonAI.Zone;
+using CommonAI.ZoneClient;
+using CommonLang.Geometry;
 using ET.Client;
 using ET.Client;
 using ET.EventType;
 using ET.EventType;
 using System;
 using System;
@@ -16,25 +18,39 @@ namespace ET
         private Vector3 VecTmp = new Vector3();
         private Vector3 VecTmp = new Vector3();
         private void SyncUnitPos()
         private void SyncUnitPos()
         {
         {
-            if(UnitMgr.Instance != null)
+            if (UnitMgr.Instance != null)
             {
             {
                 foreach (var obj in UnitMgr.Instance.AllUnits)
                 foreach (var obj in UnitMgr.Instance.AllUnits)
                 {
                 {
-                    if (obj is BattleUnit unit)
+                    if (obj is BattleUnit || obj is BattleSpell)
                     {
                     {
-                        var zu = unit.ZUnit;
-                        VecTmp.Set(zu.X, zu.Y, zu.Z);
-                        if (!VecTmp.Equal(unit.LastPos, 0.01f) || MathF.Abs(unit.LastRotation - zu.Direction) > 0.01f)
+                        /*if(obj is BattleSpell spell)
                         {
                         {
-                            EventSystem.Instance.Publish<SyncUnitPosEvent>(SyncUnitPosEvent.Static.Clone(unit.Id, VecTmp, zu.Direction));
-                            unit.LastPos.Set(VecTmp);
-                            unit.LastRotation = zu.Direction;
+                            var zs = spell.ZoneSpell;
+                            if (zs.Info.MType == CommonAI.Zone.SpellTemplate.MotionType.Foxfire)
+                            {
+                                if(zs.Target.ObjectID == 0 || zs.PassTimeMS > zs.Info.LifeTimeMS + 5000)
+                                {
+                                    PostMsg2Layer(new RemoveObjectEvent(zs.ObjectID));
+                                    return;
+                                }
+                            }
+                            else if(zs.PassTimeMS > zs.Info.LifeTimeMS + 150)
+                            {
+                                PostMsg2Layer(new RemoveObjectEvent(zs.ObjectID));
+                                return;
+                            }
+                        }*/
+
+                        var zo = obj.ZoneObject;
+                        VecTmp.Set(zo.X, zo.Y, zo.Z);
+                        if (!VecTmp.Equal(obj.LastPos, 0.01f) || MathF.Abs(obj.LastRotation - zo.Direction) > 0.01f)
+                        {
+                            EventSystem.Instance.Publish<SyncUnitPosEvent>(SyncUnitPosEvent.Static.Clone(zo.ObjectID, VecTmp, zo.Direction));
+                            obj.LastPos.Set(VecTmp);
+                            obj.LastRotation = zo.Direction;
                         }
                         }
                     }
                     }
-                    else if (obj is BattleSpell spell)
-                    {
-                        //TODO: spell
-                    }
                 }
                 }
             }
             }
         }
         }

+ 10 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/UnitMgr.cs

@@ -22,18 +22,28 @@ namespace ET.Client
             get { return UnitList.Values; }
             get { return UnitList.Values; }
         }
         }
 
 
+        public bool HasUnit(uint unitId)
+        {
+            return UnitList.ContainsKey(unitId);
+        }
         public BattleObject GetUnit(uint id)
         public BattleObject GetUnit(uint id)
         {
         {
             return UnitList.ContainsKey(id) ? UnitList[id] : null;
             return UnitList.ContainsKey(id) ? UnitList[id] : null;
         }
         }
         public void PutUnit(uint id, BattleObject obj)
         public void PutUnit(uint id, BattleObject obj)
         {
         {
+            if(UnitList.ContainsKey(id))
+            {
+                Log.Error($"Already exist unit({id}) @{obj}");
+                UnitList.Remove(id);
+            }
             UnitList[id] = obj;
             UnitList[id] = obj;
         }
         }
         public void RemoveUnit(uint id)
         public void RemoveUnit(uint id)
         {
         {
             if (UnitList.ContainsKey(id))
             if (UnitList.ContainsKey(id))
             {
             {
+                var unit = UnitList[id];
                 UnitList.Remove(id);
                 UnitList.Remove(id);
             }
             }
         }
         }

+ 5 - 6
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleObject.cs

@@ -1,12 +1,15 @@
 using CommonAI.ZoneClient;
 using CommonAI.ZoneClient;
+using CommonLang.Geometry;
 using ET;
 using ET;
 using ET.Client;
 using ET.Client;
 using ET.EventType;
 using ET.EventType;
 
 
 public class BattleObject
 public class BattleObject
 {
 {
-    protected ZoneObject ZoneObject;
+    public ZoneObject ZoneObject;
     public uint Id { get { return ZoneObject.ObjectID; } }
     public uint Id { get { return ZoneObject.ObjectID; } }
+    public Vector3 LastPos = Vector3.Zero;
+    public float LastRotation = 0;
 
 
     public BattleObject() { }
     public BattleObject() { }
 
 
@@ -18,11 +21,7 @@ public class BattleObject
 
 
     public virtual void OnSleep()
     public virtual void OnSleep()
     {
     {
-        AsyncSleep().Coroutine();
-    }
-    protected async ETTask AsyncSleep()
-    {
-        await EventSystem.Instance.PublishAsync(CurrentScene, new OnDestroyZoneObject() { ObjectId = Id });
+        EventSystem.Instance.Publish(CurrentScene, new OnDestroyZoneObject() { ObjectId = Id });
         ObjectPool.Instance.Recycle(this);
         ObjectPool.Instance.Recycle(this);
     }
     }
 
 

+ 38 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleSpell.cs

@@ -0,0 +1,38 @@
+using CommonAI.Zone;
+using CommonAI.ZoneClient;
+using CommonLang.Geometry;
+using ET;
+using ET.Client;
+using ET.EventType;
+using Sirenix.Utilities;
+using System;
+using System.Security.Claims;
+
+public class BattleSpell : BattleObject
+{
+    public Vector3 OriginPos;
+    public ZoneSpell ZoneSpell { get { return ZoneObject as ZoneSpell; } }
+
+    private LaunchEffect spawnEffect;
+
+    public override void OnAwake(ZoneObject zo)
+    {
+        base.OnAwake(zo);
+        var zs = zo as ZoneSpell;
+        OriginPos = new Vector3(zs.X, zs.Y, zs.LaunchHeight);
+
+        if(!zs.Info.FileNameSpawn.IsNullOrWhitespace())
+        {
+            if(spawnEffect == null)
+            {
+                spawnEffect = new LaunchEffect()
+                {
+                    Name = zs.Info.FileNameSpawn,
+                    SoundName = zs.Info.AudioName,
+                    IsLoop = zs.Info.IsAudioLoop
+                };
+            }
+            EventSystem.Instance.Publish<PlayEffectEvent>(PlayEffectEvent.Static.Clone(spawnEffect, zs.ObjectID, CommonLang.Geometry.Vector3.Zero));
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleSpell.cs.meta

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

+ 0 - 2
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleUnit.cs

@@ -12,8 +12,6 @@ public class BattleUnit : BattleObject
 {
 {
     public BattleUnit() { }
     public BattleUnit() { }
     public ZoneUnit ZUnit { get { return ZoneObject as ZoneUnit; } }
     public ZoneUnit ZUnit { get { return ZoneObject as ZoneUnit; } }
-    public Vector3 LastPos = Vector3.Zero;
-    public float LastRotation = 0;
 
 
     private EventDispatcher<UnitActionStatus, object> actionChangeHandler;
     private EventDispatcher<UnitActionStatus, object> actionChangeHandler;
 
 

+ 6 - 5
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnDestroyZoneObject.cs

@@ -7,15 +7,16 @@ namespace ET.Client
     {
     {
         protected override async ETTask Run(Scene scene, EventType.OnDestroyZoneObject args)
         protected override async ETTask Run(Scene scene, EventType.OnDestroyZoneObject args)
         {
         {
-            await DestroyUnitModel(args.ObjectId);
+            Log.Debug($"remove unit view: {args.ObjectId}");
+            DestroyUnitModel(args.ObjectId);
+            await ETTask.CompletedTask;
         }
         }
 
 
-        private async ETTask DestroyUnitModel(uint unitid)
+        private void DestroyUnitModel(uint unitid)
         {
         {
             ModelViewComponent.Instance?.RemoveChild(unitid);
             ModelViewComponent.Instance?.RemoveChild(unitid);
 
 
-            var unit = UnitMgr.Instance.GetUnit(unitid);
-            if (unit is BattleActor)
+            if (unitid == UnitMgr.Instance.ActorId)
             {
             {
                 //相机跟随主角
                 //相机跟随主角
                 //ModelViewComponent.Instance.AddComponent<CameraComponent>().Unit = unit;
                 //ModelViewComponent.Instance.AddComponent<CameraComponent>().Unit = unit;
@@ -24,7 +25,7 @@ namespace ET.Client
                 var camera = Camera.main;
                 var camera = Camera.main;
                 //camera.transform.position = new Vector3(unit.Position.x, 7, unit.Position.z - 15);
                 //camera.transform.position = new Vector3(unit.Position.x, 7, unit.Position.z - 15);
             }
             }
-            await ETTask.CompletedTask;
+            
         }
         }
     }
     }
 }
 }

+ 41 - 2
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnNewZoneObject.cs

@@ -1,4 +1,7 @@
-using UnityEngine;
+using CommonAI.ZoneClient;
+using Sirenix.Utilities;
+using System.Text.RegularExpressions;
+using UnityEngine;
 
 
 namespace ET.Client
 namespace ET.Client
 {
 {
@@ -12,6 +15,11 @@ namespace ET.Client
             {
             {
                 await CreatUnitModel(obj as BattleUnit);
                 await CreatUnitModel(obj as BattleUnit);
             }
             }
+            else if(obj is BattleSpell)
+            {
+                //TODO: 性能有问题时,可以减少法术展示
+                await CreateSpellModel(obj as BattleSpell);
+            }
             else
             else
             {
             {
                 Log.Error("unknow new object");
                 Log.Error("unknow new object");
@@ -24,9 +32,16 @@ namespace ET.Client
             var zu = unit.ZUnit;
             var zu = unit.ZUnit;
             
             
             var handle = await YooAssetProxy.LoadAssetAsync<GameObject>($"Unit_{zu.Info.FileName}");
             var handle = await YooAssetProxy.LoadAssetAsync<GameObject>($"Unit_{zu.Info.FileName}");
+            if(!UnitMgr.Instance.HasUnit(zu.ObjectID))
+            {
+                //还没显示就已挂掉的单位,走好
+                Log.Debug($"ignore dead unit: {zu}@{zu.ObjectID}");
+                return;
+            }
+
             var prefab = handle.GetAssetObject<GameObject>();
             var prefab = handle.GetAssetObject<GameObject>();
             GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.Unit, true);
             GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.Unit, true);
-            vecTemp.Set(unit.ZUnit.X, unit.ZUnit.Y, unit.ZUnit.Z);
+            vecTemp.Set(zu.X, zu.Y, zu.Z);
             go.transform.position = RenderUtils.UnityPosFromBattle(vecTemp);
             go.transform.position = RenderUtils.UnityPosFromBattle(vecTemp);
             go.transform.rotation = RenderUtils.UnityRotationFromBattle(zu.Direction);
             go.transform.rotation = RenderUtils.UnityRotationFromBattle(zu.Direction);
 
 
@@ -40,5 +55,29 @@ namespace ET.Client
 
 
             //TODO: 同步ZoneUnit status
             //TODO: 同步ZoneUnit status
         }
         }
+
+        private async ETTask CreateSpellModel(BattleSpell spell)
+        {
+            var zs = spell.ZoneObject as ZoneSpell;
+            //spell effect hack
+            var res = zs.Info.FileName;
+            var handle = await YooAssetProxy.LoadAssetAsync<GameObject>($"Effect_{res}");
+            if (!UnitMgr.Instance.HasUnit(zs.ObjectID) || !UnitMgr.Instance.HasUnit(zs.Sender.ObjectID))
+            {
+                //还没显示就已挂掉的单位,走好
+                Log.Debug($"ignore dead unit's spell: {zs.ObjectID}@{zs.Sender.ObjectID}");
+                return;
+            }
+
+            var prefab = handle.GetAssetObject<GameObject>();
+            GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.Unit, true);
+            vecTemp.Set(zs.X, zs.Y, zs.Z);
+            go.name = "spell_" + zs.ObjectID;
+            go.transform.localScale = Vector3.one * zs.Info.FileBodyScale;
+            go.transform.position = RenderUtils.UnityPosFromBattle(vecTemp);
+            go.transform.rotation = RenderUtils.UnityRotationFromBattle(zs.Direction);
+            ModelViewComponent.Instance.AddChildWithId<UnitRenderComponet, GameObject>(zs.ObjectID, go, true);
+            Log.Debug($"spellRender({zs.ObjectID}) ok.");
+        }
     }
     }
 }
 }

+ 30 - 22
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/UnitRenderSystem.cs

@@ -7,6 +7,7 @@ using ET.EventType;
 namespace ET.Client
 namespace ET.Client
 {
 {
     [Event(SceneType.Current)]
     [Event(SceneType.Current)]
+    [FriendOf(typeof(ET.Client.UnitRenderComponet))]
     public class AnimatorEventHandler : AEvent<EventType.PlayAnimatorEvent>
     public class AnimatorEventHandler : AEvent<EventType.PlayAnimatorEvent>
     {
     {
         protected override async ETTask Run(Scene scene, EventType.PlayAnimatorEvent args)
         protected override async ETTask Run(Scene scene, EventType.PlayAnimatorEvent args)
@@ -17,15 +18,23 @@ namespace ET.Client
                 Log.Debug($"Not found UnitRener of object{args.UnitId}");
                 Log.Debug($"Not found UnitRener of object{args.UnitId}");
                 return;
                 return;
             }
             }
-            if(args.CommandType == CMDType.Skill)
+            if (component.AniData == null)
+            {
+                var unit = UnitMgr.Instance.GetUnit(args.UnitId);
+                Log.Error($"UnitRender({unit?.ZoneObject}) not contains AnimationData component");
+                return;
+            }
+
+            if (args.CommandType == CMDType.Skill)
             {
             {
                 var m = Regex.Match(args.SkillName, "[Ss]kill(\\d+)");
                 var m = Regex.Match(args.SkillName, "[Ss]kill(\\d+)");
                 if (m.Success)
                 if (m.Success)
                 {
                 {
                     int n = System.Convert.ToInt32(m.Groups[1].Value, 10);
                     int n = System.Convert.ToInt32(m.Groups[1].Value, 10);
-                    if(n >=0 && AniType.SkillMax > AniType.Skill0 + n)
+                    if (n >= 0 && AniType.SkillMax > AniType.Skill0 + n)
                     {
                     {
-                        AnimatorCommand cmd = new AnimatorCommand((AniType)(AniType.Skill0 + n)) {
+                        AnimatorCommand cmd = new AnimatorCommand((AniType)(AniType.Skill0 + n))
+                        {
                             Duration = args.Duration,
                             Duration = args.Duration,
                             Speed = args.Speed,
                             Speed = args.Speed,
                             GroupId = args.GroupId,
                             GroupId = args.GroupId,
@@ -48,7 +57,7 @@ namespace ET.Client
                 };
                 };
                 component.AppendCommand(cmd);
                 component.AppendCommand(cmd);
             }
             }
-            
+
             await ETTask.CompletedTask;
             await ETTask.CompletedTask;
         }
         }
     }
     }
@@ -89,7 +98,12 @@ namespace ET.Client
             protected override void Awake(UnitRenderComponet self, GameObject go)
             protected override void Awake(UnitRenderComponet self, GameObject go)
             {
             {
                 self.GameObject = go;
                 self.GameObject = go;
-                self.Awake();
+
+                self.AniData = self.GameObject.GetComponent<Mono.AnimationData>();
+                if (self.AniData != null)
+                {
+                    self.ExeCommand(UnitRenderComponet.CMDIdle);
+                }
             }
             }
         }
         }
 
 
@@ -98,7 +112,13 @@ namespace ET.Client
         {
         {
             protected override void Update(UnitRenderComponet self)
             protected override void Update(UnitRenderComponet self)
             {
             {
-                self.Update();
+                if (self.AniData == null) { return; }
+
+                var cmd = self.FilterCmdList();
+                if (cmd != null)
+                {
+                    self.ExeCommand(cmd);
+                }
             }
             }
         }
         }
 
 
@@ -107,7 +127,10 @@ namespace ET.Client
         {
         {
             protected override void Destroy(UnitRenderComponet self)
             protected override void Destroy(UnitRenderComponet self)
             {
             {
-                self.AniData.Animancer.Stop();
+                if(self.AniData!= null)
+                { 
+                    self.AniData.Animancer.Stop();
+                }
                 UnityEngine.Object.Destroy(self.GameObject);
                 UnityEngine.Object.Destroy(self.GameObject);
             }
             }
         }
         }
@@ -119,21 +142,6 @@ namespace ET.Client
         }
         }
         //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
-        public static void Awake(this UnitRenderComponet self)
-        {
-            self.AniData = self.GameObject.GetComponent<Mono.AnimationData>();
-
-            self.ExeCommand(UnitRenderComponet.CMDIdle);
-        }
-
-        public static void Update(this UnitRenderComponet self)
-        {
-            var cmd = self.FilterCmdList();
-            if(cmd != null)
-            {
-                self.ExeCommand(cmd);
-            }
-        }
 
 
         //执行指令
         //执行指令
         private static void ExeCommand(this UnitRenderComponet self, AnimatorCommand cmd)
         private static void ExeCommand(this UnitRenderComponet self, AnimatorCommand cmd)