Sorry for the n00b question, but I just don’t know how to do it
How does one display an array in a custom editor window, not a custom inspector
Thanks, that’s all
public class MyClass : MonoBehaviour
{
// simply define the array as public
public int[ ] myTab;
// Or if u want the array to be private
[Serialized]
private int[ ] myTab;
}
attach this script on a Object and u’ll see the tab appear in the inspector.
it work with list too
Idk if I’ve just misunderstood, but I don’t want the array exposed in the editor of an object, I have my own custom editor window using the legacy GUI system, which is where I want it exposed
I’ve been trying multiple times to use EditorGUI.PropertyField with the includeChildren parameter but it always only displays “Element X”. I tried setting isExpanded to true in the SerializedProperty of the array entry but that didn’t help…
Any idea of what I could be missing ?
SerializedProperty prop = values.GetArrayElementAtIndex(index);
prop.isExpanded = true;
EditorGUILayout.PropertyField(prop, true);
if (EditorGUI.EndChangeCheck())
EditorUtility.SetDirty(target);
Are you sure your property has serializable children?
it’s a List of
[Serializable]
public class CameraShakePreset
{
[Serializable]
public struct Shake
{
public float Frequency;
public float Amplitude;
}
public Shake[ ] RotationalX;
public Shake[ ] RotationalY;
public Shake[ ] RotationalZ;
public float Duration = 0.5f;
}
It should be, right ?
Hmm, this works for me:
CameraShakeIsPresent.cs:
using System;
[Serializable]
public class CameraShakePreset
{
[Serializable]
public struct Shake
{
public float Frequency;
public float Amplitude;
}
public Shake[] RotationalX;
public Shake[] RotationalY;
public Shake[] RotationalZ;
public float Duration = 0.5f;
}
CameraShakeIsPresentList.cs:
using UnityEngine;
using System.Collections.Generic;
public class CameraShakePresentList : MonoBehaviour {
public List<CameraShakePreset> list = new List<CameraShakePreset>();
}
CameraShakeIsPresentListEditor.cs:
using UnityEditor;
[CustomEditor(typeof(CameraShakePresentList))]
public class CameraShakePresentListEditor : Editor
{
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("Custom editor:");
var serializedObject = new SerializedObject(target);
var property = serializedObject.FindProperty("list");
serializedObject.Update();
EditorGUILayout.PropertyField(property, true);
serializedObject.ApplyModifiedProperties();
}
}
I’m trying to display each element separately, not the whole list.
But I just understood the problem! Since I’m trying to display the list in a different manner but still want the rest of the inspector display as usual, I had hidden the list with [HideInInspector], used DrawDefaultInspector() to draw everything else and then do my custom display where entries would be displayed as usual with PropertyField. But it seems that since the list is hidden, all children are too. I’m not sure if it’s supposed to be that way… If I remove the HideInInspector, PropertyField works fine.
Shouldn’t PropertyField ignore the hidden status of the parent serialized property ?
I guess not! I’ve never tried it myself.
I’ve got a similar problem… I’d like to “take” a single item out of the array, present it in an ObjectField and insert that back into the serialized object… any ideas?
I’m not sure what you mean. Like this?
[Serializable]
public class MyClass {
public SomeType[] myArray;
}
...
var myArrayProperty = serializedObject.FindProperty("myArray");
var myElement = myArrayProperty.GetArrayElementAtIndex(42);
myElement.objectReferenceValue = EditorGUILayout.ObjectField(myElement.objectReferenceValue, typeof(SomeType), true);
yeah turns out exactly like that and i just had a brainFart
switched up the type on what’s line 7 of your code
Thanks fast and easy way
this thread should be named “for custom inspector” and not for editor window.
I literally stated in the OP that I wanted it for a custom editor window, NOT a custom inspector. So I have no idea why you’re claiming that. Especially since its such an old thread.
Sorry then i got confused by all the responses that use SerializedProperty, assumed the thread was about inspector. You dont have the serialized properties in editor window? Or i am missing something.
Yeah, I’m pretty sure you’re correct with that, so you’re right in saying these responses are for inspectors but it was never what i asked for
Yeah sry again, i solved same problem with just doing it with gui methods
Yeah it’s the same for a window and for an editor.