public void Reset() { StructureBase = null; StructurePiece = null; ParentStructure = null; MinorParent = null; if (MaterialLookup != null) { MaterialLookup.Clear(); } //if (Template != null) { //Template.Clear(); //} Template = null; if (gHelperTransform != null) { gHelperTransform.transform.parent = transform; } State = BuilderState.Dormant; }
public IEnumerator GenerateStructureMeshes() { State = BuilderState.BuildingMeshes; switch (Mode) { case BuilderMode.Exterior: default: mCurrentTemplateGroup = Template.Exterior; //extract the fires from the template and add it to the template //StructureTemplate.ExtractChildPiecesFromLayer (ref ParentStructure.DestroyedFires, Template.Exterior.DestroyedFires); //StructureTemplate.ExtractFXPiecesFromLayer (ref ParentStructure.DestroyedFX, Template.Exterior.DestroyedFX); if (ParentStructure.DestroyedFX == null) { ParentStructure.DestroyedFX = new List <FXPiece> (); } if (ParentStructure.DestroyedFires == null) { ParentStructure.DestroyedFires = new List <ChildPiece> (); } ParentStructure.DestroyedFX.AddRange(Template.Exterior.DestroyedFXPieces); ParentStructure.DestroyedFires.AddRange(Template.Exterior.DestroyedFiresPieces); switch (Template.BuildMethod) { case StructureBuildMethod.MeshCombiner: //before we actually generate the meshes //see if it's cached /*Structure cachedInstance = null; * if (Structures.Get.GetCachedInstance(Template.Name, ParentStructure, out cachedInstance)) { * //hooray it's cached * //duplicate it piece for piece * yield return StartCoroutine(StructureBuilder.InstantiateMeshes( * ParentStructure, * cachedInstance, * this)); * * } else {*/ //otherwise just generate the meshes normally var generateMeshes = StructureBuilder.GenerateMeshes( mCurrentTemplateGroup, PrimaryCombiner, LODCombiner, DestroyedCombiner, LODDestroyedCombiner, GetChildName(false, false), ParentStructure.ExteriorMeshes, ParentStructure.ExteriorRenderers, ParentStructure.ExteriorRenderersDestroyed, ParentStructure.ExteriorLodRenderers, ParentStructure.ExteriorLodRenderersDestroyed, false, Template.UseLOD, this, Template.Name); while (generateMeshes.MoveNext()) { yield return(generateMeshes.Current); } /*}*/ //non-destroyed custom colliders var generateCustomColliders = StructureBuilder.GenerateColliders( GetChildName(false, false), ParentStructure.ExteriorLayers, ParentStructure.ExteriorBoxColliders, ParentStructure.ExteriorMeshColliders, ParentStructure.ExteriorBoxCollidersDestroyed, ParentStructure.ExteriorMeshCollidersDestroyed, ParentStructure.ExteriorMeshes, mCurrentTemplateGroup.CustomStructureColliders, false, //exterior this); while (generateCustomColliders.MoveNext()) { yield return(generateCustomColliders.Current); } //non-destroyed static colliders var generateStaticColliders = StructureBuilder.GenerateColliders( GetChildName(false, false), ParentStructure.ExteriorLayers, ParentStructure.ExteriorBoxColliders, ParentStructure.ExteriorMeshColliders, ParentStructure.ExteriorBoxCollidersDestroyed, ParentStructure.ExteriorMeshCollidersDestroyed, ParentStructure.ExteriorMeshes, mCurrentTemplateGroup.StaticStructureColliders, false, //exterior this); while (generateStaticColliders.MoveNext()) { yield return(generateStaticColliders.Current); } break; case StructureBuildMethod.MeshInstances: if (ParentStructure.DestroyedFX == null) { ParentStructure.DestroyedFX = new List <FXPiece> (); } if (ParentStructure.DestroyedFires == null) { ParentStructure.DestroyedFires = new List <ChildPiece> (); } //extract the fires from the template and add it to the template ParentStructure.DestroyedFires.AddRange(Template.Exterior.DestroyedFiresPieces); ParentStructure.DestroyedFX.AddRange(Template.Exterior.DestroyedFXPieces); //StructureTemplate.ExtractChildPiecesFromLayer (ref ParentStructure.DestroyedFires, Template.Exterior.DestroyedFires); //StructureTemplate.ExtractFXPiecesFromLayer (ref ParentStructure.DestroyedFX, Template.Exterior.DestroyedFX); var instanceMeshes = InstanceMeshes( mCurrentTemplateGroup, GetChildName(false, false), mExteriorRenderers, mExteriorLODRenderers, Globals.StructureExteriorLODRatio); while (instanceMeshes.MoveNext()) { yield return(instanceMeshes.Current); } break; } if (ParentStructure.ExteriorMovmementNodes == null) { ParentStructure.ExteriorMovmementNodes = new List <MovementNode> (); } ParentStructure.ExteriorMovmementNodes.AddRange(mCurrentTemplateGroup.MovementNodes); mCurrentTemplateGroup = null; break; case BuilderMode.Interior: //we're not caching interior meshes yet for (int i = 0; i < InteriorVariants.Count; i++) { int interiorVariant = InteriorVariants [i]; if (interiorVariant < Template.InteriorVariants.Count) { mCurrentTemplateGroup = Template.InteriorVariants [interiorVariant]; var generateMeshes = StructureBuilder.GenerateMeshes( mCurrentTemplateGroup, PrimaryCombiner, LODCombiner, DestroyedCombiner, LODDestroyedCombiner, GetChildName(true, false), ParentStructure.InteriorMeshes, ParentStructure.InteriorRenderers, ParentStructure.InteriorRenderersDestroyed, null, null, true, Template.UseLOD, this, Template.Name); while (generateMeshes.MoveNext()) { yield return(generateMeshes.Current); } MaterialLookup.Clear(); //non-destroyed custom colliders var generateCustomColliders = StructureBuilder.GenerateColliders( GetChildName(true, false), ParentStructure.InteriorLayers, ParentStructure.InteriorBoxColliders, ParentStructure.InteriorMeshColliders, ParentStructure.InteriorBoxCollidersDestroyed, ParentStructure.InteriorMeshCollidersDestroyed, ParentStructure.InteriorMeshes, mCurrentTemplateGroup.CustomStructureColliders, true, //interior this); while (generateCustomColliders.MoveNext()) { yield return(generateCustomColliders.Current); } //non-destroyed static colliders var generateStaticColliders = StructureBuilder.GenerateColliders( GetChildName(true, true), ParentStructure.InteriorLayers, ParentStructure.InteriorBoxColliders, ParentStructure.InteriorMeshColliders, ParentStructure.InteriorBoxCollidersDestroyed, ParentStructure.InteriorMeshCollidersDestroyed, ParentStructure.InteriorMeshes, mCurrentTemplateGroup.StaticStructureColliders, true, //interior this); while (generateStaticColliders.MoveNext()) { yield return(generateStaticColliders.Current); } yield return(null); if (ParentStructure.InteriorMovementNodes == null) { ParentStructure.InteriorMovementNodes = new List <MovementNode> (); } ParentStructure.InteriorMovementNodes.AddRange(mCurrentTemplateGroup.MovementNodes); //Debug.Log ("Done generating interior variant " + interiorVariant.ToString () + ", state is " + State.ToString ()); } /*else { * Debug.Log ("Didn't generate items for interior variant " + interiorVariant.ToString () + " because it has either been loaded once (" + ParentStructure.State.InteriorsLoadedOnce.Contains (interiorVariant).ToString() + ") or it's out of range (" + (interiorVariant >= Template.InteriorVariants.Count).ToString () + ")"); + }*/ } //Debug.Log ("Finished generating states"); mCurrentTemplateGroup = null; break; case BuilderMode.Minor: mCurrentTemplateGroup = Template.Exterior; switch (Template.BuildMethod) { case StructureBuildMethod.MeshCombiner: var generateMeshes = StructureBuilder.GenerateMeshes( mCurrentTemplateGroup, PrimaryCombiner, LODCombiner, DestroyedCombiner, LODDestroyedCombiner, GetChildName(false, false, MinorParent.Number), MinorParent.ExteriorMeshes, MinorParent.ExteriorRenderers, MinorParent.ExteriorRenderersDestroyed, MinorParent.ExteriorLODRenderers, MinorParent.ExteriorLODRenderersDestroyed, false, Template.UseLOD, this, Template.Name); while (generateMeshes.MoveNext()) { yield return(generateMeshes.Current); } StructurePiece.transform.ResetLocal(); var generateCustomColliders = StructureBuilder.GenerateColliders( GetChildName(false, false, MinorParent.Number), MinorParent.ExteriorLayers, MinorParent.ExteriorBoxColliders, MinorParent.ExteriorMeshColliders, MinorParent.ExteriorBoxColliders, MinorParent.ExteriorMeshColliders, MinorParent.ExteriorMeshes, mCurrentTemplateGroup.StaticStructureColliders, false, this); while (generateCustomColliders.MoveNext()) { yield return(generateCustomColliders.Current); } var generateStaticColliders = StructureBuilder.GenerateColliders( GetChildName(false, false, MinorParent.Number), MinorParent.ExteriorLayers, MinorParent.ExteriorBoxColliders, MinorParent.ExteriorMeshColliders, MinorParent.ExteriorBoxColliders, MinorParent.ExteriorMeshColliders, MinorParent.ExteriorMeshes, mCurrentTemplateGroup.CustomStructureColliders, false, this); while (generateStaticColliders.MoveNext()) { yield return(generateStaticColliders.Current); } break; case StructureBuildMethod.MeshInstances: var instanceMeshes = InstanceMeshes( mCurrentTemplateGroup, GetChildName(false, false, MinorParent.Number), mExteriorRenderers, mExteriorLODRenderers, Globals.StructureExteriorLODRatio); while (instanceMeshes.MoveNext()) { yield return(instanceMeshes.Current); } break; } //StructurePiece.transform.ResetLocal(); mCurrentTemplateGroup = null; break; } State = Builder.BuilderState.Finished; }