We’re externalising all texts in our game, and want an easy and efficient way to set it all via the GUI. Basically when anyone creates a button, or label, or anything with text in, we want them to be able to put in the text ID of that component, “TEXT_ID_OK” for instance, and the text associated with that ID show up on it.
I’ve tried the below script in “ButtonEditor.cs” in the Assets/Editor, but it’s done nothing at all, same with a near identical “TextEditor.cs” file. The Inspector editor stays exactly the same with no change.
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
[CustomEditor(typeof(Button))]
public class ButtonEditor : Editor
{
public override void OnInspectorGUI()
{
Button button = (Button)target;
Text text = button.GetComponentsInChildren<Text>()[0];
text.text = GetTextFromId(EditorGUILayout.TextField("Button TextID", text.text));
DrawDefaultInspector();
}
}
Can anyone point out what I’m doing wrong? Can you not set custom editors for default components? Am I referencing the incorrect components? When I reference “CustomButton” (which does nothing but inherit from Button) instead of just “Button” it works as expected, but but nothing happens when just “Button” or “Text”.