internal SceneCondition CreateNewCondition(string name, System.Type conditionType) { if (string.IsNullOrEmpty(name)) { Debug.LogError("Name not provided"); return(null); } if (conditionType == null) { return(null); } if (!conditionType.IsOrIsSubclassOf(typeof(SceneCondition))) { Debug.LogError("Provided type does not derive from Scene Condition, cannot create"); return(null); } SceneCondition newCondition = AssetDatabaseExtensions.CreateSubScriptableObject(TargetManager, conditionType, name) as SceneCondition; Undo.RegisterCreatedObjectUndo(newCondition, "Create Condition"); return(newCondition); }
private void InitializeDefaults() { SceneManagerAssetPath = AssetDatabase.GetAssetPath(SerializedManager.targetObject); bool wasCreated = false; AssetFilter assetFilter = AssetDatabaseExtensions. FindOrCreateSubScriptableObject <AssetFilter>(SceneManagerAssetPath, "SceneFilter", out wasCreated); if (wasCreated) { assetFilter.IncludeIfNoMatch = true; } SerializedSceneFilter = new SerializedObject(assetFilter); SceneHunter sceneHunter = AssetDatabaseExtensions. GetFirstSubAssetOf <SceneHunter>(SceneManagerAssetPath); if (sceneHunter == null) { sceneHunter = AssetDatabaseExtensions. CreateSubScriptableObject <UnitySceneHunter>(SceneManagerAssetPath, "SceneHunter"); } ScenePopulator = new SerializedObject(sceneHunter); SceneNodes = AssetDatabaseExtensions. FindOrCreateSubScriptableObject <SceneNodeCollection>(SceneManagerAssetPath, "SceneNodes", out wasCreated); if (wasCreated) { SceneNodes.SceneManager = TargetManager; } SceneNodes.PopulateSceneInfos(); SceneNodesObject = new SerializedObject(SceneNodes); SceneNodesProp = SceneNodesObject.FindProperty("sceneNodes"); if (AssetDatabaseExtensions.GetSubAssetsOfType <SceneVariableContainer>(TargetManager).Count() == 0) { TargetManager.SceneVariables.name = "ManagerVariables"; AssetDatabase.AddObjectToAsset(TargetManager.SceneVariables, TargetManager); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(TargetManager)); } SerializedManager.ApplyModifiedProperties(); ScenesProp = SerializedManager.FindProperty("scenes"); EntrySceneIdProp = SerializedManager.FindProperty("entrySceneId"); AnyScenesProp = SerializedManager.FindProperty("anyScene"); UseOnPlayProp = SerializedManager.FindProperty("useOnPlay"); GoToOnPlay = SerializedManager.FindProperty("goToOnPlay"); SerializedVariables = new SerializedSceneVariableCollection(TargetManager.SceneVariables); }
/// <summary> /// Retrieves all assets with the .unity extension /// </summary> /// <returns>Retrieves all assets with the .unity extension</returns> public override IEnumerable <string> GetScenePaths() { IEnumerable <string> assetPaths = AssetDatabaseExtensions.FindAssetPathsWithExtension(".unity"); switch (Sorting) { case SortMode.NONE: default: return(assetPaths); case SortMode.ASCENDING: return(assetPaths.OrderBy((x) => x)); case SortMode.DESCENDING: return(assetPaths.OrderByDescending((x) => x)); } }
/// <summary> /// Checks every scene model in every scene manager to determine if the moved /// scene was a dependency and updates the path if so /// </summary> /// <param name="sourcePath">Where the file originated</param> /// <param name="destinationPath">Where the file is going</param> private static void UpdateSceneAssetPaths(string sourcePath, string destinationPath) { if (!IsValidSceneItem(sourcePath)) { return; } foreach (SceneManagerController controller in AssetDatabaseExtensions.GetAssetIterator <SceneManagerController>()) { SerializedObject serializedController = new SerializedObject(controller); SerializedProperty scenesProp = serializedController.FindProperty("scenes"); for (int i = 0; i < scenesProp.arraySize; i++) { SerializedProperty currentProp = scenesProp.GetArrayElementAtIndex(i); SerializedProperty pathProp = currentProp.FindPropertyRelative("sceneAssetPath"); // Check if this scene model is pointing to the active scene if (!pathProp.stringValue.Equals(sourcePath)) { continue; } pathProp.stringValue = destinationPath; SerializedProperty nameProp = currentProp.FindPropertyRelative("sceneName"); string sourcePathSceneName = System.IO.Path.GetFileNameWithoutExtension(nameProp.stringValue); string destPathSceneName = System.IO.Path.GetFileNameWithoutExtension(destinationPath); // If the scene name matched the file path, update the scene // name with the new path name if (nameProp.stringValue.Equals(sourcePathSceneName, StringComparison.OrdinalIgnoreCase)) { nameProp.stringValue = destPathSceneName; } break; } // Renames can't be undone, so updating scene path shouldn't either serializedController.ApplyModifiedPropertiesWithoutUndo(); SceneManagerEditorWindow.RefreshOpenSceneManagementWindow(); } }
private void OnNewConditionTypeSelected(System.Object selectedType) { Type type = selectedType as Type; if (type == null) { return; } string assetName = AssetDatabaseExtensions.GetUniqueSubAssetName( serializedManager.TargetManager, type.Name, StringComparison.OrdinalIgnoreCase); SceneCondition created = serializedManager.CreateNewCondition(assetName, type); conditionsListProperty.AddArrayObjectValue(created); }
private void VariableCollectionEditor_OnVariableNameChanged(object sender, ValueChangedEventArgs <string> e) { IEnumerable <ScriptableObject> subAssets = AssetDatabaseExtensions. GetSubAssetsOfType <ScriptableObject>(sceneManager); ScriptableObject foundSubAsset = subAssets.Where( (x) => x.name == e.OldValue).FirstOrDefault(); if (foundSubAsset == null) { Debug.Log("Failed to rename variable"); return; } foundSubAsset.name = e.NewValue; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(sceneManager)); }
private static void GenerateMapPreviews() { Debug.Log("Generating map previews"); string oldScenePath = EditorSceneManager.GetActiveScene().path; GameObject[] mapPrefabs = AssetDatabaseExtensions.LoadAllAssetsInDir <GameObject>(MAP_PREFABS_PATH); foreach (GameObject mapPrefab in mapPrefabs) { EditorSceneManager.OpenScene(ARENA_SCENE_PATH, OpenSceneMode.Single); // Setup the scene for the screenshot GameObject map = GameObject.Instantiate(mapPrefab, Vector3.zero, Quaternion.identity); map.GetComponent <Map>().SpawnPreviewLabels(); // Disable canvas GameObject.FindGameObjectWithTag("MainCanvas").SetActive(false); // Grab the preview shot RenderTexture oldTargetTex = Camera.main.targetTexture; RenderTexture oldActiveTex = RenderTexture.active; Camera.main.targetTexture = new RenderTexture(PREVIEW_WIDTH, PREVIEW_HEIGHT, 24, RenderTextureFormat.ARGB32); RenderTexture.active = Camera.main.targetTexture; Camera.main.Render(); Texture2D tex = new Texture2D(PREVIEW_WIDTH, PREVIEW_HEIGHT, TextureFormat.ARGB32, false); tex.ReadPixels(new Rect(0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT), 0, 0); tex.Apply(); Camera.main.targetTexture = oldTargetTex; RenderTexture.active = oldActiveTex; // Save it byte[] bytes = tex.EncodeToPNG(); string previewPath = MAP_PREVIEWS_PATH + mapPrefab.name + ".png"; File.WriteAllBytes(previewPath, bytes); AssetDatabase.ImportAsset(previewPath); Debug.Log("Successfully generated " + previewPath); } EditorSceneManager.OpenScene(oldScenePath); }
/// <summary> /// Retrieves the scene paths for all of the selected extensions /// </summary> /// <returns>Retrieves the scene paths for all of the selected extensions</returns> public override IEnumerable <string> GetScenePaths() { IEnumerable <System.Enum> selectedExtensions = ExtensionsToFind.GetEnabledFlagsInt(); IEnumerable <string> assetPaths = AssetDatabaseExtensions.FindAssetPathsWithAnyExtension( selectedExtensions.Select((ext) => ext.ToString().ToLowerInvariant())); switch (Sorting) { case SortMode.NONE: default: return(assetPaths); case SortMode.ASCENDING: return(assetPaths.OrderBy((x) => x)); case SortMode.DESCENDING: return(assetPaths.OrderByDescending((x) => x)); } }
private static void RemoveSceneAsset(string sourcePath) { if (!IsValidSceneItem(sourcePath)) { return; } foreach (SceneManagerController controller in AssetDatabaseExtensions.GetAssetIterator <SceneManagerController>()) { controller.RemoveScene(sourcePath); SceneNodeCollection nodes = AssetDatabaseExtensions.GetFirstSubAssetOf <SceneNodeCollection>(controller); if (nodes != null) { nodes.RemoveSceneNodesByPath(sourcePath); } } SceneManagerEditorWindow.RefreshOpenSceneManagementWindow(); }
public void ReplaceScenePopulator(System.Type scenePopulatorType) { if (!scenePopulatorType.IsSubclassOf(typeof(SceneHunter))) { return; } Undo.SetCurrentGroupName("Scene Populator Change"); int undoGroup = Undo.GetCurrentGroup(); Undo.DestroyObjectImmediate(ScenePopulator.targetObject); ScenePopulator = new SerializedObject(AssetDatabaseExtensions. FindOrCreateSubScriptableObject <SceneHunter>(TargetManager, scenePopulatorType, "SceneHunter")); Undo.RegisterCreatedObjectUndo(ScenePopulator.targetObject, "Scene Populator Creation"); Undo.CollapseUndoOperations(undoGroup); AssetDatabase.ImportAsset(SceneManagerAssetPath); SerializedManager.ApplyModifiedProperties(); SerializedManager.Update(); }
internal void CreateNewVariable(string name, System.Type typeToCreate) { if (!CanCreateVariable(name, typeToCreate)) { return; } ScriptableObject variableType = AssetDatabaseExtensions.CreateSubScriptableObject(SceneVariablesContainer, typeToCreate, name); Undo.SetCurrentGroupName("Variable " + name + " creation"); int undoGroup = Undo.GetCurrentGroup(); Undo.RegisterCreatedObjectUndo(variableType, "Created " + name); Undo.RegisterCompleteObjectUndo(SceneVariablesContainer, "Created " + name); SceneVariablesContainer.CreateNewVariable(name, variableType); SerializedContainer.Update(); Undo.CollapseUndoOperations(undoGroup); }