UnitFactory.cs 1.0 KB

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. namespace ETModel
  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 = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
  10. GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
  11. UnitComponent unitComponent = Game.Scene.GetComponent<UnitComponent>();
  12. Unit unit = ComponentFactory.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. unit.AddComponent<TurnComponent>();
  19. unit.AddComponent<UnitPathComponent>();
  20. unitComponent.Add(unit);
  21. return unit;
  22. }
  23. }
  24. }