void SetupList() { SerializedProperty poseListProperty = serializedObject.FindProperty("m_Poses"); if (poseListProperty != null) { mList = new ReorderableList(serializedObject, poseListProperty, true, true, true, true); mList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { SerializedProperty poseProperty = mList.serializedProperty.GetArrayElementAtIndex(index); rect.y += 1.5f; EditorGUI.PropertyField( new Rect(rect.x, rect.y, rect.width - 120, EditorGUIUtility.singleLineHeight), poseProperty, GUIContent.none); EditorGUI.BeginDisabledGroup(!poseProperty.objectReferenceValue); if (GUI.Button(new Rect(rect.x + rect.width - 115, rect.y, 55, EditorGUIUtility.singleLineHeight), "Save")) { if (EditorUtility.DisplayDialog("Overwrite Pose", "Overwrite '" + poseProperty.objectReferenceValue.name + "'?", "Apply", "Cancel")) { PoseUtils.SavePose(poseProperty.objectReferenceValue as Pose, (target as PoseManager).transform); mList.index = index; } } if (GUI.Button(new Rect(rect.x + rect.width - 55, rect.y, 55, EditorGUIUtility.singleLineHeight), "Load")) { PoseUtils.LoadPose(poseProperty.objectReferenceValue as Pose, (target as PoseManager).transform); mList.index = index; } EditorGUI.EndDisabledGroup(); }; mList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Poses"); }; mList.onSelectCallback = (ReorderableList list) => { }; } }
void CreateNewPose() { serializedObject.Update(); Pose newPose = ScriptableObjectUtility.CreateAssetWithSavePanel <Pose>(); mList.serializedProperty.arraySize += 1; SerializedProperty newElement = mList.serializedProperty.GetArrayElementAtIndex(mList.serializedProperty.arraySize - 1); newElement.objectReferenceValue = newPose; serializedObject.ApplyModifiedProperties(); PoseUtils.SavePose(newPose, (target as PoseManager).transform); }