I’m having a spot of bother with EditorGUILayout. If I create my own inspector it doesn’t format as nicely as the built in inspectors, and the labels get cut off on if the label is long.
Rigidbody is built-in and LootableObject is custom.
My long labels are cut off - take “Animate When Looting” for example, yet in the built-in inspector “Collision Detection” is not.
I’ve been spelunking into the Editor docs, and not yet found joy. How to I “unfix” the label length? I’ve tried a separate “EditorGUILayout.PrefixLabel” and it behaves the same.
The other piece of behavior that I’m finding “different” is how the Custom Inspector recalculates it’s layout when the inspector window is adjusted:
The built-in one breaks between the label and the value, but the custom one keeps the label attached to the value, and it’s the value that’s recalculated…
[edit]
The code involved is:
// LootableBaseInspector.cs
// Allows clean and easy editing of lootable items
// Place in the Editor folder and forget
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(LootableBase))]
public class LootableBaseInspector : Editor {
protected LootableBase thisTarget;
public override void OnInspectorGUI() {
thisTarget = (LootableBase)target;
thisTarget.isLootable = EditorGUILayout.Toggle("Is Lootable", thisTarget.isLootable);
thisTarget.animateWhenLooting = EditorGUILayout.Toggle("Animate When Looting", thisTarget.animateWhenLooting);
if (thisTarget.animateWhenLooting)
thisTarget.thisAnimation = EditorGUILayout.ObjectField("Animation", thisTarget.thisAnimation, typeof (Animation)) as Animation;
thisTarget.destroyWhenEmpty = EditorGUILayout.Toggle("Destroy When Empty", thisTarget.destroyWhenEmpty);
if (thisTarget.destroyWhenEmpty){
thisTarget.delayBeforeDestroying = EditorGUILayout.FloatField("Delay Before Destroying",thisTarget.delayBeforeDestroying);
thisTarget.fadeBeforeDestroying = EditorGUILayout.Toggle("Fade Before Destroying",thisTarget.fadeBeforeDestroying);
thisTarget.fadeDuration = EditorGUILayout.FloatField("Fade Duration",thisTarget.fadeDuration);
}
if (GUI.changed)
EditorUtility.SetDirty(target);
}
}
// ©2011 Adam Buckner (aka: Little Angel) and theantranch.com (mailto: adam@theantranch.com)
// Not for reuse or resale without permission.