Exemplo n.º 1
0
    public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
    {
        var labelSize = EditorGUIUtility.labelWidth;

        GUI.Label(area.CutRight(area.width - labelSize), label);
        ScriptableObjectField.Draw <UniqueAudioLoop>(area.CutLeft(labelSize), property, "Audio/Loops/" + property.serializedObject.targetObject.name + "AudioLoop");
    }
Exemplo n.º 2
0
    void OnEnable()
    {
        _author = Persistent <string> .At(AuthorPath);

        _urlField     = serializedObject.FindProperty("_url");
        _exportFields = serializedObject.FindProperty("_exportFields");
        _exportList   = new KReorderableList(serializedObject, _exportFields, "Configurations", IconCache.Get("gear").Texture);

        float lineHeight = EditorGUIUtility.singleLineHeight;
        float vSpacing   = EditorGUIUtility.standardVerticalSpacing;
        var   exporter   = target as JsonExporterData;

        _exportList.List.elementHeightCallback = ( int index ) =>
        {
            var element   = _exportFields.GetArrayElementAtIndex(index);
            var firstLine = lineHeight + vSpacing;
            var reference = element.FindPropertyRelative("_reference");
            if (!element.isExpanded)
            {
                return(firstLine);
            }
            if (reference.objectReferenceValue == null)
            {
                return(firstLine);
            }
            var data            = (JsonFieldDefinition)reference.objectReferenceValue;
            SerializedObject so = new SerializedObject(data);
            var p    = so.FindProperty("_definition");
            var edit = ExportFieldUtility.CalculateHeight(p, lineHeight);

            var inspect        = so.FindProperty("_inspect");
            var inspectionSize = 0f;

            if (!inspect.boolValue)
            {
                inspectionSize = lineHeight;
            }
            else
            {
                var minHeight     = lineHeight;
                var serialization = p.FindPropertyRelative("_serialization");
                var serType       = (EFieldSerializationType)serialization.enumValueIndex;
                if (serType == EFieldSerializationType.ToArray)
                {
                    minHeight = 3 * lineHeight;
                }
                var inspectedElement = so.FindProperty("_inspectedElement");
                var lines            = 1;

                try
                {
                    var oRef           = data.Definition.RootObject;
                    var type           = oRef.GetType();
                    var inspectionText = JsonFieldDefinitionEditor.GetInspectionText(data.Definition, type, oRef, serType, inspectedElement);
                    lines = inspectionText.Count((c) => c == '\n') + 1;
                }
                catch { }

                inspectionSize = Mathf.Max((lineHeight - 2.5f) * lines, minHeight);
            }

            return(firstLine + edit + inspectionSize);
        };

        _exportList.List.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            var firstLineRect = rect.RequestTop(lineHeight);
            var element       = _exportFields.GetArrayElementAtIndex(index);
            var selected      = element.FindPropertyRelative("_selected");
            var batchSize     = element.FindPropertyRelative("_batch");
            var reference     = element.FindPropertyRelative("_reference");

            var data = (JsonFieldDefinition)reference.objectReferenceValue;
            var w    = firstLineRect.width / 3;
            element.isExpanded = EditorGUI.Foldout(firstLineRect.RequestLeft(w).RequestRight(w - 12), element.isExpanded, data?.Definition?.FieldName ?? "*********", true);
            firstLineRect      = firstLineRect.CutLeft(w);

            selected.boolValue = EditorGUI.ToggleLeft(firstLineRect.RequestLeft(16), "", selected.boolValue);
            var r      = firstLineRect.CutLeft(16);
            var soRect = r;
            if (reference.objectReferenceValue is JsonFieldDefinition jsd && jsd.Definition.ShowBatchSize)
            {
                var batchRect = r.RequestLeft(60);
                soRect = soRect.CutLeft(62);
                EditorGUI.LabelField(batchRect, batchSize.intValue == 0 ? "(∞)batch" : "batch", K10GuiStyles.unitStyle);
                batchSize.intValue = Mathf.Max(EditorGUI.IntField(batchRect, batchSize.intValue), 0);
            }
            ScriptableObjectField.Draw <JsonFieldDefinition>(soRect, reference, "Assets/[_Configurations_]/ExportFields/");

            if (element.isExpanded && reference.objectReferenceValue != null)
            {
                SerializedObject so = new SerializedObject(data);
                var p    = so.FindProperty("_definition");
                var edit = ExportFieldUtility.CalculateHeight(p, lineHeight);
                rect = rect.CutTop(lineHeight + vSpacing);
                data.Definition.DrawElement(p, rect.RequestTop(edit), lineHeight, null);
                var inspectionRect       = rect.CutTop(edit);
                var inspectionTextRect   = inspectionRect.CutLeft(32);
                var inspectionFieldsRect = inspectionRect.RequestLeft(32);

                var inspect       = so.FindProperty("_inspect");
                var inspectChange = IconButton.Draw(inspectionFieldsRect.RequestTop(lineHeight), inspect.boolValue ? "spy" : "visibleOff");

                var inspectionText = "";

                if (inspect.boolValue && data.Definition != null)
                {
                    var count         = 0;
                    var serialization = p.FindPropertyRelative("_serialization");
                    var serType       = (EFieldSerializationType)serialization.enumValueIndex;

                    var oRef = data.Definition.RootObject;
                    if (serType == EFieldSerializationType.ToArray)
                    {
                        var enu = oRef as System.Collections.IEnumerable;
                        if (enu != null)
                        {
                            foreach (var o in enu)
                            {
                                count++;
                            }
                        }
                    }

                    var inspectedElement = so.FindProperty("_inspectedElement");
                    if (count > 0)
                    {
                        var fieldsModRect = inspectionFieldsRect.CutTop(lineHeight);
                        inspectedElement.intValue = EditorGUI.IntField(fieldsModRect.RequestTop(lineHeight), inspectedElement.intValue);
                        bool canGoUp = inspectedElement.intValue < (count - 1);

                        var btsRect = fieldsModRect.CutTop(lineHeight).RequestTop(lineHeight);
                        EditorGUI.BeginDisabledGroup(!canGoUp);
                        var up = IconButton.Draw(btsRect.VerticalSlice(1, 2), "upTriangle", '▲', "", Color.white);
                        EditorGUI.EndDisabledGroup();
                        bool canGoDown = inspectedElement.intValue > 0;
                        EditorGUI.BeginDisabledGroup(!canGoDown);
                        var down = IconButton.Draw(btsRect.VerticalSlice(0, 2), "downTriangle", '▼', "", Color.white);
                        EditorGUI.EndDisabledGroup();
                        if (up)
                        {
                            inspectedElement.intValue++;
                        }
                        if (down)
                        {
                            inspectedElement.intValue--;
                        }
                        inspectedElement.intValue = Mathf.Max(inspectedElement.intValue, 0);
                    }

                    var type = oRef.GetType();
                    inspectionText = JsonFieldDefinitionEditor.GetInspectionText(data.Definition, type, oRef, serType, inspectedElement);
                }

                if (inspectChange)
                {
                    inspect.boolValue = !inspect.boolValue;
                }

                EditorGUI.TextArea(inspectionTextRect, inspectionText);

                if (GUI.changed)
                {
                    so.ApplyModifiedProperties();
                }
            }
        };
    }
