UnitFactory.cs 760 B

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