/// <summary> /// Reimports the script code resource according to the currently set import options. /// </summary> private void TriggerReimport() { ScriptCode scriptCode = (ScriptCode)InspectedObject; string resourcePath = ProjectLibrary.GetPath(scriptCode); ProjectLibrary.Reimport(resourcePath, importOptions, true); }
/// <summary> /// Retrieves import options for the resource we're currently inspecting. /// </summary> /// <returns>Script code import options object.</returns> private ScriptCodeImportOptions GetImportOptions() { ScriptCode scriptCode = InspectedObject as ScriptCode; ScriptCodeImportOptions output = null; if (scriptCode != null) { LibraryEntry libEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(scriptCode)); if (libEntry != null && libEntry.Type == LibraryEntryType.File) { FileEntry fileEntry = (FileEntry)libEntry; output = fileEntry.Options as ScriptCodeImportOptions; } } if (output == null) { if (importOptions == null) { output = new ScriptCodeImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Loads the currently inspected resource into the <see cref="InspectedObject"/> field. By default resources /// are not loaded and you can only retrieve their path through <see cref="InspectedResourcePath"/>. /// </summary> protected void LoadResource() { if (!string.IsNullOrEmpty(inspectedResourcePath)) { inspectedObject = ProjectLibrary.Load <Resource>(inspectedResourcePath); } }
/// <summary> /// Reimports the resource according to the currently set import options. /// </summary> private void TriggerReimport() { Mesh mesh = (Mesh)InspectedObject; string resourcePath = ProjectLibrary.GetPath(mesh); ProjectLibrary.Reimport(resourcePath, importOptions, true); }
/// <summary> /// Triggered when a resource is (re)imported in the project library. /// </summary> /// <param name="path">Path of the imported resource, relative to the project's resource folder.</param> private void OnEntryImported(string path) { LibraryEntry entry = ProjectLibrary.GetEntry(path); if (entry == null || entry.Type != LibraryEntryType.File) { return; } FileEntry fileEntry = (FileEntry)entry; if (fileEntry.ResType != ResourceType.ScriptCode) { return; } ScriptCode codeFile = ProjectLibrary.Load <ScriptCode>(path); if (codeFile == null) { return; } if (codeFile.EditorScript) { isEditorAssemblyDirty = true; } else { isGameAssemblyDirty = true; } }
/// <summary> /// Triggered when the user double-clicked on the entry. /// </summary> /// <param name="path">Project library path of the double-clicked entry.</param> private void OnEntryDoubleClicked(string path) { delayedSelect = false; LibraryEntry entry = ProjectLibrary.GetEntry(path); if (entry != null) { if (entry.Type == LibraryEntryType.Directory) { owner.Window.EnterDirectory(path); } else { ResourceMeta meta = ProjectLibrary.GetMeta(path); FileEntry fileEntry = (FileEntry)entry; if (meta.ResType == ResourceType.Prefab) { EditorApplication.LoadScene(fileEntry.Path); } else if (meta.ResType == ResourceType.ScriptCode) { ProgressBar.Show("Opening external code editor...", 1.0f); delayedOpenCodeEditorFrame = Time.FrameIdx + 1; } } } }
/// <summary> /// Reimports the resource according to the currently set import options. /// </summary> private void TriggerReimport() { AudioClip audioClip = (AudioClip)InspectedObject; string resourcePath = ProjectLibrary.GetPath(audioClip); ProjectLibrary.Reimport(resourcePath, importOptions, true); }
/// <summary> /// Retrieves import options for the audio clip we're currently inspecting. /// </summary> /// <returns>Audio clip import options object.</returns> private AudioClipImportOptions GetImportOptions() { AudioClip audioClip = InspectedObject as AudioClip; AudioClipImportOptions output = null; if (audioClip != null) { LibraryEntry meshEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(audioClip)); if (meshEntry != null && meshEntry.Type == LibraryEntryType.File) { FileEntry meshFileEntry = (FileEntry)meshEntry; output = meshFileEntry.Options as AudioClipImportOptions; } } if (output == null) { if (importOptions == null) { output = new AudioClipImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Retrieves import options for the texture we're currently inspecting. /// </summary> /// <returns>Font import options object.</returns> private FontImportOptions GetImportOptions() { Font font = InspectedObject as Font; FontImportOptions output = null; if (font != null) { LibraryEntry texEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(font)); if (texEntry != null && texEntry.Type == LibraryEntryType.File) { FileEntry texFileEntry = (FileEntry)texEntry; output = texFileEntry.Options as FontImportOptions; } } if (output == null) { if (importOptions == null) { output = new FontImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Checks is the resource at the provided path a file relevant to the code editor. /// </summary> /// <param name="path">Path to the resource, absolute or relative to the project's resources folder.</param> /// <returns>True if the file is relevant to the code editor, false otherwise.</returns> private bool IsCodeEditorFile(string path) { if (Path.GetExtension(path) == ".dll") { return(true); //Include assemblies. TODO: Make platform-agnostic. } LibraryEntry entry = ProjectLibrary.GetEntry(path); if (entry != null && entry.Type == LibraryEntryType.File) { FileEntry fileEntry = (FileEntry)entry; ResourceMeta[] resourceMetas = fileEntry.ResourceMetas; foreach (var codeType in CodeEditor.CodeTypes) { foreach (var meta in resourceMetas) { if (meta.ResType == codeType) { return(true); } } } } return(false); }
/// <summary> /// Retrieves import options for the mesh we're currently inspecting. /// </summary> /// <returns>Mesh import options object.</returns> private MeshImportOptions GetImportOptions() { Mesh mesh = InspectedObject as Mesh; MeshImportOptions output = null; if (mesh != null) { LibraryEntry meshEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(mesh)); if (meshEntry != null && meshEntry.Type == LibraryEntryType.File) { FileEntry meshFileEntry = (FileEntry)meshEntry; output = meshFileEntry.Options as MeshImportOptions; } } if (output == null) { if (importOptions == null) { output = new MeshImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Checks if a file or folder at the specified path exists in the library, and if it does generates a new unique /// name for the file or folder. /// </summary> /// <param name="path">Path to the file or folder to generate a unique name.</param> /// <returns>New path with the unique name. This will be unchanged from input path if the input path doesn't /// already exist.</returns> public static string GetUniquePath(string path) { string extension = Path.GetExtension(path); string pathClean = path; if (!String.IsNullOrEmpty(extension)) { pathClean = path.Remove(path.Length - extension.Length); } int idx = 0; int separatorIdx = pathClean.LastIndexOf('_'); if (separatorIdx != -1) { string numberString = pathClean.Substring(separatorIdx + 1, pathClean.Length - (separatorIdx + 1)); if (int.TryParse(numberString, out idx)) { pathClean = pathClean.Substring(0, separatorIdx); idx++; } } string destination = path; while (ProjectLibrary.Exists(destination)) { destination = pathClean + "_" + idx + extension; idx++; } return(destination); }
/// <summary> /// Retrieves import options for the texture we're currently inspecting. /// </summary> /// <returns>Texture import options object.</returns> private TextureImportOptions GetImportOptions() { TextureImportOptions output = null; LibraryEntry texEntry = ProjectLibrary.GetEntry(InspectedResourcePath); if (texEntry != null && texEntry.Type == LibraryEntryType.File) { FileEntry texFileEntry = (FileEntry)texEntry; output = texFileEntry.Options as TextureImportOptions; } if (output == null) { if (importOptions == null) { output = new TextureImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Retrieves import options for the audio clip we're currently inspecting. /// </summary> /// <returns>Audio clip import options object.</returns> private AudioClipImportOptions GetImportOptions() { AudioClipImportOptions output = null; LibraryEntry meshEntry = ProjectLibrary.GetEntry(InspectedResourcePath); if (meshEntry != null && meshEntry.Type == LibraryEntryType.File) { FileEntry meshFileEntry = (FileEntry)meshEntry; output = meshFileEntry.Options as AudioClipImportOptions; } if (output == null) { if (importOptions == null) { output = new AudioClipImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Opens a dialog to allows the user to select a location where to save the current scene. If scene was previously /// saved it is instead automatically saved at the last location. /// </summary> public static void SaveScene(Action onSuccess = null, Action onFailure = null) { if (!string.IsNullOrEmpty(Scene.ActiveSceneUUID)) { string scenePath = ProjectLibrary.GetPath(Scene.ActiveSceneUUID); if (!string.IsNullOrEmpty(scenePath)) { if (Scene.IsGenericPrefab) { SaveGenericPrefab(onSuccess, onFailure); } else { SaveScene(scenePath); if (onSuccess != null) { onSuccess(); } } } else { SaveSceneAs(onSuccess, onFailure); } } else { SaveSceneAs(onSuccess, onFailure); } }
public static void SaveProject() { // Apply changes to any animation clips edited using the animation editor foreach (var KVP in persistentData.dirtyAnimClips) { KVP.Value.SaveToClip(); } // Save all dirty resources to disk foreach (var KVP in persistentData.dirtyResources) { string resourceUUID = KVP.Key; string path = ProjectLibrary.GetPath(resourceUUID); if (!IsNative(path)) { continue; // Imported resources can't be changed } Resource resource = ProjectLibrary.Load <Resource>(path); if (resource != null) { ProjectLibrary.Save(resource); } } persistentData.dirtyAnimClips.Clear(); persistentData.dirtyResources.Clear(); SetStatusProject(false); Internal_SaveProject(); }
/// <summary> /// Triggered by the runtime when <see cref="LoadProject"/> method completes. /// </summary> private static void Internal_OnProjectLoaded() { SetStatusProject(false); if (!unitTestsExecuted) { RunUnitTests(); unitTestsExecuted = true; } if (!IsProjectLoaded) { ProjectWindow.Open(); return; } string projectPath = ProjectPath; RecentProject[] recentProjects = EditorSettings.RecentProjects; bool foundPath = false; for (int i = 0; i < recentProjects.Length; i++) { if (PathEx.Compare(recentProjects[i].path, projectPath)) { recentProjects[i].accessTimestamp = (ulong)DateTime.Now.Ticks; EditorSettings.RecentProjects = recentProjects; foundPath = true; break; } } if (!foundPath) { List <RecentProject> extendedRecentProjects = new List <RecentProject>(); extendedRecentProjects.AddRange(recentProjects); RecentProject newProject = new RecentProject(); newProject.path = projectPath; newProject.accessTimestamp = (ulong)DateTime.Now.Ticks; extendedRecentProjects.Add(newProject); EditorSettings.RecentProjects = extendedRecentProjects.ToArray(); } EditorSettings.LastOpenProject = projectPath; EditorSettings.Save(); ProjectLibrary.Refresh(); monitor = new FolderMonitor(ProjectLibrary.ResourceFolder); monitor.OnAdded += OnAssetModified; monitor.OnRemoved += OnAssetModified; monitor.OnModified += OnAssetModified; if (!string.IsNullOrWhiteSpace(ProjectSettings.LastOpenScene)) { Scene.Load(ProjectSettings.LastOpenScene); SetSceneDirty(false); } }
/// <summary> /// Retrieves import options for the texture we're currently inspecting. /// </summary> /// <returns>Texture import options object.</returns> private TextureImportOptions GetImportOptions() { Texture2D texture = InspectedObject as Texture2D; TextureImportOptions output = null; if (texture != null) { LibraryEntry texEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(texture)); if (texEntry != null && texEntry.Type == LibraryEntryType.File) { FileEntry texFileEntry = (FileEntry)texEntry; output = texFileEntry.Options as TextureImportOptions; } } if (output == null) { if (importOptions == null) { output = new TextureImportOptions(); } else { output = importOptions; } } return(output); }
/// <summary> /// Reimports the texture resource according to the currently set import options. /// </summary> private void TriggerReimport() { Texture2D texture = (Texture2D)InspectedObject; string resourcePath = ProjectLibrary.GetPath(texture); ProjectLibrary.Reimport(resourcePath, importOptions, true); }
/// <summary> /// Returns an icon that can be used for displaying a resource of the specified type. /// </summary> /// <param name="path">Path to the project library entry to display data for.</param> /// <param name="size">Size of the icon to retrieve, in pixels.</param> /// <returns>Icon to display for the specified entry.</returns> private static SpriteTexture GetIcon(string path, int size) { LibraryEntry entry = ProjectLibrary.GetEntry(path); if (entry.Type == LibraryEntryType.Directory) { return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Folder, size)); } else { ResourceMeta meta = ProjectLibrary.GetMeta(path); switch (meta.ResType) { case ResourceType.Font: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Font, size)); case ResourceType.Mesh: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Mesh, size)); case ResourceType.Texture: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Texture, size)); case ResourceType.PlainText: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PlainText, size)); case ResourceType.ScriptCode: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.ScriptCode, size)); case ResourceType.SpriteTexture: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.SpriteTexture, size)); case ResourceType.Shader: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size)); case ResourceType.ShaderInclude: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size)); case ResourceType.Material: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Material, size)); case ResourceType.Prefab: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Prefab, size)); case ResourceType.GUISkin: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.GUISkin, size)); case ResourceType.PhysicsMaterial: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PhysicsMaterial, size)); case ResourceType.PhysicsMesh: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PhysicsMesh, size)); case ResourceType.AudioClip: return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.AudioClip, size)); } } return(null); }
/// <summary> /// Creates a new folder with in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the new folder in.</param> public static void CreateFolder(string folder) { string path = Path.Combine(folder, "New Folder"); path = GetUniquePath(path); ProjectLibrary.CreateFolder(path); }
/// <summary> /// Triggered by the runtime when a resource is dropped on the scene tree view. /// </summary> private void Internal_DoOnResourceDropped(SceneObject parent, string[] resourcePaths) { if (resourcePaths == null) { return; } List <SceneObject> addedObjects = new List <SceneObject>(); for (int i = 0; i < resourcePaths.Length; i++) { ResourceMeta meta = ProjectLibrary.GetMeta(resourcePaths[i]); if (meta == null) { continue; } if (meta.ResType == ResourceType.Mesh) { if (!string.IsNullOrEmpty(resourcePaths[i])) { string meshName = Path.GetFileNameWithoutExtension(resourcePaths[i]); Mesh mesh = ProjectLibrary.Load <Mesh>(resourcePaths[i]); if (mesh == null) { continue; } SceneObject so = UndoRedo.CreateSO(meshName, "Created a new Renderable \"" + meshName + "\""); so.Parent = parent; Renderable renderable = so.AddComponent <Renderable>(); renderable.Mesh = mesh; addedObjects.Add(so); } } else if (meta.ResType == ResourceType.Prefab) { if (!string.IsNullOrEmpty(resourcePaths[i])) { Prefab prefab = ProjectLibrary.Load <Prefab>(resourcePaths[i]); SceneObject so = UndoRedo.Instantiate(prefab, "Instantiating " + prefab.Name); so.Parent = parent; addedObjects.Add(so); } } } if (addedObjects.Count > 0) { EditorApplication.SetSceneDirty(); } Selection.SceneObjects = addedObjects.ToArray(); }
/// <summary> /// Saves the currently loaded scene to the specified path. /// </summary> /// <param name="path">Path relative to the resource folder. This can be the path to the existing scene /// prefab if it just needs updating. </param> public static void SaveScene(string path) { Prefab scene = Internal_SaveScene(path); Scene.SetActive(scene); ProjectLibrary.Refresh(true); SetSceneDirty(false); }
/// <summary> /// Reimports the resource according to the currently set import options. /// </summary> private void TriggerReimport() { Mesh mesh = (Mesh)InspectedObject; string resourcePath = ProjectLibrary.GetPath(mesh); importOptions.AnimationClipSplits = splitInfos; ProjectLibrary.Reimport(resourcePath, importOptions, true); }
/// <summary> /// Creates a new shader containing a rough code outline in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the shader in.</param> public static void CreateEmptyShader(string folder) { string path = Path.Combine(folder, "New Shader.bsl"); path = Path.Combine(ProjectLibrary.ResourceFolder, path); path = GetUniquePath(path); File.WriteAllText(path, EditorBuiltin.EmptyShaderCode); ProjectLibrary.Refresh(path); }
/// <summary> /// Creates a new empty GUI skin in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the GUI skin in.</param> public static void CreateEmptyGUISkin(string folder) { string path = Path.Combine(folder, "New GUI Skin.asset"); path = GetUniquePath(path); GUISkin guiSkin = new GUISkin(); ProjectLibrary.Create(guiSkin, path); }
/// <summary> /// Creates a new empty string table in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the string table in.</param> public static void CreateEmptyStringTable(string folder) { string path = Path.Combine(folder, "New String Table.asset"); path = GetUniquePath(path); StringTable stringTable = new StringTable(); ProjectLibrary.Create(stringTable, path); }
/// <summary> /// Creates a new empty sprite texture in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the sprite texture in.</param> public static void CreateEmptySpriteTexture(string folder) { string path = Path.Combine(folder, "New Sprite Texture.asset"); path = GetUniquePath(path); SpriteTexture spriteTexture = new SpriteTexture(null); ProjectLibrary.Create(spriteTexture, path); }
/// <summary> /// Creates a new material with the default shader in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the material in.</param> public static void CreateEmptyMaterial(string folder) { string path = Path.Combine(folder, "New Material.asset"); path = GetUniquePath(path); Material material = new Material(Builtin.GetShader(BuiltinShader.Standard)); ProjectLibrary.Create(material, path); }
/// <summary> /// Creates a new physics material with the default properties in the specified folder. /// </summary> /// <param name="folder">Folder relative to project library to create the material in.</param> public static void CreateEmptyPhysicsMaterial(string folder) { string path = Path.Combine(folder, "New Physics Material.asset"); path = GetUniquePath(path); PhysicsMaterial material = new PhysicsMaterial(); ProjectLibrary.Create(material, path); }