private void PasteElement(int i, int j) { if (MenuManager.copiedElement != null) { Undo.RecordObject(this, "Paste element"); int[] idArray = GetElementIDArray(i); MenuElement newElement = MenuManager.copiedElement.DuplicateSelf(true); newElement.linkedUiID = 0; foreach (MenuElement menuElement in menus[i].elements) { if (menuElement.title == newElement.title) { newElement.title += " (Copy)"; break; } } newElement.UpdateID(idArray); newElement.lineID = -1; newElement.hideFlags = HideFlags.HideInHierarchy; menus[i].elements.Insert(j + 1, newElement); AssetDatabase.AddObjectToAsset(newElement, this); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newElement)); AssetDatabase.SaveAssets(); CleanUpAsset(); } }
private void PasteElement(int menuIndex, int elementIndex) { if (MenuManager.copiedElement != null) { Undo.RegisterCompleteObjectUndo(menus[menuIndex], "Paste menu element"); int[] idArray = GetElementIDArray(menuIndex); MenuElement newElement = MenuManager.copiedElement.DuplicateSelf(true, false); newElement.linkedUiID = 0; foreach (MenuElement menuElement in menus[menuIndex].elements) { if (menuElement.title == newElement.title) { newElement.title += " (Copy)"; break; } } newElement.UpdateID(idArray); newElement.lineID = -1; newElement.hideFlags = HideFlags.HideInHierarchy; menus[menuIndex].elements.Insert(elementIndex + 1, newElement); AssetDatabase.AddObjectToAsset(newElement, this); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newElement)); AssetDatabase.SaveAssets(); CleanUpAsset(); EditorUtility.SetDirty(this); } }