0
\$\begingroup\$

I basically made a lot of research and wasn´t able to find any solution.
So my problem: I´ve made some variables disappear/appear depending on an enum with a custom editor script. But if they appear they do not appear at the position where the normal editor variables would appear

override public void OnInspectorGUI()
{
    base.OnInspectorGUI();
    GunCard myScript = target as GunCard;

    EditorGUI.indentLevel++;

    switch (myScript.aimingControlType)
    {
        case AimingControlType.Manual:
            myScript.hasAimAssistance = EditorGUILayout.Toggle("Has aim assistance", myScript.hasAimAssistance);
            break;
        case AimingControlType.AutoTargeting:
            myScript.targetPreference = (TargetTypes)EditorGUILayout.EnumPopup("Target preference", myScript.targetPreference);
            myScript.requiresLineOfSight = EditorGUILayout.Toggle("Requires line of sight", myScript.requiresLineOfSight);
            myScript.requiresPossibleTargetOnScreen = EditorGUILayout.Toggle("requires possible target on screen", myScript.requiresPossibleTargetOnScreen);
            break;
    }
    EditorGUI.indentLevel--;
}

Here is where they appear: enter image description here

That are the raw variables in the scriptable object

[Header("Aiming Controls")]
public AimingControlType aimingControlType;

[HideInInspector] public bool hasAimAssistance;
[HideInInspector] public bool requiresLineOfSight;                //TODO: implement -> requires 180
[HideInInspector] public bool requiresPossibleTargetOnScreen;     //TODO: implement -> requires 180
[HideInInspector] public TargetTypes targetPreference;
[HideInInspector] public bool isAutoShootWhenAimOnTarget;

I know I´m basically adding new variables to the inspector in my editor Script but it would be really useful to order them. Is there a way to do that?

P.S sorry for the funny typo in the picture :)

\$\endgroup\$
1
  • \$\begingroup\$ I just found out that the best way to achieve that is to use Custom Property Drawers. \$\endgroup\$ Commented May 5, 2019 at 13:19

1 Answer 1

0
\$\begingroup\$

In your OnInspectorGUI override, you call the base first which draws the default Inspector for the scriptable object first and the custom drawer code is actually after that, so it renders afterward.

One thing you can do is calling the base at the bottom of your override, but it means you have to add a custom editor field for you AimingControlType enumeration.

The code would be something like this:

override public void OnInspectorGUI()
{
    GunCard myScript = target as GunCard;

    EditorGUI.indentLevel++;
    myScript.aimingControlType = (AimingControlType )EditorGUILayout.EnumPopup("Aiming Control Type", myScript.aimingControlType);
    switch (myScript.aimingControlType)
    {
        case AimingControlType.Manual:
            myScript.hasAimAssistance = EditorGUILayout.Toggle("Has aim assistance", myScript.hasAimAssistance);
            break;
        case AimingControlType.AutoTargeting:
            myScript.targetPreference = (TargetTypes)EditorGUILayout.EnumPopup("Target preference", myScript.targetPreference);
            myScript.requiresLineOfSight = EditorGUILayout.Toggle("Requires line of sight", myScript.requiresLineOfSight);
            myScript.requiresPossibleTargetOnScreen = EditorGUILayout.Toggle("requires possible target on screen", myScript.requiresPossibleTargetOnScreen);
            break;
    }
    EditorGUI.indentLevel--;
    base.OnInspectorGUI();
}

As well as this change in your scriptable class.

[HideInInspector]
public AimingControlType aimingControlType;

[HideInInspector] public bool hasAimAssistance;
[HideInInspector] public bool requiresLineOfSight;                //TODO: implement -> requires 180
[HideInInspector] public bool requiresPossibleTargetOnScreen;     //TODO: implement -> requires 180
[HideInInspector] public TargetTypes targetPreference;
[HideInInspector] public bool isAutoShootWhenAimOnTarget;
\$\endgroup\$
2
  • \$\begingroup\$ Okay, I´m sorry for the late answer, but I wasn´t at home for the last few days. Okay but that would mean that I just place the enum field down to the other fields. Am I right? So that means there is no real solution for that unless I use property drawers? \$\endgroup\$ Commented May 2, 2019 at 17:27
  • \$\begingroup\$ You can mark that enum as hideininspector and draw it with custom drawer. \$\endgroup\$
    – Emad
    Commented May 2, 2019 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .