I want to be able to visualize where my ‘ResourceAreas’ are whilst in edit mode so i tried to create a tool to display them in the scene view. Here is the code for the editor:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(ResourceAreas))]
public class ResourceAreasEditor : Editor
{
void OnSceneGUI()
{
ResourceAreas resourceAreas = (ResourceAreas)target;
foreach (ResourceArea area in resourceAreas.resourceAreas)
{
Handles.color = Color.red;
Handles.DrawWireDisc(area.center, new Vector3(0,1,0), area.radius);
EditorGUI.BeginChangeCheck();
Vector3 newCenter = Handles.PositionHandle(area.center, Quaternion.identity);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(resourceAreas, "Move Resource Area Center");
area.center = newCenter;
EditorUtility.SetDirty(resourceAreas);
}
}
}
}
However upon selecting my ResourceAreas scriptable object no discs appear in the scene view. This is the code for the scriptable object and what one looks like in inspector:
using UnityEngine;
[System.Serializable]
public class ResourceArea
{
public string resourceName;
public Vector3 center; // Center point in terrain space
public float radius; // Radius of the resource area
public int resourceCount;
}
[CreateAssetMenu(fileName = "ResourceAreas", menuName = "ScriptableObjects/ResourceAreas", order = 1)]
public class ResourceAreas : ScriptableObject
{
public ResourceArea[] resourceAreas;
}