Forum

HomeHomeLithicLithicGame DiscussionGame DiscussionEditor script - Greenlight GamesEditor script - Greenlight Games
Previous
 
Next
New Post
03/10/2014 15:59
 

Greenlight asked beki about editor scripts on twitter, heres a (real quick) guide, we write in C# by the way, not too sure on the exact syntax for java:

The script attached to the object is "CombineMesh.cs", it handles mesh optimisation of the tree's mesh - what it does isn't really important for an editor script example, the only thing to know is it's called "CombineMesh.cs".

You then need a script within a folder called "Editor", it doesn't have to be in the Unity folder, our editor scripts are in Assets/Data/Sctips/Editor. It is only important that the script is in a folder called "Editor".

This is the full code of "TreeWindow.cs", the editor script that controls the CombineMesh.cs:

Make sure you are using UnityEditor;

[CustomEditor(typeof(CombineMesh))]
public class TreeWindow : Editor

Replace CombineMesh with whatever your script is called,

Use public override void OnInspectorGUI() to call the script each time the editor GUI updates (every CPU cycle near enough)

the GUI button script is a Boolean itself, so use the button to either reveal other buttons, helpboxes or set bools.

if (GUILayout.Button("Name Of Button")) - this will create a button in the GUI and also return true when its pressed.

That's about it really, you can get pretty complex with editor scripts, hiding and revealing options or panels, it depends on what you need.

One thing to note is that you need to use DrawDefaultInspector(); somewhere if you still want to see the public variables on the script exposed in the editor, having an editor script that over rides OnInspectorGUI() by default will hide all variables and only show what you explicitly tell it to show.

Hope that gets you started, the Unity API covers it pretty well. Any further questions ask away and I'll try to get to them.

 
Previous
 
Next
HomeHomeLithicLithicGame DiscussionGame DiscussionEditor script - Greenlight GamesEditor script - Greenlight Games


To post in the Forum, Please either register an account or login using the buttons below

Register Login