Browse Source

增加单位破损特效以及更换模型

大爷 1 year ago
parent
commit
cf1bef06b5

+ 58 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr.cs

@@ -9,6 +9,7 @@ using Sirenix.Utilities;
 using System;
 using System.IO;
 using System.Linq;
+using System.Text.RegularExpressions;
 using XmdsCommon.Message;
 
 namespace ET
@@ -156,6 +157,44 @@ namespace ET
             return UnitTemplateIdHash.ContainsKey(tid) ? UnitTemplateIdHash[tid] : null;
         }
 
+        public async ETTask ProcessLauncheffectTag(uint objectid, string tag)
+        {
+            //Effect支持Tag设置Event,格式:Event:事件名(事件参数)
+            Match m = Regex.Match(tag, @"^@(\w+)\(([\w\d\s_,]+)\)");
+            if (m.Groups.Count >= 3)
+            {
+                string name = m.Groups[1].Value;
+                string param = m.Groups[2].Value;
+                switch (name)
+                {
+                    case "ChangeMode":
+                        var ps = param.Split(',');
+                        if (ps.Length > 1)
+                        {
+                            try
+                            {
+                                var delay = Convert.ToInt32(ps[1]);
+                                await TimerComponent.Instance.WaitAsync(delay);
+                                EventSystem.Instance.Publish(ChangeModeEvent.Static.Clone(objectid, ps[0]));
+                            }
+                            catch
+                            {
+                                Log.Error($"effect tag param error: {tag}");
+                            }
+                        }
+                        else
+                        {
+                            EventSystem.Instance.Publish(ChangeModeEvent.Static.Clone(objectid, param));
+                        }
+                        return;
+                    default:
+                        Log.Error($"effect unknow tag: {tag}");
+                        return;
+                }
+            }
+            Log.Error($"effect illegal tag: {tag}");
+        }
+
         private void registerEventHandler()
         {
             //actor===================
@@ -168,7 +207,25 @@ namespace ET
             eventHandler.AddListener<PlayerFocuseTargetEvent>((ev) =>
             {
             });
-            
+
+            eventHandler.AddListener<UnitHitBreak>((ev) =>
+            {
+                var e = ev as UnitHitBreak;
+                var unit = UnitMgr.Instance.GetUnit(e.ObjectID);
+                if (unit != null && unit is BattleUnit bunit)
+                {
+                    var launcheffect = bunit.ZUnit.Info.HitBreakEffect;
+                    if (launcheffect != null)
+                    {
+                        EventSystem.Instance.Publish(PlayEffectEvent.Static.Clone(launcheffect, unit.Id, CommonLang.Geometry.Vector3.Zero));
+
+                        if(!launcheffect.Tag.IsNullOrWhitespace() )
+                        {
+                            ProcessLauncheffectTag(e.ObjectID, launcheffect.Tag).Coroutine();
+                        }
+                    }
+                }
+            });
             eventHandler.AddListener<ShowTipsEventB2C>((ev) =>
             {
             });

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

@@ -16,7 +16,7 @@ public class BattleObject
     public virtual void OnAwake(ZoneObject zo)
     {
         ZoneObject = zo;
-        EventSystem.Instance.Publish(CurrentScene, new OnNewZoneObject() { ObjectId = Id });
+        EventSystem.Instance.Publish(OnNewZoneObject.Static.Clone(Id));
     }
 
     public virtual void OnSleep()

+ 43 - 12
Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/GameObjectPool.cs

@@ -3,6 +3,7 @@ using CommonAI.Zone.ZoneEditor;
 using CommonLang;
 using FairyGUI;
 using Sirenix.Utilities;
+using System;
 using System.Collections.Generic;
 using System.Text.RegularExpressions;
 using UnityEngine;
@@ -42,6 +43,15 @@ namespace ET.Client
         private readonly HashMap<string, AudioClip> audioPool = new();
         private readonly List<GComponent>headBarPool = new();
 
+        public async ETTask CachePrefab(string name)
+        {
+            var handle = await YooAssetProxy.LoadAssetAsync<GameObject>(name);
+            var prefab = handle.GetAssetObject<GameObject>();
+            var gameobj = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.RecycleNode, true);
+            gameobj.name = name;
+            RecycleObject(gameobj);
+        }
+
         //TODO: 选取当前场景的单位、技能(事件触发等等)
         //TODO: BUFF
         public async ETTask CacheSceneObject(int scnId)
