/// <summary> /// Draws a serialized property, saving any recorded changes /// </summary> /// <param name="property"></param> public static bool DrawSerializedProperty(SerializedProperty property, SerializedObject serializedObject) { EditorGUI.BeginChangeCheck(); // Arrays if (property.isArray && property.propertyType != SerializedPropertyType.String) { StratusReorderableList.List(property); } else { EditorGUILayout.PropertyField(property, true); } // If property was changed, save if (EditorGUI.EndChangeCheck()) { // Record change Undo.RecordObject(property.objectReferenceValue, property.name); serializedObject.ApplyModifiedProperties(); return(true); } return(false); }
/// <summary> /// Adds all SerializedProperties to be inspected /// </summary> internal void ScanProperties() { // Reset the number of drawn properties this.drawnProperties = 0; // For every type, starting from the most derived up to the base, get its serialized properties Type currentType = this.target.GetType(); Type previousType = null; while (currentType != this.baseType && currentType != null) { // Serialized Properties StratusSerializedPropertyModel.Query query = new StratusSerializedPropertyModel.Query(serializedObject, currentType); foreach (StratusSerializedPropertyModel propertyModel in query.models) { if (propertyModel == null) { Debug.LogError($"A property was found to not be serialized properly while inspecting {this.target.name}. Did you forget a [Serializable] attribute on a class definition?"); continue; } //Debug.Log($"Drawer for serialized property: {propertyModel.displayName} with type {propertyModel.type}"); switch (propertyModel.type) { case StratusSerializedPropertyModel.SerializationType.Unity: { SerializedProperty serializedProperty = propertyModel.unitySerialized; this.propertyMap.Add(serializedProperty.name, serializedProperty); //Debug.Log($"Added property {serializedProperty.name}"); this.unitySerializedPropertyModels.Add(serializedProperty, propertyModel); // Record the attributes for this property Attribute[] attributes = propertyModel.attributes; this.propertyAttributes.Add(serializedProperty, attributes); this.propertyAttributesMap.AddUnique(serializedProperty, new Dictionary <Type, Attribute>()); foreach (Attribute attr in attributes) { this.propertyAttributesMap[serializedProperty].AddUnique(attr.GetType(), attr); } this.OnPropertyAttributesAdded(serializedProperty); // Check whether this property is an array if (serializedProperty.isArray && serializedProperty.propertyType != SerializedPropertyType.String) { this.reorderableLists.Add(propertyModel, StratusReorderableList.List(serializedProperty)); //this.AddReorderableList(serializedProperty); } } break; case StratusSerializedPropertyModel.SerializationType.Custom: { this.customSerializedPropertyModels.Add(propertyModel.customSerialized, propertyModel); if (propertyModel.customSerialized.isList) { this.reorderableLists.Add(propertyModel, StratusReorderableList.PolymorphicList(propertyModel.customSerialized)); } } break; } } this.propertiesByType.Add(currentType, query.models); this.unityPropertiesByType.Add(currentType, query.unitySerialized); this.propertyGroups.Add(new Tuple <Type, StratusSerializedPropertyModel[]>(currentType, query.models)); //// Add all the properties for this type into the property map by type //if (!currentType.IsGenericType) //{ // this.propertiesByType.Add(currentType, query.models); // this.unityPropertiesByType.Add(currentType, query.unitySerialized); // this.propertyGroups.Add(new Tuple<Type, StratusSerializedPropertyModel[]>(currentType, query.models)); //} //else //{ // if (!previousType.IsGenericType) // { // SerializedProperty[] joinedUnityProperties = this.unityPropertiesByType[previousType].Concat(query.unitySerialized); // this.unityPropertiesByType[previousType] = joinedUnityProperties; // // Combined // StratusSerializedPropertyModel[] joinedProperties = this.propertiesByType[previousType].Concat(query.models); // this.propertiesByType[previousType] = joinedProperties; // // Concat property groups // this.propertyGroups.RemoveLast(); // this.propertyGroups.Add(new Tuple<Type, StratusSerializedPropertyModel[]>(previousType, joinedProperties)); // } //} // Move on to the parent type (if any) previousType = currentType; currentType = currentType.BaseType; } this.propertyGroups.Reverse(); }