LSUnitViewComponentSystem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. namespace ET.Client
  3. {
  4. [EntitySystemOf(typeof(LSUnitViewComponent))]
  5. public static partial class LSUnitViewComponentSystem
  6. {
  7. [EntitySystem]
  8. private static void Awake(this LSUnitViewComponent self)
  9. {
  10. }
  11. [EntitySystem]
  12. private static void Destroy(this LSUnitViewComponent self)
  13. {
  14. }
  15. public static async ETTask InitAsync(this LSUnitViewComponent self)
  16. {
  17. Room room = self.Room();
  18. LSUnitComponent lsUnitComponent = room.LSWorld.GetComponent<LSUnitComponent>();
  19. Scene root = self.Root();
  20. foreach (long playerId in room.PlayerIds)
  21. {
  22. LSUnit lsUnit = lsUnitComponent.GetChild<LSUnit>(playerId);
  23. string assetsName = $"Assets/Bundles/Unit/Unit.prefab";
  24. GameObject bundleGameObject = await room.GetComponent<ResourcesLoaderComponent>().LoadAssetAsync<GameObject>(assetsName);
  25. GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
  26. GlobalComponent globalComponent = root.GetComponent<GlobalComponent>();
  27. GameObject unitGo = UnityEngine.Object.Instantiate(prefab, globalComponent.Unit, true);
  28. unitGo.transform.position = lsUnit.Position.ToVector();
  29. LSUnitView lsUnitView = self.AddChildWithId<LSUnitView, GameObject>(lsUnit.Id, unitGo);
  30. lsUnitView.AddComponent<LSAnimatorComponent>();
  31. }
  32. }
  33. }
  34. }