예제 #1
0
        void CreatePropertyDropdown()
        {
            if (referenceObject == null)
            {
                Debug.LogError("Reference Object is null. Lookup cannot be created");
                return;
            }

            HashSet <string> propertyPaths = new HashSet <string>();
            Dictionary <string, PropertyData> propertyLookup = new Dictionary <string, PropertyData>();
            var iterator      = new ScriptableObjectIterator(referenceObject);
            var configuration = (AssetListConfiguration)target;

            foreach (SerializedProperty prop in iterator)
            {
                if (prop.propertyType == SerializedPropertyType.Generic)
                {
                    if (prop.isArray)
                    {
                        propertyPaths.Add(prop.propertyPath);
                        propertyLookup.Add(prop.propertyPath, new PropertyData(configuration, prop));

                        if (!prop.NextVisible(false))
                        {
                            break;
                        }
                        iterator.PauseIteratorOnce = true;
                    }

                    //We can't display generic fields anyway.
                    continue;
                }

                propertyPaths.Add(prop.propertyPath);
                propertyLookup.Add(prop.propertyPath, new PropertyData(configuration, prop));
            }

            if (propertyDropdownState == null)
            {
                propertyDropdownState = new AdvancedDropdownState();
            }

            propertyDropdown = new PropertyDropdown(propertyDropdownState, propPath =>
            {
                SerializedProperty column = columns.GetArrayElementAtIndex(columns.arraySize++);
                column.FindPropertyRelative("PropertyPath").stringValue = propPath;
                column.FindPropertyRelative("Title").stringValue        = ObjectNames.NicifyVariableName(propPath);
                column.FindPropertyRelative("PropertyType").intValue    = (int)propertyLookup[propPath].Type;
                column.FindPropertyRelative("IsArray").boolValue        = propertyLookup[propPath].IsArray;
                serializedObject.ApplyModifiedProperties();
            }, propertyPaths, propertyLookup);
        }
예제 #2
0
        void CreateIconPropertyDropdown()
        {
            if (referenceObject == null)
            {
                Debug.LogError("Reference Object is null. Lookup cannot be created");
                return;
            }

            HashSet <string> iconPropertyPaths = new HashSet <string>();
            var iterator = new ScriptableObjectIterator(referenceObject);

            //Property paths that are also arrays
            HashSet <string> iconArrayPropertyPaths = new HashSet <string>();

            SerializedProperty skipUntil = null;

            foreach (SerializedProperty prop in iterator)
            {
                //Skip until the end of the array property
                if (skipUntil != null)
                {
                    if (!SerializedProperty.EqualContents(prop, skipUntil))
                    {
                        continue;
                    }
                    skipUntil = null;
                }

                if (prop.propertyType == SerializedPropertyType.Generic && prop.isArray)
                {
                    bool hasTextureProperty = false;
                    SerializedProperty temp = prop.Copy();
                    SerializedProperty end  = prop.GetEndProperty();
                    while (temp.NextVisible(true) && !SerializedProperty.EqualContents(temp, end))
                    {
                        if (temp.propertyType != SerializedPropertyType.ObjectReference)
                        {
                            continue;
                        }

                        if (!typeStrings.Contains(temp.type))
                        {
                            continue;
                        }

                        hasTextureProperty = true;
                        break;
                    }

                    if (hasTextureProperty)
                    {
                        //Add the array property to the list if there was a valid texture property inside it.
                        iconPropertyPaths.Add(prop.propertyPath);
                        iconArrayPropertyPaths.Add(prop.propertyPath);
                        //Define the next property as the destination to advance the for loop to.
                        skipUntil = end;
                    }
                }

                if (prop.propertyType != SerializedPropertyType.ObjectReference)
                {
                    continue;
                }

                if (typeStrings.Contains(prop.type))
                {
                    iconPropertyPaths.Add(prop.propertyPath);
                }
            }

            iconPropertyDropdown = null;

            switch (iconPropertyPaths.Count)
            {
            case 0:
                Debug.LogError("No appropriate property paths found.");
                return;

            case 1:
                Debug.Log("Only one appropriate property path found. It has been automatically assigned.");
                AssignPropPath(iconPropertyPaths.First());
                return;
            }

            if (iconPropertyDropdownState == null)
            {
                iconPropertyDropdownState = new AdvancedDropdownState();
            }

            iconPropertyDropdown = new PropertyDropdown(iconPropertyDropdownState, AssignPropPath, iconPropertyPaths, null);

            void AssignPropPath(string propPath)
            {
                iconPropertyPath.stringValue = propPath;
                if (iconArrayPropertyPaths.Contains(propPath))
                {
                    iconIsArray.boolValue = true;
                    iconArrayPropertyInformation.FindPropertyRelative("ArrayPropertyType").intValue = (int)SerializedPropertyType.ObjectReference;
                }

                serializedObject.ApplyModifiedProperties();
            }
        }