@@ -64,16 +74,42 @@ namespace ET.Client
             var units = templates.getUnits();
             foreach(var unit in units.Values)
             {
-                var name = $"Unit_{unit.FileName}";
-                var handle = await YooAssetProxy.LoadAssetAsync<GameObject>(name);
-                var prefab = handle.GetAssetObject<GameObject>();
-                var gameobj = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.RecycleNode, true);
-                gameobj.name = name;
-                RecycleObject(gameobj);
+                await CachePrefab($"Unit_{unit.FileName}");
 
                 if(unit.FootCircleEffect != null) CacheLaunchEffect(unit.FootCircleEffect, ref effectlist, ref soundlist);
                 if (unit.SpawnEffect != null) CacheLaunchEffect(unit.SpawnEffect, ref effectlist, ref soundlist);
                 if (unit.DeadActionEffect != null) CacheLaunchEffect(unit.DeadActionEffect, ref effectlist, ref soundlist);
+                if (unit.DeadEffect != null) CacheLaunchEffect(unit.DeadEffect, ref effectlist, ref soundlist);
+                if (unit.HitBreakEffect != null) CacheLaunchEffect(unit.HitBreakEffect, ref effectlist, ref soundlist);
+
+                if (!unit.PreloadResources.IsNullOrWhitespace() )
+                {
+                    var split = unit.PreloadResources.Split(';');
+                    foreach(var res in split)
+                    {
+                        var realres = res;
+                        var cns = res.Split('|');
+                        var cnt = 1;
+                        if (cns.Length > 1)
+                        {
+                            realres = cns[0];
+                            try
+                            {
+                                cnt = Convert.ToInt32(cns[1]);
+                            }
+                            catch
+                            {
+                                Log.Error($"PreloadResources illegal: {unit.PreloadResources}");
+                                break;
+                            }
+                        }
+
+                        for (var i = 0; i < cnt; i++)
+                        {
+                            await CachePrefab(realres);
+                        }
+                    }
+                }
             }
 
             var skills = templates.getAllSkillData();
@@ -101,12 +137,7 @@ namespace ET.Client
 
             foreach (var ef in effectlist)
             {
-                var name = $"Effect_{ef}";
-                var handle = await YooAssetProxy.LoadAssetAsync<GameObject>(name);
-                var prefab = handle.GetAssetObject<GameObject>();
-                var gameobj = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.RecycleNode, true);
-                gameobj.name = name;
-                RecycleObject(gameobj);
+                await CachePrefab($"Effect_{ef}");
             }
 
             foreach(var sound in soundlist)

+ 22 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnChangeModelEvent.cs

