AfterUnitCreate_CreateUnitView.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Mono;
  2. using UnityEngine;
  3. namespace ET.Client
  4. {
  5. [Event(SceneType.Current)]
  6. public class AfterUnitCreate_CreateUnitView : AEvent<EventType.AfterUnitCreate>
  7. {
  8. protected override async ETTask Run(Scene scene, EventType.AfterUnitCreate args)
  9. {
  10. Unit unit = args.Unit;
  11. // Unit View层
  12. var handle = await YooAssetProxy.LoadAssetAsync<GameObject>("Unit_Aj");
  13. var prefab = handle.GetAssetObject<GameObject>();
  14. GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalComponent.Instance.Unit, true);
  15. Log.Debug($"loaded unit({unit.Id}) model: Unit_Aj");
  16. go.transform.position = unit.Position;
  17. unit.AddComponent<GameObjectComponent>().GameObject = go;
  18. var aniComp = unit.AddComponent<AnimatorComponent>();
  19. if (unit.IsActor)
  20. {
  21. //相机跟随主角
  22. //unit.AddComponent<CameraComponent>().Unit = unit;
  23. //固定视角相机
  24. var camera = Camera.main;
  25. camera.transform.position = new Vector3(unit.Position.x, 7, unit.Position.z - 15);
  26. }
  27. }
  28. }
  29. }