I’ve made two scripts, a custom editor window and a script containing a reoderable list, but I can’t put the list in the editor. The problem comes from the fact that the list script inherits from Editor, but the window script inherits from EditorWindow. How would I combine these?
ReoderableList Script:
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
[CustomEditor(typeof(LevelData))]
public class LevelDataEditor : Editor {
private ReorderableList list;
private void OnEnable() {
list = new ReorderableList(serializedObject,
serializedObject.FindProperty("Waves"),
true, true, true, true);
list.drawElementCallback =
(Rect rect, int index, bool isActive, bool isFocused) => {
var element = list.serializedProperty.GetArrayElementAtIndex(index);
rect.y += 2;
EditorGUI.PropertyField(
new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("Type"), GUIContent.none);
EditorGUI.PropertyField(
new Rect(rect.x + 60, rect.y, rect.width - 60 - 30, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("Prefab"), GUIContent.none);
EditorGUI.PropertyField(
new Rect(rect.x + rect.width - 30, rect.y, 30, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("Count"), GUIContent.none);
};
list.drawHeaderCallback = (Rect rect) => {
EditorGUI.LabelField(rect, "Monster Waves");
list.onCanRemoveCallback = (ReorderableList l) => {
return l.count > 1;
};
list.onRemoveCallback = (ReorderableList l) => {
if (EditorUtility.DisplayDialog("Warning!",
"Are you sure you want to delete the wave?", "Yes", "No")) {
ReorderableList.defaultBehaviours.DoRemoveButton(l);
}
};
};
}
public override void OnInspectorGUI() {
serializedObject.Update();
list.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
EditorWindow Script:
using UnityEditor;
using UnityEngine;
using UnityEditorInternal;
public class PathCreator : EditorWindow
{
float ScaleX;
float ScaleY;
float OriginX;
float OriginY;
float smoothingScale = 1f;
bool boundFoldout;
bool active;
bool smoothing;
float spacing;
Object m_MainCamera;
Object subject;
private ReorderableList list;
//Location of the editor
[MenuItem("Window/Path Creator")]
public static void ShowWindow ()
{
GetWindow<PathCreator>("Path Creator");
}
void OnGUI ()
{
//Create ReoderableList
list = new ReorderableList(serializedObject, serializedObject.FindProperty("Waves"), true, true, true, true);
EditorGUI.indentLevel++;
GUILayout.Label("Custom Camera Path", EditorStyles.boldLabel);
//Active checkbox
active = EditorGUI.Toggle(new Rect(3, 20, position.width, 20), "Active", active);
//Check if active is true
if(active)
{
smoothing = EditorGUI.Toggle(new Rect(3, 40, position.width, 20), "Edge Smoothing", smoothing);
if (smoothing)
{
EditorGUI.indentLevel++;
//Create smoothing slider
smoothingScale = EditorGUI.Slider(new Rect(5, 70, 300, 20), "Smoothing", smoothingScale, 1, 100);
spacing = 80f;
EditorGUI.indentLevel--;
}
else
{
spacing = 45f;
}
//Space accordingly
EditorGUILayout.Space(spacing);
//Create an empty field for Main Camera and Subject
m_MainCamera = EditorGUILayout.ObjectField("Main Camera", m_MainCamera, typeof(Camera), true);
subject = EditorGUILayout.ObjectField("Subject", subject, typeof(GameObject), true);
//Create bounds foldout
boundFoldout = EditorGUILayout.Foldout(boundFoldout,"Bounds");
//Check if the bounds are folded
if (boundFoldout)
{
EditorGUI.indentLevel++;
ScaleX = EditorGUILayout.FloatField("Scale X", ScaleX);
ScaleY = EditorGUILayout.FloatField("Scale Y", ScaleY);
OriginX = EditorGUILayout.FloatField("Origin X", OriginX);
OriginY = EditorGUILayout.FloatField("Origin Y", OriginY);
EditorGUI.indentLevel--;
}
}
}
}
Thanks <3