1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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
- {
- 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}");
- var prefab = handle.GetAssetObject<GameObject>();
- GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.Unit, true);
- vecTemp.Set(unit.ZUnit.X, unit.ZUnit.Y, unit.ZUnit.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}) ok.");
- //TODO: 同步ZoneUnit status
- }
- }
- }
|