WeaverEditorUtilities Class

Summary

[Editor-Only] A variety of miscellaneous utility methods.
Assembly
Weaver.dll
Namespace
Weaver.Editor
Base Types
  • Object
graph BT Type-->Base0["Object"] Type["WeaverEditorUtilities"] class Type type-node

Syntax

public static class WeaverEditorUtilities

Fields

Name Constant Value Summary
ErrorColor
[Editor-Only] The UnityEngine.Color used to indicate an error.
static
WarningColor
[Editor-Only] The UnityEngine.Color used to indicate a warning.
static

Properties

Name Value Summary
DontExpandWidth GUILayoutOption[]
[Editor-Only] The cached result of UnityEngine.GUILayout.ExpandWidth(System.Boolean) with a false parameter.
static
ForceGenerate bool
[Editor-Only] Some assets (such as scripts) don't always need to regenerate. This property is set to true when the user generates a single asset rather than a group.
static
IsBuilding bool
[Editor-Only] Indicates whether a runtime build is currently being compiled.
static
IsPreprocessingBuild bool
[Editor-Only] UnityEditor.BuildPipeline.isBuildingPlayer isn't true during UnityEditor.Build.IPreprocessBuildWithReport.OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport) so we use this value instead.
static
WeaverPluginsDirectory string
The asset path of the folder containing the Weaver assembly. "Assets/Plugins/Weaver" by default.
static

Methods

Name Value Summary
AddLinkToURL(GenericMenu, string, string) void
Adds a function to open the specified `url`. If it begins with a '/' it is treated as a path relative to the Weaver.WeaverUtilities.DocumentationURL.
static
AssetToResourcePath(string, int) string
Returns the resource path substring of the `assetPath` starting at the `resourcePathStart` and ending without the file extension.
static
ClearAssetPathCache() void
Clears all paths cached by Weaver.Editor.WeaverEditorUtilities.FindAllAssetPaths(System.Type).
static
ContainsNonMetaFiles(string, string[]) bool
[Editor-Only] Checks if the specified directory contains any files which don't end with ".meta".
static
CreateNewAsset(Type, string) Object
Creates a new asset of the specified `type` at the specified `assetPath`.
static
DeleteEmptyDirectories(string) void
[Editor-Only] Deletes the specified directory if it is empty (ignoring metadata files), then does the same recursively for each parent directory. Refreshes the UnityEditor.AssetDatabase if anything was deleted.
static
DestroySubAssets(string) void
[Editor-Only] Destroys all sub-assets which are part of the specified asset.
static
DoLayoutListFixed(ReorderableList, GUILayoutOption[]) void
[Editor-Only] Works like UnityEditorInternal.ReorderableList.DoLayoutList but doesn't screw up the padding while a fade group is animating.
static
DoToggle(bool, string, string) bool
[Editor-Only] Draws a UnityEngine.GUILayout.Toggle(System.Boolean,UnityEngine.GUIContent,UnityEngine.GUILayoutOption[]) and returns true if the value is changed.
static
EditorStartCoroutine(IEnumerator) EditorApplication.CallbackFunction
[Editor-Only] Starts a coroutine to run in the editor update loop. The coroutine can be cancelled by removing the returned delegate from UnityEditor.EditorApplication.update.
static
FindAllAssetPaths(Type) string[]
Returns the paths of all assets of the specified `type`.

The result is cached for efficiency and can be cleared by Weaver.Editor.WeaverEditorUtilities.ClearAssetPathCache.

If the `type` is a UnityEngine.Component, this method returns the paths of all prefabs so they will need to be checked for that component individually.
static
FindAsset<T>() T
Returns an asset of the specified type from anywhere in the project.
static
FindAsset<T>(string) T
Returns an asset of the specified type from anywhere in the project. Checks the `assetPathHint` before searching the rest of the project.
static
GetAttributeDisplayString(Type) string
Returns a friendly display string for the specified attribute `type` surrounded by square brackets.

For example, Weaver.AssetReferenceAttribute would return "[AssetReference]".
static
GetDefaultFileExtension(Type) string
[Editor-Only] Returns the default file extension for a type derived from UnityEngine.Object.
static
GetFullNameWithoutNamespace(Type) string
Returns the full name of the `type` and any types it is nested inside, but without the namespace prefix.
static
GetGameObject(Object, Component) GameObject
[Editor-Only] If `obj` is a UnityEngine.GameObject this method casts and returns it. Or if it is a UnityEngine.Component this method returns its UnityEngine.Component.gameObject and outputs the `component`. Otherwise it returns null.
static
GetPathWithoutExtension(string) string
Returns a copy of the `path` with the file extension removed from the end and caches the result.
static
GUIDsToAssetPaths(string[]) void
Replaces each GUID in an array with the corresponding asset path using UnityEditor.AssetDatabase.GUIDToAssetPath(System.String)
static
IsEditorOnly(Type) bool
[Editor-Only] Tries to determine whether the `type` is only available in the Unity Editor.
static
IsResource(string, int) bool
Returns true if the specified path includes a "Resources" folder, along with the character index at which the resource path starts (the character after the "Resources" folder).
static
OpenRelativeURL(string) void
Opens the specified `url`. If it begins with a '/' it is treated as a path relative to the Weaver.WeaverUtilities.DocumentationURL.
static
SaveSubAssets(Object, Object) bool
[Editor-Only] After you save the scene object `obj` as an asset file and load it as `asset`, this method goes through all the serialized UnityEngine.Object fields which weren't saved and adds them as sub-assets. Returns true if any sub-assets were saved.

For example, creating a procedural UnityEngine.Mesh, assigning it to a UnityEngine.MeshFilter, and saving the object as a prefab would not save the mesh anywhere unless you call this method or UnityEditor.AssetDatabase.AddObjectToAsset(UnityEngine.Object,UnityEngine.Object).
static
SetHideFlagsRecursive(Transform, HideFlags) void
Sets transform.hideFlags = flags and does the same for all the children of `transform`.
static
TempContent(string, string, Texture) GUIContent
Returns a UnityEngine.GUIContent containing the specified parameters. The same object is returned every time so it can be reused without causing garbage collection.
static
TempTypeContent(Type) GUIContent
[Editor-Only] Returns a UnityEngine.GUIContent using the type name as the text, full name as the tooltip, and UnityEditor.AssetPreview icon as the image (if it has one). The same object is returned every time so it can be reused without causing garbage collection.
static