private static void ApplyValueStrong(IPropertyValueEntry <TDrawnType> entry, SerializedProperty unityProperty) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <TDrawnType> target = (EmittedScriptableObject <TDrawnType>)targetObjects[i]; entry.Values[i] = target.GetValue(); } entry.Values.ForceMarkDirty(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(GUIContent label) { var entry = this.ValueEntry; FieldInfo fieldInfo; SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo); if (unityProperty == null) { SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'."); return; } if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <T> ) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <T> target = (EmittedScriptableObject <T>)targetObjects[i]; target.SetValue(entry.Values[i]); } unityProperty.serializedObject.Update(); unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath); } EditorGUILayout.PropertyField(unityProperty, true); if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <T> ) { unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo(); var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <T> target = (EmittedScriptableObject <T>)targetObjects[i]; entry.Values[i] = target.GetValue(); } } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <TDrawnType> entry, GUIContent label) { if (SetFieldInfo == null) { SirenixEditorGUI.ErrorMessageBox("Could not find the internal Unity field 'PropertyDrawer.m_FieldInfo'; UnityPropertyDrawer alias '" + typeof(UnityPropertyDrawer <TDrawer, TDrawnType>).GetNiceName() + "' has been disabled."); return; } FieldInfo fieldInfo; SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo); if (unityProperty == null) { if (UnityVersion.IsVersionOrGreater(2017, 1)) { this.CallNextDrawer(entry, label); } else { SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'."); } return; } SetFieldInfo(ref this.drawer, fieldInfo); if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <TDrawnType> ) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <TDrawnType> target = (EmittedScriptableObject <TDrawnType>)targetObjects[i]; target.SetValue(entry.Values[i]); } unityProperty.serializedObject.Update(); } else if (unityProperty.serializedObject.targetObject is EmittedScriptableObject) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i]; target.SetWeakValue(entry.Values[i]); } unityProperty.serializedObject.Update(); unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath); } float height = this.drawer.GetPropertyHeight(unityProperty, label); Rect position = EditorGUILayout.GetControlRect(false, height); EditorGUI.BeginChangeCheck(); if (this.propertyHandler != null) { UnityPropertyHandlerUtility.PropertyHandlerOnGUI(this.propertyHandler, position, unityProperty, label, false); } else { this.drawer.OnGUI(position, unityProperty, label); } bool changed = EditorGUI.EndChangeCheck(); if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <TDrawnType> ) { if (unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo() || changed) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <TDrawnType> target = (EmittedScriptableObject <TDrawnType>)targetObjects[i]; entry.Values[i] = target.GetValue(); } entry.Values.ForceMarkDirty(); } } else if (unityProperty.serializedObject.targetObject is EmittedScriptableObject) { if (unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo() || changed) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i]; entry.Values[i] = (TDrawnType)target.GetWeakValue(); } entry.Values.ForceMarkDirty(); } } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(GUIContent label) { var entry = this.ValueEntry; if (SetFieldInfo == null) { SirenixEditorGUI.ErrorMessageBox("Could not find the internal Unity field 'PropertyDrawer.m_FieldInfo'; UnityPropertyDrawer alias '" + typeof(AbstractTypeUnityPropertyDrawer <TDrawer, TDrawnType, T>).GetNiceName() + "' has been disabled."); return; } FieldInfo fieldInfo; SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo); if (unityProperty == null) { SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'. Legacy Unity drawing compatibility is broken for this property; falling back to normal Odin drawing. Please report an issue on Odin's issue tracker with details."); this.CallNextDrawer(label); return; } SetFieldInfo(ref this.drawer, fieldInfo); if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <T> ) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <T> target = (EmittedScriptableObject <T>)targetObjects[i]; target.SetValue(entry.Values[i]); } unityProperty.serializedObject.Update(); } else if (unityProperty.serializedObject.targetObject is EmittedScriptableObject) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i]; target.SetWeakValue(entry.Values[i]); } unityProperty.serializedObject.Update(); unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath); } float height; if (this.propertyHandler != null) { height = UnityPropertyHandlerUtility.PropertyHandlerGetHeight(this.propertyHandler, unityProperty.Copy(), label, false); } else { height = this.drawer.GetPropertyHeight(unityProperty.Copy(), label); } Rect position = EditorGUILayout.GetControlRect(false, height); if (this.propertyHandler != null) { UnityPropertyHandlerUtility.PropertyHandlerOnGUI(this.propertyHandler, position, unityProperty, label, false); } else { this.drawer.OnGUI(position, unityProperty, label); } if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <T> ) { unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo(); var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject <T> target = (EmittedScriptableObject <T>)targetObjects[i]; entry.Values[i] = target.GetValue(); } } else if (unityProperty.serializedObject.targetObject is EmittedScriptableObject) { unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo(); var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i]; entry.Values[i] = (T)target.GetWeakValue(); } } }