Unity APIs that may be useful but not mentioned in the documentation.
Tip: Press Ctrl+F on the list page to search for the keyword of the content you are looking for.
- Unity 6000.0.23f1 Undocumented APIs
- Unity 2022.3.0f1 Undocumented APIs
- Unity 2021.3.0f1 Undocumented APIs
- Unity 2020.3.48f1 Undocumented APIs
- Unity 2019.4.40f1 Undocumented APIs
Draw buttons on the header area of the EditorWindow:
// Unity message method
// Put in your EditorWindow class
void ShowButton(Rect position)
Open asset in a custom EditorWindow when double-clicking:
[CreateAssetMenu(fileName = nameof(MyCustomAsset), menuName = "Tests/My Custom Asset")]
public class MyCustomAsset : ScriptableObject { }
public class MyCustomAssetEditorWindow : EditorWindow
{
[OnOpenAsset]
static bool OnOpenAsset(int instanceID, int line, int column)
{
if (EditorUtility.InstanceIDToObject(instanceID) is MyCustomAsset myAsset)
{
var window = GetWindow<MyCustomAssetEditorWindow>();
window.SetTarget(myAsset);
window.Focus();
// Returning true indicates that the open operation has been processed
// and the callback is not continued.
return true;
}
// Returning false indicates that the open operation cannot be handled here,
// and other methods in the callback should be continued.
return false;
}
public void SetTarget(MyCustomAsset target)
{
// Do anything you want here.
titleContent = new GUIContent(target.name);
Debug.Log($"Open {target}.");
}
}
Modify menu items dynamically, no need for MenuItemAttribute:
The UnityEditor.Menu
class provides some methods for dynamically managing menu items, but these methods are internal
and can be called through reflection.
Here is a utility class that simplifies reflection: DynamicMenuItem.cs.
Keep serialized data after changing name or namespace of type:
Similar to UnityEngine.Serialization.FormerlySerializedAsAttribute
.
UnityEngine.Scripting.APIUpdating.MovedFromAttribute
Read/Write assets in Library/ProjectSettings/UserSettings folder:
UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget()
UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget()
Usually, the UnityEditor.ScriptableSingleton<T>
type can be used to create a singleton configuration asset stored in the Library folder, eliminating the need to use the above two methods.
Many helpful editor utility functions:
UnityEditorInternal.InternalEditorUtility
To be continued...