UnitFactory.cs 1000 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. 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<UnitPathComponent>();
  19. unitComponent.Add(unit);
  20. return unit;
  21. }
  22. }
  23. }