1

I'm trying to customize Array object in Custom Inspector looks like below image.

enter image description here

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 ();
    }
}
3
  • How is this related to unity? Commented Oct 13, 2015 at 23:51
  • @YacoubMassad He means Unity3D. Fixed tag. Commented Oct 13, 2015 at 23:59
  • oops, my bad. it's about Unity3D. Commented Oct 14, 2015 at 0:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.