LSUnitViewComponentSystem.cs 1.2 KB

1234567891011121314151617181920212223242526272829
  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. Scene root = self.Root();
  12. foreach (long playerId in room.PlayerIds)
  13. {
  14. LSUnit lsUnit = lsUnitComponent.GetChild<LSUnit>(playerId);
  15. ResourcesComponent resourcesComponent = root.GetComponent<ResourcesComponent>();
  16. GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
  17. GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
  18. GlobalComponent globalComponent = root.GetComponent<GlobalComponent>();
  19. GameObject unitGo = UnityEngine.Object.Instantiate(prefab, globalComponent.Unit, true);
  20. unitGo.transform.position = lsUnit.Position.ToVector();
  21. LSUnitView lsUnitView = self.AddChildWithId<LSUnitView, GameObject>(lsUnit.Id, unitGo);
  22. lsUnitView.AddComponent<LSAnimatorComponent>();
  23. }
  24. }
  25. }
  26. }