UnitFactory.cs 938 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. namespace Model
  3. {
  4. public static class UnitFactory
  5. {
  6. public static Unit Create(long id)
  7. {
  8. ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
  9. GameObject bundleGameObject = resourcesComponent.GetAsset<GameObject>("Unit", "Unit");
  10. GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
  11. UnitComponent unitComponent = Game.Scene.GetComponent<UnitComponent>();
  12. Unit unit = EntityFactory.CreateWithId<Unit>(id);
  13. unit.GameObject = UnityEngine.Object.Instantiate(prefab);
  14. GameObject parent = GameObject.Find($"/Global/Unit");
  15. unit.GameObject.transform.SetParent(parent.transform, false);
  16. unit.AddComponent<AnimatorComponent>();
  17. unit.AddComponent<MoveComponent>();
  18. unitComponent.Add(unit);
  19. return unit;
  20. }
  21. }
  22. }