Extending unity3d Editor
Develop Tools that fasten game development
Seminar
Frag Games
DisclaimerThe purpose of these slides is to give general overview how
to extend unity3d editor to unity3d dev team of company(frag
games).
I did not own the whole material of these slides most of the
stuff is taken from unity3d Documentation.
Custom Editor
IMGUI Basics
Property Drawers
Custom Editor
Custom Windows
Gizmos
Scriptable Objects
Unity Seralization
April 25 2016Presented by Ahmed
Roadmap
This Seminar is divided in two parts
Part-oneIMGUI Basics
Property Drawers
Custom Editor
Part-TwoCustom Windows
Scriptable Objects
Unity Serialization
Gizmos
immediate mode GUI (imgui)
Immediate mode vs Retained modeNo setup required
Specify GUI Components as
function calls
Inefficient for game UI
Good for editor scripting
Requires setup
Retains information about GUI
Respond to callbacks
Main GUI Components.Unity provides three classes GUI, EditorGUI & EditorGUILayout
which contains function to draw GUI components.
GUI class can be used for both in game & editor code.
EditorGUILayout is auto-layout version of EditorGUI
Basic ComponentsLable
Button
Toggle
FloatField | IntField
Vect3Field
TextField
ColorField
BeginScrollView
BeginHorizontal
example
How Unity Scripts are Build
Phase 1
Phase 2
Phase 3
Phase 4
Assets folder has same
physical path.
Property Drawers
Property DrawersProperty Drawers can be used
to customize the look of
certains controls in
Inspector.
There are two types of
property drawers
Built in
Custom
builtin-Example
Custom property Drawersfor serialized classes
For Fields as Attributes
Property Drawer for serialized class
Code SnapShotPlace this script
in Editor folder
Property Drawer Of Field
Code SnapShotInherits with
PropertyAttribute
Inherits propertyDrawer
Draw GUI stuff
Get Height of Element
Place this script
in Editor folder
Custom Editor
Custom Inspector
1: pass class name
2: Extends with Editor
3: target contains under
inspection class data
4: here do draw stuff
5: utilities
If you want to study the
source code of this custom
inspector see this link
Custom Menus
Adding Menu Items
Context Menu Item
Very Useful for testing
purpose
Take Away
Property Drawers
-Serialized Class
-Fields
Custom Inspector (Editor)
Custom Editor Gizmos
Custom Windows
Scriptable Objects
Unity Seralization
May 5 2016Presented by Ahmed
Part-2
Gizmos
DescriptionGizmos are used to give visual debugging or setup aid in
scene view.
Use OnDrawGizmos or OnDrawGizmosSelected in your class to
draw them.
First one get called in every frame second get called only
when object is selected to whom this script is attached.
GizmosThese function are very easy to use just called them in OnGizmosDraw:)
Custom Window
Custom Window
Extends with EditorWindow
Scriptable Objects
Scriptable ObjectsScriptableobject is a class that allows you to store large
quantities of shared data independent from script instance.
they don’t need to be attached to game objects.
Read Only at run-time
Use case:Reduce memory usage by avoiding copies of values
Define pluggable data sets.
How to Create themExtends from ScriptableObject
method to create ScriptableObject
These methods are
self-explanatory
Method to load existing ScriptableObject
Serialization in unity
Serialization in unity [behind the scene]{content of this section is taken from blog post written by
unity Dev who wrote unity serialization system}
Serialization of “things” is at very core of Unity.Many of
unity's features build on top of serialization system.
The serialization is written in C++.
Continued...
Continued...Storing Data (Inspector Window)
Inspector window doesn't talk to C# api for properties &
their values
It asks the object to serialize itself and then displays
serialized data.
Continued...Prefabs
Internally, prefab is serialized data stream of game
object(s) & components
A prefab instance is a list of modifications that should be
made on the serialized data for this instance.
The concept of prefab only exist in editor, instantiated
gameobjects have no idea they were prefabs in editor.
Continued...Instantiation
When you call Instantiate() on a prefab or on existing
gameobject
Object get serialized, new object created & and deserialize
the data on new object
if object contains reference to external objects reference
is kept as is, if it has reference to its children than
reference is patched to new copy
Continued...Save/Load [Scene]
Unity saves it scenes as yaml file, you can check that by
opening scene with text editor, but you have to set unity
to “force text serialization”
Loading of scenes & assets uses serialization system
Last few words on serialization{don’t confuse this serialization with some
3rd party library}
How many
allocations are made
when deserializing a
monobehaviour that
uses this script.
No support
for null for
custom class
No support
for
polymorphism
Correct answer is 729 with 7 level depth
limit
When to write custom EditorWhen we learn something
new we tend to overuse
It.
Don't hesitate just write
Custom editor with
Experience you get
“Right Use”
Right Use
overuse
under-use