Extending unity3D Editor

40
Extending unity3d Editor Develop Tools that fasten game development Seminar Frag Games

Transcript of Extending unity3D Editor

Page 1: Extending unity3D  Editor

Extending unity3d Editor

Develop Tools that fasten game development

Seminar

Frag Games

Page 2: Extending unity3D  Editor

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.

Page 3: Extending unity3D  Editor

Custom Editor

IMGUI Basics

Property Drawers

Custom Editor

Custom Windows

Gizmos

Scriptable Objects

Unity Seralization

April 25 2016Presented by Ahmed

Roadmap

Page 4: Extending unity3D  Editor

This Seminar is divided in two parts

Part-oneIMGUI Basics

Property Drawers

Custom Editor

Part-TwoCustom Windows

Scriptable Objects

Unity Serialization

Gizmos

Page 5: Extending unity3D  Editor

immediate mode GUI (imgui)

Page 6: Extending unity3D  Editor

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

Page 7: Extending unity3D  Editor

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

Page 8: Extending unity3D  Editor

Basic ComponentsLable

Button

Toggle

FloatField | IntField

Vect3Field

TextField

ColorField

BeginScrollView

BeginHorizontal

example

Page 9: Extending unity3D  Editor

How Unity Scripts are Build

Phase 1

Phase 2

Phase 3

Phase 4

Assets folder has same

physical path.

Page 10: Extending unity3D  Editor

Property Drawers

Page 11: Extending unity3D  Editor

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

Page 12: Extending unity3D  Editor

Custom property Drawersfor serialized classes

For Fields as Attributes

Page 13: Extending unity3D  Editor

Property Drawer for serialized class

Page 14: Extending unity3D  Editor

Code SnapShotPlace this script

in Editor folder

Page 15: Extending unity3D  Editor

Property Drawer Of Field

Page 16: Extending unity3D  Editor

Code SnapShotInherits with

PropertyAttribute

Inherits propertyDrawer

Draw GUI stuff

Get Height of Element

Place this script

in Editor folder

Page 17: Extending unity3D  Editor

Custom Editor

Page 18: Extending unity3D  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

Page 19: Extending unity3D  Editor

Custom Menus

Page 20: Extending unity3D  Editor

Adding Menu Items

Page 21: Extending unity3D  Editor

Context Menu Item

Very Useful for testing

purpose

Page 22: Extending unity3D  Editor

Take Away

Property Drawers

-Serialized Class

-Fields

Custom Inspector (Editor)

Page 23: Extending unity3D  Editor

Custom Editor Gizmos

Custom Windows

Scriptable Objects

Unity Seralization

May 5 2016Presented by Ahmed

Part-2

Page 24: Extending unity3D  Editor

Gizmos

Page 25: Extending unity3D  Editor

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.

Page 26: Extending unity3D  Editor

GizmosThese function are very easy to use just called them in OnGizmosDraw:)

Page 27: Extending unity3D  Editor

Custom Window

Page 28: Extending unity3D  Editor

Custom Window

Extends with EditorWindow

Page 29: Extending unity3D  Editor

Scriptable Objects

Page 30: Extending unity3D  Editor

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.

Page 31: Extending unity3D  Editor

How to Create themExtends from ScriptableObject

method to create ScriptableObject

These methods are

self-explanatory

Method to load existing ScriptableObject

Page 32: Extending unity3D  Editor

Serialization in unity

Page 33: Extending unity3D  Editor

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

Page 34: Extending unity3D  Editor

Continued...

Page 35: Extending unity3D  Editor

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.

Page 36: Extending unity3D  Editor

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.

Page 37: Extending unity3D  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

Page 38: Extending unity3D  Editor

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

Page 39: Extending unity3D  Editor

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

Page 40: Extending unity3D  Editor

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