- Home /
Question by
Seneral · Feb 07, 2015 at 09:01 PM ·
componenttypecustomeditortypecastingcustominspector
Custom Editors for any Component
Hey there! I'm searching for a way to create a custom Inspector for any Component; Basically I wish to add a Button under every Component without adressing it specifically in the CustomEditor Attribute:
[CustomEditor(typeof(Transform))]
rather than doing something like this:
[CustomEditor(typeof(Component))]
public class ObjectEditor : Editor
{}
I intent to use it for applying Component values at RT regardless of the type. My Custom Editor So far:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(Component))]
public class ObjectEditor : Editor {
public override void OnInspectorGUI ()
{
DrawDefaultInspector ();
if (GUILayout.Button ("Save"))
{
RTEdits.comps.Add ((Component)target);
Debug.Log ("Adding " + target.name + " to save list!");
}
}
}
Where the list "comps" will be iterated through on playmode change (exit) to apply every component marked as "save". Which currently does not work as the given type is not recognised in any Component even though they all inherit from Component. Just so you know, I did not make anything else wrong, changing it to for Example "transform" works fine.
Do you know anything to get this work?
Comment