private void MenuEditScript(object userData) { int index = (int)userData; var draw = m_draws[index]; ScriptableObjectCollectionUtility.EditScript(draw.TargetEditor); }
private void MenuCopy(object userData) { int index = (int)userData; var propertyElement = m_serializedProperty.GetArrayElementAtIndex(index); var scriptableObject = (ScriptableObject)propertyElement.objectReferenceValue; ScriptableObjectCollectionUtility.Copy(scriptableObject); }
public ScriptableObjectCollectionDraw(SerializedProperty serializedProperty) { m_serializedProperty = serializedProperty; m_elementType = ScriptableObjectCollectionUtility.GetElementType(serializedProperty); m_tracker = new ScriptableObjectCollectionTracker(serializedProperty.serializedObject); Rebuild(); }
private void MenuAdd(object userdata) { var type = (Type)userdata; var scriptableObject = ScriptableObject.CreateInstance(type); scriptableObject.name = type.Name; ScriptableObjectCollectionUtility.AddElement(m_serializedProperty, scriptableObject); }
private void MenuPasteValues(object userData) { int index = (int)userData; var draw = m_draws[index]; ScriptableObjectCollectionUtility.PasteValues(draw.TargetEditor); EditorUtility.SetDirty(m_serializedProperty.serializedObject.targetObject); }
public void DrawAddButton() { using (new EditorGUI.DisabledScope(m_serializedProperty.hasMultipleDifferentValues)) { if (ScriptableObjectCollectionGUIUtility.DrawAddButtonBig()) { ScriptableObjectCollectionUtility.CreateScriptableObjectMenu(MenuAdd, m_elementType).ShowAsContext(); } } }
private void MenuRemove(object userData) { int index = (int)userData; var propertyElement = m_serializedProperty.GetArrayElementAtIndex(index); if (propertyElement.objectReferenceValue != null) { ScriptableObjectCollectionUtility.RemoveElement(m_serializedProperty, index); } else { m_serializedProperty.DeleteArrayElementAtIndex(index); m_serializedProperty.serializedObject.ApplyModifiedProperties(); } EditorUtility.SetDirty(m_serializedProperty.serializedObject.targetObject); }
private void MenuPasteAsNew(object userData) { int index = (int)userData; ScriptableObjectCollectionUtility.PasteAsNew(m_serializedProperty, index); }
private void ShowMenu(int index) { var menu = new GenericMenu(); var contentReset = new GUIContent("Reset"); var contentRemove = new GUIContent("Remove ScriptableObject"); var contentMoveUp = new GUIContent("Move Up"); var contentMoveDown = new GUIContent("Move Down"); var contentCopy = new GUIContent("Copy ScriptableObject"); var contentPasteAsNew = new GUIContent("Paste ScriptableObject As New"); var contentPasteValues = new GUIContent("Paste ScriptableObject Values"); var contentEditScript = new GUIContent("Edit Script"); var draw = m_draws[index]; bool hasMultipleValues = m_serializedProperty.hasMultipleDifferentValues; bool isEmpty = draw.TargetEditor == null; if (!isEmpty) { menu.AddItem(contentReset, false, MenuReset, index); } else { menu.AddDisabledItem(contentReset); } menu.AddSeparator(string.Empty); if (!hasMultipleValues) { menu.AddItem(contentRemove, false, MenuRemove, index); } else { menu.AddDisabledItem(contentRemove); } if (!hasMultipleValues && index > 0) { menu.AddItem(contentMoveUp, false, MenuMoveUp, index); } else { menu.AddDisabledItem(contentMoveUp); } if (!hasMultipleValues && index < m_serializedProperty.arraySize - 1) { menu.AddItem(contentMoveDown, false, MenuMoveDown, index); } else { menu.AddDisabledItem(contentMoveDown); } if (!hasMultipleValues && !isEmpty) { menu.AddItem(contentCopy, false, MenuCopy, index); } else { menu.AddDisabledItem(contentCopy); } if (!hasMultipleValues && ScriptableObjectCollectionUtility.CanPasteAsNew(m_elementType)) { menu.AddItem(contentPasteAsNew, false, MenuPasteAsNew, index); } else { menu.AddDisabledItem(contentPasteAsNew); } if (!isEmpty && ScriptableObjectCollectionUtility.CanPasteValues(m_draws[index].TargetEditor)) { menu.AddItem(contentPasteValues, false, MenuPasteValues, index); } else { menu.AddDisabledItem(contentPasteValues); } menu.AddSeparator(string.Empty); if (!isEmpty) { menu.AddItem(contentEditScript, false, MenuEditScript, index); } else { menu.AddDisabledItem(contentEditScript); } if (!isEmpty) { var editorWithCustomMenu = draw.TargetEditor as IHasCustomMenu; if (editorWithCustomMenu != null) { menu.AddSeparator(string.Empty); editorWithCustomMenu.AddItemsToMenu(menu); } } menu.ShowAsContext(); }