You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.1 KiB
118 lines
4.1 KiB
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Unit))] |
|
public static class UnitFactory |
|
{ |
|
public static Unit Create(Scene currentScene, UnitProto unitProto) |
|
{ |
|
UnitComponent unitComponent = currentScene.GetComponent<UnitComponent>(); |
|
Unit unit = unitComponent.AddChildWithId<Unit>(unitProto.Id); |
|
unit.Water = unitProto.Water; |
|
unit.Food = unitProto.Food; |
|
unit.Season = unitProto.Season; |
|
unit.GameTime = unitProto.GameTime; |
|
unit.SilverTael = unitProto.SilverTael; |
|
unit.GoldIngot = unitProto.GoldIngot; |
|
unit.Name = unitProto.Name; |
|
unit.Scale = unitProto.Scale; |
|
unit.Day = unitProto.Day; |
|
unit.EventSeed = unitProto.EventSeed; |
|
unit.EventNames = unitProto.EventNames; |
|
|
|
for (int i = 0; i < unitProto.FighterList.Count / 2; i++) |
|
{ |
|
unit.FighterDic[(int)unitProto.FighterList[i * 2]] = unitProto.FighterList[i * 2 + 1]; |
|
} |
|
|
|
BuildingComponent buildingComponent = unit.AddComponent<BuildingComponent>(); |
|
foreach (var info in unitProto.Buildings) |
|
{ |
|
Building building = buildingComponent.AddChildWithId<Building>(info.Id); |
|
building.FromMessage(info); |
|
//buildingComponent.Add(building); |
|
} |
|
|
|
PeopleComponent pc = unit.GetOrAddComponent<PeopleComponent>(); |
|
foreach (var v in unitProto.PeopleList) |
|
{ |
|
People people = pc.AddChildWithId<People,int>(v.Id,v.ConfigId); |
|
people.FromMessage(v); |
|
people.InitNumericComponent(); |
|
|
|
} |
|
|
|
ResourcePointComponent rc = unit.GetOrAddComponent<ResourcePointComponent>(); |
|
foreach (var v in unitProto.ResourceList) |
|
{ |
|
ResourcePoint res = rc.AddChildWithId<ResourcePoint>(v.Id); |
|
res.FromMessage(v); |
|
} |
|
|
|
StoreComponent sc = unit.GetOrAddComponent<StoreComponent>(); |
|
foreach (var v in unitProto.Store) |
|
{ |
|
sc.Add(v.ConfigId,v.Amount); |
|
} |
|
|
|
if (unitProto.GatherList.Count > 0) |
|
{ |
|
GatherComponent gc = unit.GetOrAddComponent<GatherComponent>(); |
|
foreach (var v in unitProto.GatherList) |
|
{ |
|
Gather gather = gc.AddChildWithId<Gather>(v.Id); |
|
gather.FromMessage(v); |
|
} |
|
} |
|
|
|
if (unitProto.ConstructList.Count > 0) |
|
{ |
|
ConstructComponent gc = unit.GetOrAddComponent<ConstructComponent>(); |
|
foreach (var v in unitProto.ConstructList) |
|
{ |
|
Construct construct = gc.AddChildWithId<Construct>(v.Id); |
|
construct.FromMessage(v); |
|
} |
|
} |
|
if (unitProto.SynthesisList.Count > 0) |
|
{ |
|
var now = TimeHelper.ServerNow(); |
|
SynthesisComponent synthesisComponent = unit.GetOrAddComponent<SynthesisComponent>(); |
|
foreach (var v in unitProto.SynthesisList) |
|
{ |
|
Synthesis synthesis = synthesisComponent.AddChildWithId<Synthesis>(v.ConfigId); |
|
synthesis.FromMessage(v); |
|
// synthesis.UpdateTime = now; |
|
} |
|
} |
|
if (unitProto.MenuList.Count > 0) |
|
{ |
|
MenuComponent menuComponent = unit.GetOrAddComponent<MenuComponent>(); |
|
foreach (var v in unitProto.MenuList) |
|
{ |
|
Menu menu = menuComponent.AddChildWithId<Menu>(v.ConfigId); |
|
menu.FromMessage(v); |
|
} |
|
} |
|
|
|
if (unitProto.MonsterGroupList.Count > 0) |
|
{ |
|
MonsterGroupComponent monsterGroupComponent = unit.GetOrAddComponent<MonsterGroupComponent>(); |
|
foreach (var v in unitProto.MonsterGroupList) |
|
{ |
|
MonsterGroup monsterGroup = monsterGroupComponent.AddChildWithId<MonsterGroup,int>(v.Id,v.ConfigId); |
|
monsterGroup.FromMessage(v); |
|
} |
|
} |
|
|
|
unitComponent.Add(unit); |
|
unit.AddComponent<ObjectWait>(); |
|
unit.InitGrandChildren(); |
|
Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit}); |
|
|
|
return unit; |
|
} |
|
} |
|
}
|
|
|