Top Banner
Custom Editor
16
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Custom Editor Unity

Custom Editor

Page 2: Custom Editor Unity

Custom Editor1. Menu

2. Custom Inspector

3. Editor Window

4. Asset Database

Page 3: Custom Editor Unity

Menu• Menu Item

• Context Menu

• Context Menu Item

Page 4: Custom Editor Unity

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).

Page 5: Custom Editor Unity

Menu

Page 6: Custom Editor Unity

Menu

Page 7: Custom Editor Unity

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.

Page 8: Custom Editor Unity

Custom Inspectorusing UnityEditor;

Page 9: Custom Editor Unity

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

Page 10: Custom Editor Unity

Editor Windowusing UnityEditor;

Page 11: Custom Editor Unity

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.

Page 12: Custom Editor Unity

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.

Page 13: Custom Editor Unity

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

Page 14: Custom Editor Unity

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.)

Page 15: Custom Editor Unity

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.

Page 16: Custom Editor Unity

Asset Database