- Home /
in editor object placement by script in editor
i would like to make a simple grid of cubes. i can simpely do this in runtime with a for loop but the point is that i want to do this in editor. i dont like to spend my time making grids by hand.
i have looked at the editor scripting api and have seen a basic tutoriol wich did not get me that far.
id like to have some tips on where to find a decent editor tutorial. or share some of your own experience.
i just need a bit help to get started.
Answer by Cherno · Mar 17, 2015 at 01:25 PM
Suppose you have a gameobject which has a script which generates your cubes with a function.
All you need now to do it in editing mode is to write a simple editor extension which adds a button to that script in the inspector that, upon clicking it, calls the function. Of course, you need to select the gameobject which has the generator script. The extension script itself (below) is not attached to any gameobject, you can just let it sit inside your asset folder with your other scripts.
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections;
[CustomEditor(typeof(YourCubeGeneratorScript))]
public class YourCubeGeneratorScriptExtension : Editor {
#if UNITY_EDITOR
override public void OnInspectorGUI () {
YourCubeGeneratorScript yourCubeGeneratorScript = (YourCubeGeneratorScript)target;
if(GUILayout.Button("Generator Cubes")) {
yourCubeGeneratorScript.GenerateCubes();
}
if (GUI.changed) {
EditorUtility.SetDirty(target);
}
DrawDefaultInspector();
}
#endif
}
thanks now i can make my own little tool set so my artists can build their levels faster.
Your answer
Follow this Question
Related Questions
how to stop reorderable list from passing Event value to the new element 1 Answer
Can't remove using Unity Editor, it is necessary for the development of the game. 0 Answers
[ExecuteInEditMode] OnEnable Running twice on Play? 1 Answer
How to show a custom UnityEvent in custom class to custom Editor 1 Answer
ReorderableList always show all element. How to hide some element ? 1 Answer