Object field in the scene view - Custom Editor Script
Hello there!
I would like to create an object field in the scene view to ease the work for our designers. The purpose is to connect road network nodes. An inspiration is the mod "traffic manager" from the game Cities Skylines, where small circles are shown on the screen and the user can click and drag and connect two nodes with each-other in this manner.
I have tried this so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PathNode))]
public class PathNodeEditor : Editor
{
public Object obj;
private void OnSceneGUI()
{
PathNode myPathNode = (PathNode)target;
Vector3 position = myPathNode.transform.position;
EditorGUILayout.BeginHorizontal();
obj = EditorGUILayout.ObjectField(obj, typeof(Object), true);
EditorGUILayout.EndHorizontal();
}
}
But so far nothing comes up in the sceneview. The rest I can fix on my own, must of it is already done. The connections can be made in the inspector, but I lack the option to have it easily accessed in the sceneview.
Thanks in beforehand!
public Object obj;
private void OnSceneGUI()
{
PathNode myPathNode = (PathNode)target;
Vector3 position = myPathNode.transform.position;
EditorGUILayout.BeginHorizontal();
obj = EditorGUILayout.ObjectField(obj, typeof(Object), true);
EditorGUILayout.EndHorizontal();
}
Your answer
Follow this Question
Related Questions
Set content of ObjectField from Editor Script 0 Answers
Can't update ObjectField after object is selected 1 Answer
Trying to add EditorGUILabels and am getting a couple errors. 0 Answers
EditorGUILayout.EnumPopup shows always the same selected option but works as programmed 1 Answer
Webview in custom Unity Editor Window? 0 Answers