Reputation: 60
I'm trying to customize Array object in Custom Inspector looks like below image.
and I can't find how to do this. :-(
Can you tell me how to do it? any link or answer will very helpful.
Below Code is what I'm working so far.
myClass.cs
using UnityEngine;
using System.Collections;
public class myClass : MonoBehaviour {
public string[] myArray = new string[0];
void Update () {
// do something
}
}
myClassEditor.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(myClass))]
[CanEditMultipleObjects]
public class myClassEditor : Editor {
SerializedObject serializedObj;
myClass myClassScript;
SerializedProperty myArray;
void OnEnable() {
serializedObj = new SerializedObject (target);
myClassScript = (myClass)target;
myArray = serializedObject.FindProperty ("myArray");
}
public override void OnInspectorGUI() {
serializedObj.Update ();
EditorGUILayout.HelpBox ("Default Inspector", MessageType.None);
DrawDefaultInspector();
EditorGUILayout.HelpBox ("Custom Inspector", MessageType.None);
EditorGUILayout.PropertyField(myArray, new GUIContent("My Custom Array"), true);
serializedObj.ApplyModifiedProperties ();
}
}
Upvotes: 1
Views: 5709
Reputation: 1268
If you just want to change the font you can look into setting GUI.Skin to a custom GUISkin
If you actually want to change the text it will be much more involved. You would have to loop through all the values of the array and add a label and value field manually for each one so you have full control. This means you would have to program your own controls for managing the array such as adding or removing an entry. You will also have to manage serializing the data since the propertyfield handles a lot of that for you. You will want to look into SetDirty as well so the editor knows when something has been changed and needs to be saved.
The second option is very involved but it gives you precise control over what it will look like. You could even add things like arrow buttons to move array elements up and down within the array.
Upvotes: 1