Quantcast
Channel: Answers for "Unity Editor Inspector creating gameObjects in world"
Viewing all articles
Browse latest Browse all 4

Answer by C.Malcolm

$
0
0
I actually wrote an Editor script which allows the user to drag and drop a prefab into a selector, then input its position, give it a name and place it. Here is the code for that: using UnityEngine; using System.Collections; using UnityEditor; public class CustomWindow : EditorWindow { GameObject obj = null; Vector3 vec3 = new Vector3(0,0,0); string objname = ""; GameObject tempobj = null; [MenuItem ("Window/My Custom Window")] static void ShowWindow () { EditorWindow.GetWindow(typeof(CustomWindow)); } void OnInspectorUpdate () { Repaint (); } void OnGUI() { obj = EditorGUILayout.ObjectField("Select game object to place",obj, typeof(GameObject), true) as GameObject; vec3 = EditorGUILayout.Vector3Field("placement position:", vec3); objname = EditorGUILayout.TextField("Name for new object: ", objname); if (obj && objname != "") { if (GUILayout.Button( "Add to scene")) { tempobj = (GameObject)Instantiate(obj, vec3, Quaternion.identity); tempobj.name = objname; } } else { EditorGUILayout.LabelField ( "You must select an object and give it a name first"); } } } That's a good place to get started, then I suggest reading our 'Extending the Editor' docs page: http://docs.unity3d.com/Documentation/Components/ExtendingTheEditor.html You should be able to add some code that then places the rest of the objects in the order you choose within the OnGUI() function. I hope this answers your question somewhat!

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>