- Home /
Question by
Lukas_GMC · Oct 09, 2012 at 12:50 AM ·
editorinspectorcustomeditor
DrawDefaultInspector crash
I have multiple types of creatures the player can be and they all have different options that my game designer can tweak. I use DrawDefaultInspector to show these options but when changing to a different creature the editor crashes when it calls DrawDefaultInspector. This is a crucial piece of what were trying to do and I'd rather not hand code the entire gui for each creature. Thanks in advance.
Comment
Wrong. It's actually line 50. If anybody with any actual idea of whats going on please help.
Answer by Lukas_GMC · Oct 10, 2012 at 12:05 AM
[CustomEditor(typeof(PlayerController))]
public class PlayerEditor : Editor
{
string[] CHARACTER_TYPE = {"NULL", "Frog", "Snake", "Armadillo"};
public PlayerController m_player;
public int Type
{
get
{
for(int i = 0; i < CHARACTER_TYPE.Length; ++i)
if(CHARACTER_TYPE[i] == m_player.Type())
return i;
return 0;
}
set
{
if (value == Type || value <= 0)
return;
GameObject newPlayer = (GameObject)Instantiate(Resources.Load("Prefabs/" + CHARACTER_TYPE[value], typeof(GameObject)), m_player.transform.position, m_player.transform.rotation);
Debug.Log(newPlayer);
DestroyImmediate(m_player.gameObject);
m_player = newPlayer.GetComponent<PlayerController>();
Selection.activeGameObject = newPlayer;
newPlayer.name = "player";
}
}
virtual public void OnEnable()
{
m_player = (PlayerController)target;
}
public override void OnInspectorGUI()
{
DrawPlayerGUI();
}
public void DrawPlayerGUI()
{
Type = EditorGUILayout.Popup("Type", Type, CHARACTER_TYPE, GUILayout.ExpandWidth(true));
DrawDefaultInspector();
}
}