//last initialization method for factions: extra buildings and NPC managers init. private void InitFactions() { //no factions? if (Factions.Count == 0) { return; //do not proceed. } //go through the factions. for (int i = 0; i < Factions.Count; i++) { //Depending on the faction type, add extra units/buildings (if there's actually any) to be created for each faction: if (Factions[i].playerControlled == true) //if this faction is player controlled: { if (Factions[i].TypeInfo != null) //if this faction has a valid type. { if (Factions[i].TypeInfo.extraBuildings.Count > 0) //if the faction type has extra buildings: { foreach (Building b in Factions[i].TypeInfo.extraBuildings) { BuildingMgr.AllBuildings.Add(b); //add the extra buildings so that this faction can use them. } } } } else if (Factions[i].IsNPCFaction() == true) //if this is not controlled by the local player but rather NPC. { //Init the NPC Faction manager: Factions[i].InitNPCMgr(); } if (Factions[i].TypeInfo != null) //if this faction has a valid type. { Factions[i].FactionMgr.Limits.Clear(); //copy the faction type limits in the faction manager: foreach (FactionTypeInfo.FactionLimitsVars LimitElem in Factions[i].TypeInfo.Limits) { FactionTypeInfo.FactionLimitsVars newLimitElem = new FactionTypeInfo.FactionLimitsVars() { Code = LimitElem.Code, MaxAmount = LimitElem.MaxAmount, CurrentAmount = 0 }; Factions[i].FactionMgr.Limits.Add(newLimitElem); } } } }
void FactionSettings() { Target.Name = EditorGUILayout.TextField("Name", Target.Name); Target.Code = EditorGUILayout.TextField("Code", Target.Code); EditorGUILayout.Space(); Target.CapitalBuilding = EditorGUILayout.ObjectField("Capital Building", Target.CapitalBuilding, typeof(Building), true) as Building; Target.BuildingCenter = EditorGUILayout.ObjectField("Building Center", Target.BuildingCenter, typeof(Building), true) as Building; Target.PopulationBuilding = EditorGUILayout.ObjectField("Population Building", Target.PopulationBuilding, typeof(Building), true) as Building; Target.DropOffBuilding = EditorGUILayout.ObjectField("Drop Off Building", Target.DropOffBuilding, typeof(Building), true) as Building; EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Extra Buildings"); EditorGUILayout.Space(); if (GUILayout.Button("+", SmallButtonLayout)) { Target.ExtraBuildings.Add(null); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (Target.ExtraBuildings.Count > 0) { for (int i = 0; i < Target.ExtraBuildings.Count; i++) { GUILayout.BeginHorizontal(); Target.ExtraBuildings[i] = EditorGUILayout.ObjectField(Target.ExtraBuildings[i], typeof(Building), false) as Building; if (GUILayout.Button("-", SmallButtonLayout)) { Target.ExtraBuildings.Remove(Target.ExtraBuildings[i]); } GUILayout.EndHorizontal(); } } else { EditorGUILayout.HelpBox("No extra buildings defined for this faction type", MessageType.Warning); } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Limits"); EditorGUILayout.Space(); if (GUILayout.Button("+", SmallButtonLayout)) { FactionTypeInfo.FactionLimitsVars NewLimitElement = new FactionTypeInfo.FactionLimitsVars(); Target.Limits.Add(NewLimitElement); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (Target.Limits.Count > 0) { for (int i = 0; i < Target.Limits.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); Target.Limits[i].Code = EditorGUILayout.TextField("Code", Target.Limits[i].Code); Target.Limits[i].MaxAmount = EditorGUILayout.IntField("Max Amount", Target.Limits[i].MaxAmount); GUILayout.EndVertical(); if (GUILayout.Button("-", SmallButtonLayout)) { Target.Limits.Remove(Target.Limits[i]); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); } } else { EditorGUILayout.HelpBox("No building/unit limits defined for this faction type", MessageType.Warning); } }
void Start() { /*because the building's main compoment is a network behaviour. The building centers, already present in the scene when it loads, will be disabled in an offline * game because their NetworkIdentity components can not connect to a server. Therefore, we need to enable under "Start ()". * */ if (Factions.Count > 0) { for (int i = 0; i < Factions.Count; i++) { if (Factions[i].CapitalBuilding != null) { Factions[i].CapitalBuilding.gameObject.SetActive(true); } if (Factions[i].TypeInfo != null) { //if this is a valid faction //Depending on the faction type, add extra units/buildings (if there's actually any) to be created for each faction: if (MultiplayerGame == false || (MultiplayerGame == true && PlayerFactionID == i)) { if (Factions[i].PlayerControl == true) { //if this faction is player controlled: if (Factions[i].TypeInfo.ExtraBuildings.Count > 0) { //if the faction type has extra buildings: for (int j = 0; j < Factions[i].TypeInfo.ExtraBuildings.Count; j++) { //go through them: if (Factions[i].TypeInfo.ExtraBuildings[j] != null) //only if there's an assigned building. { BuildingMgr.AllBuildings.Add(Factions[i].TypeInfo.ExtraBuildings[j]); //add the extra buildings so that this faction can use them. } } } } else { //NPC players. if (Factions[i].TypeInfo.ExtraBuildings.Count > 0) { //if the faction type has extra buildings: Factions[i].FactionMgr.BuildingMgr.AllBuildings.AddRange(Factions[i].TypeInfo.ExtraBuildings); //add the extra buildings so that this faction can use them. } //special buildings for NPC factions: if (Factions[i].TypeInfo.BuildingCenter != null) { Factions[i].FactionMgr.BuildingMgr.BuildingCenter = Factions[i].TypeInfo.BuildingCenter; } if (Factions[i].TypeInfo.DropOffBuilding != null) { Factions[i].FactionMgr.BuildingMgr.DropOffBuilding = Factions[i].TypeInfo.DropOffBuilding; } if (Factions[i].TypeInfo.PopulationBuilding != null) { Factions[i].FactionMgr.BuildingMgr.PopulationBuilding = Factions[i].TypeInfo.PopulationBuilding; } } Factions[i].FactionMgr.Limits.Clear(); //set the faction type limits in the faction manager: foreach (FactionTypeInfo.FactionLimitsVars LimitElem in Factions[i].TypeInfo.Limits) { FactionTypeInfo.FactionLimitsVars CopyLimitElem = new FactionTypeInfo.FactionLimitsVars(); CopyLimitElem.Code = LimitElem.Code; CopyLimitElem.MaxAmount = LimitElem.MaxAmount; CopyLimitElem.CurrentAmount = 0; Factions[i].FactionMgr.Limits.Add(CopyLimitElem); } } } } } //if it's not a MP game: if (MultiplayerGame == false) { //Set the player's initial cam position (looking at the faction's capital building): CamMov.LookAt(Factions[PlayerFactionID].CapitalBuilding.transform.position); CamMov.SetMiniMapCursorPos(Factions[PlayerFactionID].CapitalBuilding.transform.position); } }