C# EditorGUILayout.ObjectField selection referencing its own object variables

I don’t know if I’m describing what I want correctly in the title, but let me give a simple example of what I would like to happen.

I have a structure like this in the Inspector:

→ List (custom class)
—>Operation (contains MonoScript variable and an OperationScript variable)

1.) The Operations list contains individual Operation objects.
2.) Operation objects are setup to accept any MonoScript item in the editor, because I can’t figure out how to make it only allow script derived from the Operation class (which would make this so much easier.)

I can extend the list, add Operation items and select a MonoScript for the Operation.

I want to take that MonoScript that I select, determine the class (GetClass?, I presume) and assign that class to a variable in the same Operation the editor has generated that will handle executing code in-game that’s specific to that MonoScript. For example: I select my ChangeTransform script and after selecting it, a ChangeTransform object is instantiated and assigned to the OperationScript variable in that same Operation object.

If there’s an easier way to do this, I would love to know! Thanks!

Ouch. A case of RTFM on my part. You can use “target” anywhere in the Editor derived class to get the object you’re inspecting.

I’m still having issues getting the CustomEditor to actually work. I have a custom class (not inheriting from anything) called EDExtraParams. It’s got a string in it and that’s it.

using UnityEngine;
using System.Collections;

[System.Serializable]
public class EDExtraParams
{
	public string testString= "";
}

I then use the following for the Inspector’s code:

using UnityEngine;
using UnityEditor;
using System;
using System.Collections;


[CustomEditor(typeof(EDExtraParams))]
class EDOperation2Editor : Editor
{
	public override void OnInspectorGUI()
	{
		EditorGUIUtility.LookLikeInspector();

		Color greenish = EditorGUILayout.ColorField(Color.green, new GUILayoutOption[0]);
	}
}

But nothing happens in the inspector. It’s still showing just the public properties of ExtraParams. Any advice on what I did wrong there?

Your script code looks fine to me. Is your custom editor script in a folder called Editor as it should be? Is your Inspector perhaps accidentally in Debug mode?

Rune

The Editor-derived script is in a folder named “Editor” in the root “Assets” folder of my project. I double-checked my Inspector settings and it appears to be set to “Normal”.

It works if EDExtraParams inherits MonoBehavior and drop it directly on an object, but when it’s a property of another custom class dropped on an object, then it doesn’t show up correctly.

Thanks for the help in troubleshooting this with me.

Edit: I believe what I may be looking for is a “PropertyDrawer” instead of what I have. It just took finding and using the proper terminology in Google. I’ll update if this works for me.

Edit2: “CustomPropertyDrawer” was exactly what I needed. It’s working like a champ now :slight_smile: Thanks to anyone who read through all my junk and I hope this helps clear up confusion for someone else as to how to achieve similar results.