Example #1
0
            static private float CalculateHeight(UnityEditor.SerializedProperty property)
            {
                float height = UnityEditor.EditorGUIUtility.singleLineHeight;

                property = property.Copy();
                UnityEditor.SerializedProperty endProperty = property.GetEndProperty();

                bool bHasChildren = property.hasVisibleChildren;

                if (!bHasChildren)
                {
                    return(height);
                }

                height += 2;

                bool bEnterChildren = true;

                while (property.NextVisible(bEnterChildren) && !UnityEditor.SerializedProperty.EqualContents(property, endProperty))
                {
                    height        += UnityEditor.EditorGUI.GetPropertyHeight(property, true) + 2;
                    bEnterChildren = false;
                }

                return(height);
            }
        public static float GetPropertyHeight(UnityEditor.SerializedProperty property, bool includeChildren, GUIContent label)
        {
            var prop = property.Copy();

            if (EditorUtilities.GetPropertyChildCount(prop) == 1 && prop.NextVisible(true) == true)
            {
                prop.isExpanded = true;
                return(UnityEditor.EditorGUI.GetPropertyHeight(prop, label, includeChildren));
            }

            return(UnityEditor.EditorGUI.GetPropertyHeight(property, label, includeChildren));
        }
        public static int GetPropertyChildCount(UnityEditor.SerializedProperty property)
        {
            var prop  = property.Copy();
            var enter = true;
            var count = 0;

            while (prop.NextVisible(enter) == true)
            {
                ++count;
                enter = false;
            }

            return(count);
        }
Example #4
0
    public static void SetByteArrayProperty(UnityEditor.SerializedProperty property, byte[] byteArray)
    {
        if (!property.isArray)
        {
            return;
        }

        var iterator = property.Copy();

        iterator.arraySize = byteArray.Length;

        while (iterator.name != "data")
        {
            iterator.Next(true);
        }

        for (var i = 0; i < byteArray.Length; i++)
        {
            iterator.intValue = byteArray[i];
            iterator.Next(true);
        }
    }
Example #5
0
        public static bool SearchAndProcessWwiseTypes(UnityEditor.SerializedProperty property, UnityEditor.SerializedProperty endProperty = null)
        {
            var returnValue = false;

            if (property == null)
            {
                return(returnValue);
            }

            var recurse = false;

            if (property.isArray)
            {
                if (property.arraySize > 0)
                {
                    var copyProperty = property.Copy();
                    copyProperty.Next(false);
                    returnValue = SearchAndProcessWwiseTypes(property.GetArrayElementAtIndex(0), copyProperty);
                }
            }
            else if (property.propertyType == UnityEditor.SerializedPropertyType.Generic)
            {
                recurse = true;

                var wwiseObjectType = GetWwiseObjectType(property);
                if (wwiseObjectType != WwiseObjectType.None)
                {
                    // At this point, we know that the property's type's name is the same as one of our WwiseTypes.
                    var valueGuidProperty            = property.FindPropertyRelative("valueGuidInternal");
                    var wwiseObjectReferenceProperty = property.FindPropertyRelative("WwiseObjectReference");
                    if (valueGuidProperty != null && wwiseObjectReferenceProperty != null)
                    {
                        // At this point, we can be **pretty** sure that we are dealing with a WwiseType.
                        // The uncertainty lies with the fact that the property.type is the non-qualified name of the property's type.
                        recurse = false;

                        var idProperty = property.FindPropertyRelative("idInternal");
                        if (wwiseObjectType == WwiseObjectType.State || wwiseObjectType == WwiseObjectType.Switch)
                        {
                            var groupGuidProperty = property.FindPropertyRelative("groupGuidInternal");
                            if (groupGuidProperty != null)
                            {
                                var groupIdProperty = property.FindPropertyRelative("groupIdInternal");
                                returnValue = ProcessDoubleGuidType(wwiseObjectReferenceProperty, wwiseObjectType, valueGuidProperty, idProperty, groupGuidProperty, groupIdProperty);
                            }
                        }
                        else
                        {
                            returnValue = ProcessSingleGuidType(wwiseObjectReferenceProperty, wwiseObjectType, valueGuidProperty, idProperty);
                        }
                    }
                }
            }

            if (endProperty != null && UnityEditor.SerializedProperty.EqualContents(property, endProperty))
            {
                return(returnValue);
            }

            if (!property.Next(recurse))
            {
                return(returnValue);
            }

            // property is modified above, so this check needs to be performed again.
            if (endProperty != null && UnityEditor.SerializedProperty.EqualContents(property, endProperty))
            {
                return(returnValue);
            }

            return(SearchAndProcessWwiseTypes(property, endProperty) || returnValue);
        }