Пример #1
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        //Display of this drawer (specially here: the height) is dependant of the modification type
        EventScript.E_ModificationType modifierType = (EventScript.E_ModificationType)property.FindPropertyRelative("modificationType").enumValueIndex;

        float totalHeight = 18f;

        switch (modifierType)
        {
        case EventScript.E_ModificationType.add:
        case EventScript.E_ModificationType.set:
            totalHeight = 18f;
            break;

        case EventScript.E_ModificationType.setRandInt:
        case EventScript.E_ModificationType.addRandInt:
        case EventScript.E_ModificationType.addRandom:
        case EventScript.E_ModificationType.setRandom:
            totalHeight = 36;
            break;

//            case EventScript.E_ModifierType._event:
//                totalHeight = EditorGUI.GetPropertyHeight(property.FindPropertyRelative("_event"), label, true) + 18f;
//                break;
        default:
            totalHeight = 18f;
            break;
        }

        return(totalHeight);
    }
Пример #2
0
    // Draw the property inside the given rect
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //don't alter
        EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        float x  = position.x;
        float y  = position.y;
        float w  = position.width;
        float h  = 16f;
        float w2 = w / 2f;
        float w3 = w / 3f;

        //Display of this drawer is dependant of the modification type
        EventScript.E_ModificationType modifierType = (EventScript.E_ModificationType)property.FindPropertyRelative("modificationType").enumValueIndex;

        // Calculate rects
        var modTypeRectw1 = new Rect(x, y, w, h);
        var modTypeRectw2 = new Rect(x, y, w2, h);
        var modTypeRectw3 = new Rect(x, y, w3, h);

        var modRectw3 = new Rect(x + w3, y, w3, h);
        var modRectw2 = new Rect(x + w2, y, w2, h);

        var valRect    = new Rect(x + 2 * w3, y, w3, h);
        var valMinRect = new Rect(x, y + +18f, w2, h);
        var valMaxRect = new Rect(x + w2, y + +18f, w2, h);

        var eventR = new Rect(0f, y + 18f, position.width + x, h + 50f);

        // Draw fields - passs GUIContent.none to each so they are drawn without labels
        switch (modifierType)
        {
        case EventScript.E_ModificationType.add:
            EditorGUI.PropertyField(modTypeRectw3, property.FindPropertyRelative("modificationType"), GUIContent.none);
            EditorGUI.PropertyField(modRectw3, property.FindPropertyRelative("modifier"), GUIContent.none);
            EditorGUI.PropertyField(valRect, property.FindPropertyRelative("valueAdd"), GUIContent.none);
            break;

        case EventScript.E_ModificationType.set:
            EditorGUI.PropertyField(modTypeRectw3, property.FindPropertyRelative("modificationType"), GUIContent.none);
            EditorGUI.PropertyField(modRectw3, property.FindPropertyRelative("modifier"), GUIContent.none);
            EditorGUI.PropertyField(valRect, property.FindPropertyRelative("valueSet"), GUIContent.none);
            break;

        case EventScript.E_ModificationType.addRandInt:
        case EventScript.E_ModificationType.addRandom:
            EditorGUI.PropertyField(modTypeRectw2, property.FindPropertyRelative("modificationType"), GUIContent.none);
            EditorGUI.PropertyField(modRectw2, property.FindPropertyRelative("modifier"), GUIContent.none);
            EditorGUI.PropertyField(valMinRect, property.FindPropertyRelative("rndRangeAdd").FindPropertyRelative("min"), GUIContent.none);
            EditorGUI.PropertyField(valMaxRect, property.FindPropertyRelative("rndRangeAdd").FindPropertyRelative("max"), GUIContent.none);
            break;

        case EventScript.E_ModificationType.setRandInt:
        case EventScript.E_ModificationType.setRandom:
            EditorGUI.PropertyField(modTypeRectw2, property.FindPropertyRelative("modificationType"), GUIContent.none);
            EditorGUI.PropertyField(modRectw2, property.FindPropertyRelative("modifier"), GUIContent.none);
            EditorGUI.PropertyField(valMinRect, property.FindPropertyRelative("rndRangeSet").FindPropertyRelative("min"), GUIContent.none);
            EditorGUI.PropertyField(valMaxRect, property.FindPropertyRelative("rndRangeSet").FindPropertyRelative("max"), GUIContent.none);
            break;

        //            case EventScript.E_ModifierType._event:
        //               EditorGUI.PropertyField(modTypeRectw1, property.FindPropertyRelative("modifierType"), GUIContent.none);
        //                EditorGUI.PropertyField(eventR, property.FindPropertyRelative("_event"), GUIContent.none);
        //                break;
        default:
            //should not be possible...
            break;
        }



        //don't alter
        EditorGUI.indentLevel = indent;
        EditorGUI.EndProperty();
    }