UnitFactory.cs 935 B

123456789101112131415161718192021222324252627
  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. GameObject go = UnityEngine.Object.Instantiate(prefab);
  13. Unit unit = ComponentFactory.CreateWithId<Unit, GameObject>(id, go);
  14. unit.AddComponent<AnimatorComponent>();
  15. unit.AddComponent<MoveComponent>();
  16. unit.AddComponent<TurnComponent>();
  17. unit.AddComponent<UnitPathComponent>();
  18. unitComponent.Add(unit);
  19. return unit;
  20. }
  21. }
  22. }