private static void DisplayArrayKeyPropertyDropdown(Rect rect, string propertyPath, SerializedProperty column, Object referenceObject) { HashSet <string> propertyPaths = new HashSet <string>(); var iterator = new ScriptableObjectPropertyIterator(referenceObject, propertyPath); if (!iterator.IsValid()) { Debug.LogError($"The current reference object {referenceObject} does not contain an array of this type with values in it. Try another reference object."); return; } foreach (SerializedProperty property in iterator) { if (!IsValidPropertyKeyType(property.propertyType)) { continue; } propertyPaths.Add(property.propertyPath.Substring(propertyPath.Length + 1)); // + 1 to skip the '.' } PropertyDropdown dropdown = new PropertyDropdown(new AdvancedDropdownState(), s => { column.FindPropertyRelative("ArrayPropertyKey").stringValue = s; column.serializedObject.ApplyModifiedProperties(); }, propertyPaths, null); dropdown.Show(rect); }
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); }
private static void DisplayArrayDrawingPropertyDropdown(Rect rect, string propertyPath, SerializedProperty column, Object referenceObject, HashSet <string> typeStrings) { HashSet <string> propertyPaths = new HashSet <string>(); Dictionary <string, SerializedPropertyType> typeLookup = new Dictionary <string, SerializedPropertyType>(); var iterator = new ScriptableObjectPropertyIterator(referenceObject, propertyPath); if (!iterator.IsValid()) { Debug.LogError($"The current reference object {referenceObject} does not contain an array of this type with values in it. Try another reference object."); return; } foreach (SerializedProperty property in iterator) { if (property.propertyType == SerializedPropertyType.Generic) { continue; } if (!typeStrings?.Contains(property.type) ?? false) { continue; } string localPath = property.propertyPath.Substring(propertyPath.Length + 1); propertyPaths.Add(localPath); // + 1 to skip the '.' typeLookup.Add(localPath, property.propertyType); } PropertyDropdown dropdown = new PropertyDropdown(new AdvancedDropdownState(), s => { column.FindPropertyRelative("ArrayPropertyPath").stringValue = s; column.FindPropertyRelative("ArrayPropertyType").intValue = (int)typeLookup[s]; column.serializedObject.ApplyModifiedProperties(); }, propertyPaths, null); dropdown.Show(rect); }
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(); } }