1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using CommonAI.ZoneClient;
- using Sirenix.Utilities;
- using System.Text.RegularExpressions;
- using UnityEngine;
- namespace ET.Client
- {
- [Event(SceneType.Current)]
- public class OnNewZoneObjectHandler : AEvent<EventType.OnNewZoneObject>
- {
- protected override async ETTask Run(Scene scene, EventType.OnNewZoneObject args)
- {
- var obj = UnitMgr.Instance.GetUnit(args.ObjectId);
- if(obj is BattleUnit)
- {
- await CreatUnitModel(obj as BattleUnit);
- }
- else if(obj is BattleSpell)
- {
- //TODO: 性能有问题时,可以减少法术展示
- await CreateSpellModel(obj as BattleSpell);
- }
- else
- {
- Log.Error("unknow new object");
- }
- }
- private static CommonLang.Geometry.Vector3 vecTemp = new();
- private async ETTask CreatUnitModel(BattleUnit unit)
- {
- var zu = unit.ZUnit;
-
- 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>();
- GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.Unit, true);
- vecTemp.Set(zu.X, zu.Y, zu.Z);
- go.transform.position = RenderUtils.UnityPosFromBattle(vecTemp);
- go.transform.rotation = RenderUtils.UnityRotationFromBattle(zu.Direction);
- ModelViewComponent.Instance.AddChildWithId<UnitRenderComponet, GameObject>(unit.Id, go, true);
- if (unit is BattleActor)
- {
- CameraMgr.FollowMe(go.transform.position);
- }
- Log.Debug($"unitRender({zu.ObjectID}),pos({zu.X},{zu.Y},{zu.Z}) ok.");
- //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) || (zs.Sender != null && !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.");
- }
- }
- }
|