Class ScyllaEditorAssetUtil
Creates and locates project assets, with the folder and undo handling done once.
Inherited Members
Namespace: Scylla.Core.Editor
Assembly: ScyllaCore.Editor.dll
Syntax
public static class ScyllaEditorAssetUtil
Remarks
Asset creation is deceptively fiddly: the containing folders have to exist first, CreateFolder(string, string) only makes one level at a time, a created asset should join the undo stack so the action that made it can be walked back, and the database needs saving and refreshing afterwards. Scylla had that sequence written out separately in a dozen places, each getting a slightly different subset right.
Editor-only, main thread only.
Methods
CreateScriptableObject<T>(string, bool, string)
Creates a UnityEngine.ScriptableObject asset at a path, creating folders as needed.
Declaration
public static T CreateScriptableObject<T>(string assetPath, bool registerUndo = true, string undoName = null) where T : ScriptableObject
Parameters
| Type | Name | Description |
|---|---|---|
| string | assetPath | Project-relative path including the |
| bool | registerUndo | Whether to add the creation to the undo stack. |
| string | undoName | Undo entry label. Defaults to |
Returns
| Type | Description |
|---|---|
| T | The created asset. |
Type Parameters
| Name | Description |
|---|---|
| T | The asset type to instantiate. |
Remarks
The asset is registered with the undo system, so whatever action created it can be
undone as one step and the file is removed cleanly. Pass false only for
assets created outside a user action, such as a first-run default.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the path is empty. |
EnsureFolder(string)
Creates a project folder and every missing folder above it.
Declaration
public static bool EnsureFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Project-relative folder path, for example |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Recursive, unlike CreateFolder(string, string), which creates a single level and silently fails when its parent is missing. Callers previously worked around that by invoking a one-level helper once per path segment, which is easy to get wrong by one level and produces no error when it happens.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the path is empty or is not under |
GetUniqueAssetPath(string)
Returns a path that does not collide with an existing asset.
Declaration
public static string GetUniqueAssetPath(string assetPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | assetPath | The desired project-relative path. |
Returns
| Type | Description |
|---|---|
| string | A free path, suffixed with a number when needed. |
Remarks
Delegates to GenerateUniqueAssetPath(string), but ensures the containing folder exists first. Without that the call returns the path unchanged for a folder that does not exist, so two assets created in a new folder in the same frame would collide.
LoadCachedStyleSheet(ref StyleSheet, string, string, string, Assembly)
Resolves and caches one stylesheet, looking in the development project first and then in the installed package.
Declaration
public static StyleSheet LoadCachedStyleSheet(ref StyleSheet slot, string fileName, string devPath, string packageSubPath, Assembly assembly)
Parameters
| Type | Name | Description |
|---|---|---|
| StyleSheet | slot | The static cache field for this sheet, passed by reference. |
| string | fileName | The file name without its extension, for example |
| string | devPath | The folder the sheet lives in inside the development project, ending in a slash. |
| string | packageSubPath | The folder inside the installed package, ending in a slash. |
| Assembly | assembly | The assembly whose package should be searched. Pass the calling module's own assembly, since the package that ships the sheet is the one that ships the code asking for it. |
Returns
| Type | Description |
|---|---|
| StyleSheet | The sheet, or |
Remarks
Public so that a module shipping its own stylesheets does not have to copy this two-location lookup. Each module keeps its own cache fields and its own paths and passes them in; only the resolution logic is shared.
LoadOrCreateScriptableObject<T>(string, out bool)
Loads the asset at a path, creating it when it is not there yet.
Declaration
public static T LoadOrCreateScriptableObject<T>(string assetPath, out bool wasCreated) where T : ScriptableObject
Parameters
| Type | Name | Description |
|---|---|---|
| string | assetPath | Project-relative path including the extension. |
| bool | wasCreated | Receives |
Returns
| Type | Description |
|---|---|
| T | The existing or newly created asset. |
Type Parameters
| Name | Description |
|---|---|
| T | The asset type. |
Remarks
Never registers an undo step. A caller using this wants the asset to exist, and an undo that deleted it out from under them would be surprising rather than helpful.
Reveal(Object)
Selects an asset in the Project window and flashes it.
Declaration
public static void Reveal(Object asset)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | asset | The asset to reveal. Ignored when |