Custom Editor
Aug 08, 2015
Custom Editor
Custom Editor1. Menu
2. Custom Inspector
3. Editor Window
4. Asset Database
Menu• Menu Item
• Context Menu
• Context Menu Item
Menu• The MenuItem attribute allows you to add menu items to the main menu and inspector
context menus.
• The MenuItem attribute turns any static function into a menu command. Only static functions can use the MenuItem attribute.
• To create a hotkey you can use the following special characters: % (ctrl on Windows, cmd on OS X), # (shift), & (alt), <b>_</b> (no key modifiers). For example to create a menu with hotkey shift-alt-g use "MyMenu/Do Something #&g". To create a menu with hotkey g and no key modifiers pressed use "MyMenu/Do Something _g".
• Some special keyboard keys are supported as hotkeys, for example "#LEFT" would map to shift-left. The keys supported like this are: LEFT, RIGHT, UP, DOWN, F1 .. F12, HOME, END, PGUP, PGDN.
• A hotkey text must be preceded with a space character ("MyMenu/Do_g" won't be interpreted as hotkey, while "MyMenu/Do _g" will).
Menu
Menu
Custom InspectorUnity lets you extend the editor with your own Custom Inspectors and Editor Windows and you can define how properties are displayed in the inspector with custom Property Drawers.
Custom Inspectorusing UnityEditor;
Editor Window• You can create any number of custom windows in your app.
• These behave just like the Inspector, Scene or any other built-in ones.
• This is a great way to add a user interface to a sub-system for your game
Editor Windowusing UnityEditor;
Asset Database• AssetDatabase is an API which allows you to access
the assets contained in your project
• Among other things, it provides methods to find and load assets and also to create, delete and modify them.
Asset Database• Importing an Asset
Unity normally imports assets automatically when they are dragged into the project but it is also possible to import them under script control. To do this you can use the AssetDatabase.ImportAsset method as in the example below.
Asset Database• Loading an Asset
The editor loads assets only as needed, say if they are added to the scene or edited from the Inspector panel. However, you can load and access assets from a script
Asset Database• Create an Asset
- Creates a new asset at path. - You must ensure that the path uses a supported extension ('.mat' for
materials, '.cubemap' for cubemaps, '.GUISkin' for skins, '.anim' for animations and '.asset' for arbitrary other assets.)
Asset Database• ScriptableObject
- A class you can derive from if you want to create objects that don't need to be attached to game objects.
- This is most useful for assets which are only meant to store data.
Asset Database