protected static int AutoCalculateStructureValue(Structure structure) { //TODO this method sucks, do something better int structureValue = 1; //see how big the house is StructureTemplate template = null; if (Mods.Get.Editor.LoadMod <StructureTemplate> (ref template, "Structure", structure.State.TemplateName)) { int numDoorsAndWindows = template.Exterior.GenericDoors.Length + template.Exterior.GenericWindows.Length; int stackItems = template.Exterior.UniqueWorlditems.Count; List <ChildPiece> genericDoors = null; //new List<ChildPiece>(); List <ChildPiece> genericWindows = null; //new List<ChildPiece>(); if (StructureTemplate.ExtractChildPiecesFromLayer(ref genericDoors, template.Exterior.GenericDoors)) { numDoorsAndWindows += genericDoors.Count; } if (StructureTemplate.ExtractChildPiecesFromLayer(ref genericWindows, template.Exterior.GenericWindows)) { numDoorsAndWindows += genericWindows.Count; } for (int i = 0; i < template.InteriorVariants.Count; i++) { if (StructureTemplate.ExtractChildPiecesFromLayer(ref genericDoors, template.InteriorVariants [i].GenericDoors)) { numDoorsAndWindows += genericDoors.Count; } if (StructureTemplate.ExtractChildPiecesFromLayer(ref genericWindows, template.InteriorVariants [i].GenericWindows)) { numDoorsAndWindows += genericWindows.Count; } stackItems += template.InteriorVariants [i].UniqueWorlditems.Count; } structureValue += numDoorsAndWindows + stackItems; } return(structureValue); }
public void CreateFoundation() { if (!Manager.IsAwake <Mods> ()) { Manager.WakeUp <Mods> ("__MODS"); } Mods.Get.Editor.InitializeEditor(true); if (!Manager.IsAwake <Structures> ()) { Manager.WakeUp <Structures> ("Frontiers_Structures"); } Structures.Get.Initialize(); if (!Manager.IsAwake <WorldItems> ()) { Manager.WakeUp <WorldItems> ("Frontiers_WorldItems"); } WorldItems.Get.Initialize(); StructureTemplate template = null; if (Mods.Get.Editor.LoadMod <StructureTemplate> (ref template, "Structure", StructureBuilder.GetTemplateName(name))) { GameObject foundation = gameObject.FindOrCreateChild("__TEMP_FOUNDATION").gameObject; foreach (StructureLayer staticLayer in template.Exterior.StaticStructureLayers) { string prefabName = staticLayer.PrefabName.Trim().ToLower(); if (prefabName.Contains("foundation")) { StructurePackPrefab prefab = null; if (Structures.Get.PackStaticPrefab(staticLayer.PackName, staticLayer.PrefabName, out prefab)) { List <ChildPiece> staticPieces = null; if (StructureTemplate.ExtractChildPiecesFromLayer(ref staticPieces, staticLayer.Instances)) { //ChildPiece[] staticPieces = StructureTemplate.ExtractChildPiecesFromLayer(staticLayer.Instances); for (int i = 0; i < staticPieces.Count; i++) { ChildPiece piece = staticPieces [i]; GameObject instantiatedPrefab = UnityEditor.PrefabUtility.InstantiatePrefab(prefab.Prefab) as GameObject; //instantiate a new prefab - keep it as a prefab! instantiatedPrefab.name = prefab.Prefab.name; instantiatedPrefab.transform.parent = foundation.transform; instantiatedPrefab.tag = staticLayer.Tag; instantiatedPrefab.layer = staticLayer.Layer; //put it in the right place instantiatedPrefab.transform.localPosition = piece.Position; instantiatedPrefab.transform.localRotation = Quaternion.identity; instantiatedPrefab.transform.Rotate(piece.Rotation); instantiatedPrefab.transform.localScale = piece.Scale; Material[] variationsArray = null; if (staticLayer.Substitutions != null && staticLayer.Substitutions.Count > 0) { MeshRenderer pmr = prefab.MRenderer; variationsArray = pmr.sharedMaterials; string newMaterialName = string.Empty; for (int j = 0; j < variationsArray.Length; j++) { if (staticLayer.Substitutions.TryGetValue(variationsArray [j].name, out newMaterialName)) { Material sharedMaterial = null; if (Structures.Get.SharedMaterial(newMaterialName, out sharedMaterial)) { variationsArray [j] = sharedMaterial; } } } instantiatedPrefab.GetComponent <Renderer>().materials = variationsArray; } } staticPieces.Clear(); staticPieces = null; } } } } } }