12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using Unity.Mathematics;
- namespace ET.Client
- {
- public static class UnitFactory
- {
- public static Unit Create(Scene currentScene, UnitInfo unitInfo, bool isActor = false)
- {
- Log.Debug($"Create unit :{unitInfo.UnitId}@{unitInfo.Type}");
- UnitComponent unitComponent = currentScene.GetComponent<UnitComponent>();
- Unit unit = unitComponent.AddChildWithId<Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);
- unit.IsActor = isActor;
- unit.Position = unitInfo.Position;
- unit.Forward = unitInfo.Forward;
- unitComponent.Add(unit);
- NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
- foreach (var kv in unitInfo.KV)
- {
- numericComponent.Set(kv.Key, kv.Value);
- }
-
- unit.AddComponent<MoveComponent>();
- if (unitInfo.MoveInfo != null)
- {
- if (unitInfo.MoveInfo.Points.Count > 0)
- {
- unitInfo.MoveInfo.Points[0] = unit.Position;
- unit.MoveToAsync(unitInfo.MoveInfo.Points).Coroutine();
- }
- }
- unit.AddComponent<ObjectWait>();
- if (unitInfo.Type == (int)UnitType.Monster)
- {
- unit.AddComponent<XunLuoPathComponent>();
- }
- EventSystem.Instance.Publish(unit.DomainScene(), new EventType.AfterUnitCreate() {Unit = unit});
- return unit;
- }
- }
- }
|