Exemplo n.º 3
0
    // Draw the property inside the given rect
    public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
    {
        var slh = EditorGUIUtility.singleLineHeight;
        var svs = EditorGUIUtility.standardVerticalSpacing;
        var lw  = EditorGUIUtility.labelWidth;

        var attrib = (InlinePropertiesAttribute)attribute;

        if (attrib.boxed)
        {
            GUI.Box(new Rect(0, area.y, Screen.width, area.height), "");
            area = area.VerticalShrink(6);
        }

        EditorGUI.BeginProperty(area, label, property);
        var type = GetFieldType();

        if (type == null || ignoreClassFullNames.Contains(type.FullName))
        {
            EditorGUI.PropertyField(area, property, label);
            EditorGUI.EndProperty();
            return;
        }

        ScriptableObject propertySO = null;

        if (!property.hasMultipleDifferentValues && property.serializedObject.targetObject != null && property.serializedObject.targetObject is ScriptableObject)
        {
            propertySO = (ScriptableObject)property.serializedObject.targetObject;
        }

        var propertyRect = Rect.zero;
        var guiContent   = new GUIContent(property.displayName);
        var foldoutRect  = new Rect(area.x, area.y, lw, slh);

        if (property.objectReferenceValue != null && AreAnySubPropertiesVisible(property))
        {
            var exp = property.isExpanded;
            property.isExpanded = EditorGUI.Foldout(foldoutRect, exp, guiContent, true);
            if (exp != property.isExpanded)
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }
        else
        {
            // So yeah having a foldout look like a label is a weird hack
            // but both code paths seem to need to be a foldout or
            // the object field control goes weird when the codepath changes.
            // I guess because foldout is an interactable control of its own and throws off the controlID?
            foldoutRect.x += 12;
            EditorGUI.Foldout(foldoutRect, property.isExpanded, guiContent, true, EditorStyles.label);
        }

        propertyRect = area.CutLeft(lw).RequestTop(slh);
        ScriptableObjectField.Draw(propertyRect, property, type);
        // property.objectReferenceValue = EditorGUI.ObjectField( propertyRect, GUIContent.none, property.objectReferenceValue, type, false );
        if (GUI.changed)
        {
            property.serializedObject.ApplyModifiedProperties();
        }

        var buttonRect = new Rect(area.x + area.width - buttonWidth, area.y, buttonWidth, slh);


        if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null)
        {
            var data = (ScriptableObject)property.objectReferenceValue;

            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;
                SerializedObject serializedObject = new SerializedObject(data);

                // Iterate over all the values and draw them
                SerializedProperty prop = serializedObject.GetIterator();
                float y = area.y + slh + svs;
                if (prop.NextVisible(true))
                {
                    do
                    {
                        // Don't bother drawing the class file
                        if (prop.name == SCRIPT_FIELD)
                        {
                            continue;
                        }
                        float height = EditorGUI.GetPropertyHeight(prop, new GUIContent(prop.displayName), prop.isExpanded);
                        EditorGUI.PropertyField(new Rect(area.x, y, area.width, height), prop, prop.isExpanded);
                        y += height + svs;
                    }while(prop.NextVisible(false));
                }
                if (GUI.changed)
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.indentLevel--;
            }
        }

        property.serializedObject.ApplyModifiedProperties();
        EditorGUI.EndProperty();
    }