in IndoorSceneSynthesis/ConstraintStochasticIndoorSceneGeneration/Custom/CustomEditor/CSceneCopier.cs [436:571]
public void CopyStructure2NewScene() {
Assert.IsTrue(m_SceneAssets.Count == m_SceneNames.Count);
IEnumerator SequentialCopyScenes() {
for (int i = 0; i < m_SceneAssets.Count; ++i) {
SceneAsset fromScene = m_SceneAssets[i];
string newSceneName = m_SceneNames[i];
string scenePath = AssetDatabase.GetAssetPath(fromScene);
Debug.Log("Copy Scene from scene path: " + scenePath + " \n Scene name: " + newSceneName.ToString());
EditorSceneManager.OpenScene(scenePath);
//new scene
string saveSceneFolder = "Assets/Custom/";
string saveScenePath = saveSceneFolder + newSceneName + ".unity";
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), saveScenePath, true);
EditorSceneManager.OpenScene(saveScenePath);
//EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent("Paste"));
StructureObject[] structObjs = GameObject.FindObjectsOfType<StructureObject>();
foreach (StructureObject structObj in structObjs) {
if (structObj.WhatIsMyStructureObjectTag == StructureObjectTag.Ceiling) {
structObj.gameObject.SetActive(false);
}
}
GameObject structureAttr = new GameObject();
structureAttr.name = "StructureAttr";
GameObject structure = GameObject.Find("Structure");
structureAttr.transform.parent = structure.transform;
//Copy floor/window/curtain
//Set floor
GameObject obbjects = GameObject.Find("Objects");
List<GameObject> structureInObjects = new List<GameObject>();
if (obbjects != null) {
if (CSceneBuilderTool.samplingRoomType == CRoomType.Bathroom) {
foreach (Transform child in obbjects.transform) {
string childName = child.gameObject.name;
if (childName.Contains("Floor_") || childName.Contains("Window_") || childName.Contains("Curtains_") ||
childName.Contains("Bathtub") || childName.Contains("ShowerCurtain_") || childName.Contains("ShowerHead_") ||
childName.Contains("ShowerGlass_") || childName.Contains("ShowerDoor_") ||
childName.Contains("CounterTop_") || childName.Contains("Sink_") || childName.Contains("Cabinet_") ||
childName.Contains("Drawer_") || childName.Contains("Mirror") || childName.Contains("CabinetMesh") ||
childName.Contains("Faucet_") || childName.Contains("BathroomSink") || childName.Contains("CabinetBody") ||
childName.Contains("FP424:polySurface389") //special cases
) {
structureInObjects.Add(child.gameObject);
}
}
}
if (CSceneBuilderTool.samplingRoomType == CRoomType.LivingRoom) {
foreach (Transform child in obbjects.transform) {
string childName = child.gameObject.name;
if (childName.Contains("Floor_") || childName.Contains("Window_") || childName.Contains("Curtains_")) {
structureInObjects.Add(child.gameObject);
}
}
}
if (CSceneBuilderTool.samplingRoomType == CRoomType.Kitchen) {
foreach (Transform child in obbjects.transform) {
string childName = child.gameObject.name;
if (childName.Contains("Burner") ||
childName.Contains("CounterTop_") || childName.Contains("Sink_") || childName.Contains("Cabinet_") ||
childName.Contains("Drawer_") || childName.Contains("Burner_") || childName.Contains("StoveKnob_") ||
childName.Contains("Faucet_") || childName.Contains("OvenTop")
) {
structureInObjects.Add(child.gameObject);
}
}
}
}
foreach (GameObject go in structureInObjects) {
go.transform.parent = structureAttr.transform;
}
//Delete furniture and objects
DestroyImmediate(obbjects);
//Filter out unneccessary structure
GameObject roomStruct = GameObject.Find("Structure");
List<GameObject> objsUnnecessary = new List<GameObject>();
if (roomStruct != null) {
if (CSceneBuilderTool.samplingRoomType == CRoomType.Kitchen) {
foreach (Transform child in roomStruct.transform) {
string childName = child.gameObject.name;
if (childName.Contains("FloorPlan")) {
foreach (Transform childchild in child.transform) {
if (childchild.gameObject.name.Contains("Ladle") || childchild.gameObject.name.Contains("Kettle") ||
childchild.gameObject.name.Contains("Vase") || childchild.gameObject.name.Contains("PlateStack") ||
childchild.gameObject.name.Contains("Spatula") || childchild.gameObject.name.Contains("PaperClutter") ||
childchild.gameObject.name.Contains("Pitcher") || childchild.gameObject.name.Contains("Pot") ||
childchild.gameObject.name.Contains("Bowl") || childchild.gameObject.name.Contains("WineGlasses") ||
childchild.gameObject.name.Contains("Jar") || childchild.gameObject.name.Contains("Decals") ||
childchild.gameObject.name.Contains("TurkeyPan") || childchild.gameObject.name.Contains("WineGlass") ||
childchild.gameObject.name.Contains("Mug") || childchild.gameObject.name.Contains("SaltShaker") ||
childchild.gameObject.name.Contains("Ladel") || childchild.gameObject.name.Contains("Bottle") ||
childchild.gameObject.name.Contains("Bucket") || childchild.gameObject.name.Contains("CuttingBoard") ||
childchild.gameObject.name.Contains("Cup") //|| childchild.gameObject.name.Contains("CuttingBoard")
) {
//childchild.gameObject.SetActive(false);
objsUnnecessary.Add(childchild.gameObject);
}
}
}
if (childName.Contains("PaperClutter")) {
objsUnnecessary.Add(child.gameObject);
}
}
}
}
//Delete objs
foreach (var obj in objsUnnecessary) {
DestroyImmediate(obj);
}
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
yield return new EditorWaitForSeconds(2);
}
}
EditorCoroutineUtility.StartCoroutineOwnerless(SequentialCopyScenes());
}