- Home /
Question by
Vegedus · Jul 15, 2014 at 10:39 PM ·
inspectorcustom-inspectoreditorguilayoutcomparison
Custom Inspector: Iteration/property comparison always false
I'm making a custom inspector for the first time and, well, it doesn't work. For now I'm just trying to recreate the default inspector by iterating through all elements and showing them as fields. No fields ever show up, however. Neither of the two lines marked with //?? seems to be ever reached. If I uncomment the line right above, that has no if-sentence attached to it, all properties are shown, suggesting that something is up with the comparison. The script referred to only has a global float and int variable in them and no errors are thrown. What am I doing wrong?
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(StatsPlayer))]
public class StatsEditor : Editor
{
private StatsPlayer statsPlayer;
private SerializedObject serializedObject;
private SerializedProperty property;
public void OnEnable()
{
statsPlayer = (StatsPlayer)target;
serializedObject = new SerializedObject (statsPlayer);
property = serializedObject.GetIterator ();
}
public override void OnInspectorGUI ()
{
property.Reset();
property.Next (true);
do {
//EditorGUILayout.PropertyField(property);
if (property.type.Equals(typeof(float).ToString())) {
EditorGUILayout.PropertyField (property); //??
}
if (property.GetType () == typeof(int)) {
EditorGUILayout.IntField (property.name, property.intValue ); //??
}
} while (property.NextVisible(false));
}
}
Comment