123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using UnityEngine;
- namespace ET.Client
- {
- [Event(SceneType.Current)]
- public class OnNewZoneObject : AEvent<EventType.OnNewZoneObject>
- {
- protected override async ETTask Run(Scene scene, EventType.OnNewZoneObject args)
- {
- var bo = args.Object;
- if(bo is BattleUnit)
- {
- await CreatUnitModel(bo as BattleUnit);
- }
- else
- {
- Log.Error("unknow new object");
- }
- }
- 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);
- go.transform.position = new Vector3(0, 0, 0);
- go.transform.rotation = Quaternion.identity;
- ModelViewComponent.Instance.AddChildWithId<AnimatorComponent, GameObject>(unit.Id, go, true);
- if (unit is BattleActor)
- {
- //相机跟随主角
- //ModelViewComponent.Instance.AddComponent<CameraComponent>().Unit = unit;
- //固定视角相机
- var camera = Camera.main;
- var pos = go.transform.position;
- camera.transform.position = new Vector3(pos.x, 7, pos.z - 15);
- }
- }
- }
- }
|