LSUnitViewComponentSystem.cs 1.2 KB

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. namespace ET.Client
  3. {
  4. public static partial class LSUnitViewComponentSystem
  5. {
  6. [EntitySystem]
  7. private static void Awake(this LSUnitViewComponent self)
  8. {
  9. Room room = self.Room();
  10. LSUnitComponent lsUnitComponent = room.LSWorld.GetComponent<LSUnitComponent>();
  11. foreach (long playerId in room.PlayerIds)
  12. {
  13. LSUnit lsUnit = lsUnitComponent.GetChild<LSUnit>(playerId);
  14. ResourcesComponent resourcesComponent = self.Fiber().GetComponent<ResourcesComponent>();
  15. GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
  16. GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
  17. GlobalComponent globalComponent = self.Fiber().GetComponent<GlobalComponent>();
  18. GameObject unitGo = UnityEngine.Object.Instantiate(prefab, globalComponent.Unit, true);
  19. unitGo.transform.position = lsUnit.Position.ToVector();
  20. LSUnitView lsUnitView = self.AddChildWithId<LSUnitView, GameObject>(lsUnit.Id, unitGo);
  21. lsUnitView.AddComponent<LSAnimatorComponent>();
  22. }
  23. }
  24. }
  25. }