public static void CB_Scene_UpdateDatabase() { cb_scenes_displayProgressBar = true; cb_scenes_action = "Part 1 of 3: Getting scenes database..."; cb_scenes_progress = 1 / 2; if (!E_Helpers.DirExists(string.Format("Assets{0}Resources{0}ScenesDatabase{0}", Path.DirectorySeparatorChar))) { E_Helpers.CreateDirectory(string.Format("Assets{0}Resources{0}ScenesDatabase{0}", Path.DirectorySeparatorChar)); } SceneDatabase database; if (E_Helpers.FileExists(string.Format("Assets{0}Resources{0}ScenesDatabase{0}ScenesDatabase.asset", Path.DirectorySeparatorChar))) { database = (SceneDatabase)AssetDatabase.LoadAssetAtPath(string.Format("Assets{0}Resources{0}ScenesDatabase{0}ScenesDatabase.asset", Path.DirectorySeparatorChar), typeof(SceneDatabase)); } else { database = ScriptableObject.CreateInstance <SceneDatabase>(); AssetDatabase.CreateAsset(database, string.Format("Assets{0}Resources{0}ScenesDatabase{0}ScenesDatabase.asset", Path.DirectorySeparatorChar)); } cb_scenes_action = "Part 1 of 3: Gathering Scenes List..."; cb_scenes_progress = 2 / 2; List <DatabaseScene> scenes = (database.storedScenesData != null) ? database.storedScenesData : new List <DatabaseScene>(); scenes = scenes.Where(item => item != null).ToList(); EditorBuildSettingsScene[] editorScenes = EditorBuildSettings.scenes; for (int i = 0; i < editorScenes.Length; i++) { string sceneName = editorScenes[i].path.Split('/')[editorScenes[i].path.Split('/').Length - 1]; sceneName = sceneName.Replace(".unity", ""); cb_scenes_action = "Part 2 of 3: Adding Scene: " + sceneName; cb_scenes_progress = i / editorScenes.Length; int foundSceneIndex = scenes.FindIndex(target => target.name == sceneName); if (foundSceneIndex > -1) { scenes[foundSceneIndex].path = editorScenes[i].path; scenes[foundSceneIndex].index = i; scenes[foundSceneIndex].enabled = editorScenes[i].enabled; EditorUtility.SetDirty(scenes[foundSceneIndex]); } else { DatabaseScene newScene = ScriptableObject.CreateInstance <DatabaseScene>(); newScene.name = sceneName; newScene.path = editorScenes[i].path; newScene.sceneName = sceneName; newScene.index = i; newScene.enabled = editorScenes[i].enabled; AssetDatabase.CreateAsset(newScene, string.Format("Assets{0}Resources{0}ScenesDatabase{0}{1}.asset", Path.DirectorySeparatorChar, sceneName)); Debug.Log("Create " + sceneName + " scene asset."); scenes.Add(newScene); Debug.Log("Added " + sceneName + " scene asset to scene database."); } } SetAllLoadPointsInAllScenes(ref scenes); cb_scenes_action = "Part 3 of 3: Saving built database.. "; cb_scenes_progress = 1 / 1; database.storedScenesData = scenes; EditorUtility.SetDirty(database); AssetDatabase.SaveAssets(); cb_scenes_displayProgressBar = false; GameObject roomButton = E_Helpers.GetPrefabReference("Assets/InvectorMultiplayer/UI/RoomButton.prefab"); roomButton.GetComponent <RoomButton>().database = database; E_Helpers.SaveAsPrefab(roomButton, "Assets/InvectorMultiplayer/UI/RoomButton.prefab"); if (EditorUtility.DisplayDialog("Success!", "The scene database has successfully been updated!", "Okay")) { } Debug.Log("Successfully updated the ScenesDatabase!"); }
IEnumerator ConvertPlayer(GameObject targetObj) { GameObject _builtPrefab = null; convertLog.Clear(); _converting = true; _errorsOccured = false; if (convertLog != null) { convertLog.Add("Beginning to convert: " + targetObj.name); } if (convertLog != null) { convertLog.Add(""); } if (convertLog != null) { convertLog.Add("Copying " + targetObj.name + " -> MP_" + targetObj.name); } // Copy Player GameObject GameObject _copiedPlayer = GameObject.Instantiate(targetObj, targetObj.transform.position + Vector3.left, Quaternion.identity) as GameObject; _copiedPlayer.name = _copiedPlayer.name.Replace("(Clone)", ""); _copiedPlayer.name = "MP_" + _copiedPlayer.name; //Add Components if (CB_addVoiceChat == true) { CB_COMP_PlayerVoiceChat(_copiedPlayer, ref convertLog); } if (CB_addNameBar == true) { CB_COMP_PlayerNameBar(_copiedPlayer, ref convertLog); } CB_COMP_vMeleeCombatInput(_copiedPlayer, ref convertLog); CB_COMP_vWeaponHolderManager(_copiedPlayer, ref convertLog); CB_COMP_vGenericAction(_copiedPlayer, ref convertLog); CB_COMP_vMeleeManager(_copiedPlayer, ref convertLog); CB_COMP_vHeadTrack(_copiedPlayer, ref convertLog); CB_COMP_vShooterMeleeInput(_copiedPlayer, ref convertLog); CB_COMP_vShooterManager(_copiedPlayer, ref convertLog); CB_COMP_vFreeClimb(_copiedPlayer, ref convertLog); CB_COMP_vSwimming(_copiedPlayer, ref convertLog); CB_COMP_vZipline(_copiedPlayer, ref convertLog); CB_COMP_SyncPlayer(_copiedPlayer, ref convertLog); CB_COMP_vThirdPersonController(_copiedPlayer, ref convertLog); CB_COMP_vItemManager(_copiedPlayer, ref convertLog); CB_COMP_vLadderAction(_copiedPlayer, ref convertLog); // Make sure the file name is unique, in case an existing Prefab has the same name. string saveLocation = string.Format("Assets{0}Resources{0}{1}.prefab", Path.DirectorySeparatorChar, _copiedPlayer.name); if (E_Helpers.CreateDirectory(E_Helpers.GetDirectoryPath(saveLocation))) { if (convertLog != null) { convertLog.Add("Created Assets/Resources directory"); } } E_Helpers.SetObjectIcon(_copiedPlayer, E_Core.h_playerIcon); if (E_Helpers.FileExists(saveLocation)) { if (EditorUtility.DisplayDialog("Duplicate Detected!", "A prefab with the same name already exists, would you like to overwrite it or create a new one, keeping both?", "Overwrite", "Keep Both")) { //Overwrite E_Helpers.DeleteFile(saveLocation); if (convertLog != null) { convertLog.Add("Generating prefab at: " + saveLocation); } PrefabUtility.SaveAsPrefabAsset(_copiedPlayer, saveLocation); } else { //Keep Both saveLocation = AssetDatabase.GenerateUniqueAssetPath(saveLocation); if (convertLog != null) { convertLog.Add("Generating prefab at: " + saveLocation); } PrefabUtility.SaveAsPrefabAsset(_copiedPlayer, saveLocation); } } else { saveLocation = AssetDatabase.GenerateUniqueAssetPath(saveLocation); if (convertLog != null) { convertLog.Add("Generating prefab at: " + saveLocation); } PrefabUtility.SaveAsPrefabAsset(_copiedPlayer, saveLocation); } if (FindObjectOfType <NetworkManager>()) { if (convertLog != null) { convertLog.Add("Adding generated prefab to the \"playerPrefab\" field in the \"NetworkManager\""); } _builtPrefab = E_Helpers.GetPrefabReference(saveLocation); int timeout = 4; int count = 0; while (_builtPrefab == null) { if (count == timeout) { Debug.LogWarning("Unable to locate the player prefab to place into the NetworkManager."); break; } yield return(new WaitForSeconds(0.5f)); count += 1; _builtPrefab = E_Helpers.GetPrefabReference(saveLocation); } FindObjectOfType <NetworkManager>().playerPrefab = _builtPrefab; } else { if (convertLog != null) { convertLog.Add("WARNING: Skipped adding to \"NetworkManager\" component."); } if (EditorUtility.DisplayDialog("Unable To Find NetworkManager", "No NetworkManager was found in the scene so this converted player was not added to the \"playerPrefab\"!" + " When the NetworkManager is added to the scene make sure to add the generated prefab in the \"Resources\" folder to that field.", "Okay")) { Debug.LogWarning("No NetworkManager component was found in the scene so this prefab was not added a spawn object. When the NetworkManager component is added to the scene please add a prefab to it."); } } Selection.activeObject = _copiedPlayer; foreach (string log in convertLog) { Debug.Log(log); } yield return(null); }