@@ -0,0 +1,22 @@
+using ET;
+using ET.Client;
+
+[Event(SceneType.None)]
+public class ChangeModelEventHandler : BEvent<ET.EventType.ChangeModeEvent>
+{
+    public override void OnEvent(ET.EventType.ChangeModeEvent args)
+    {
+        var unitid = args.ObjectId;
+        if (!UnitMgr.Instance.HasUnit(unitid))
+        {
+            Log.Debug($"ignore change event @{unitid}, unit not exist");
+            return;
+        }
+
+        if (ModelViewComponent.Instance != null)
+        {
+            ModelViewComponent.Instance.RemoveChild(unitid);
+        }
+        EventSystem.Instance.Publish(ET.EventType.OnNewZoneObject.Static.Clone(unitid, args.ModelName));
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnChangeModelEvent.cs.meta

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

+ 16 - 11
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnNewZoneObject.cs

@@ -6,21 +6,28 @@ using UnityEngine;
 
 namespace ET.Client
 {
-    [Event(SceneType.Current)]
+    [Event(SceneType.None)]
     [FriendOfAttribute(typeof(ET.Client.UnitRenderComponet))]
-    public class OnNewZoneObjectHandler : AEvent<EventType.OnNewZoneObject>
+    public class OnNewZoneObjectHandler : BEvent<EventType.OnNewZoneObject>
     {
-        protected override async ETTask Run(Scene scene, EventType.OnNewZoneObject args)
+        public override void OnEvent(EventType.OnNewZoneObject args)
         {
             var obj = UnitMgr.Instance.GetUnit(args.ObjectId);
+            if (obj == null)
+            {
+                //还没显示就已挂掉的单位,走好
+                Log.Debug($"ignore dead unit: {args.ObjectId}");
+                return;
+            }
+
             if (obj is BattleUnit)
             {
-                await CreatUnitModel(obj as BattleUnit);
+                CreatUnitModel(obj as BattleUnit, args.ModelName).Coroutine();
             }
             else if (obj is BattleSpell)
             {
                 //TODO: 性能有问题时,可以减少法术展示
-                await CreateSpellModel(obj as BattleSpell);
+                CreateSpellModel(obj as BattleSpell).Coroutine();
             }
             else
             {
@@ -29,17 +36,15 @@ namespace ET.Client
         }
 
         private static CommonLang.Geometry.Vector3 vecTemp = new();
-        private async ETTask CreatUnitModel(BattleUnit unit)
+        private async ETTask CreatUnitModel(BattleUnit unit, string modelName)
         {
             var zu = unit.ZUnit;
-            if (!UnitMgr.Instance.HasUnit(zu.ObjectID))
+            if(modelName.IsNullOrWhitespace() )
             {
-                //还没显示就已挂掉的单位,走好
-                Log.Debug($"ignore dead unit: {zu}@{zu.ObjectID}");
-                return;
+                modelName = $"Unit_{zu.Info.FileName}";
             }
 
-            var go = await GameObjectPool.Instance.Acquire($"Unit_{zu.Info.FileName}");
+            var go = await GameObjectPool.Instance.Acquire(modelName);
             go.SetActive(true);
             go.transform.parent = GlobalViewComponent.Instance.Unit;
             vecTemp.Set(zu.X, zu.Y, zu.Z);

+ 0 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/UnitRenderSystem.cs

@@ -172,7 +172,6 @@ namespace ET.Client
                 }
                 else
                 {
-                    var screenpos = pos;
                     pos.y = Screen.height - pos.y;
                     pos = GRoot.inst.GlobalToLocal(pos);
                     self.HeadBar.SetXY(pos.x, pos.y);

+ 22 - 1
Unity/Assets/Scripts/Codes/Model/Client/EventTypeClient.cs

@@ -5,9 +5,18 @@ namespace ET
 {
     namespace EventType
     {
-        public struct OnNewZoneObject
+        public class OnNewZoneObject
         {
             public uint ObjectId;
+            public string ModelName;
+
+            public static OnNewZoneObject Static = new();
+            public OnNewZoneObject Clone(uint id, string modelName = null)
+            {
+                ObjectId = id;
+                ModelName = modelName;
+                return this;
+            }
         }
         public struct OnDestroyZoneObject
         {
@@ -173,6 +182,18 @@ namespace ET
                 return this;
             }
         }
+        public class ChangeModeEvent
+        {
+            public uint ObjectId;
+            public string ModelName;
+            public static ChangeModeEvent Static = new();
+            public ChangeModeEvent Clone(uint id, string modelName)
+            {
+                ObjectId = id;
+                ModelName = modelName;
+                return this;
+            }
+        }
     }
 
     //状态指令

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Client/Generate/Message/OuterMessage_C_10001.cs.meta

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