Created
November 24, 2021 16:09
-
-
Save instance-id/5bbe6772a045e6ab89bb7bf8bfc528e9 to your computer and use it in GitHub Desktop.
Unity Project View Asset Drag/Move Confirmation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------- | |
// -- Project View Asset Move Confirmation ------ | |
// -- Place In Editor Folder -------------------- | |
// ---------------------------------------------- | |
using System; | |
using System.IO; | |
using UnityEditor; | |
internal sealed class DragAssetConfirmation : UnityEditor.AssetModificationProcessor | |
{ | |
private static bool moveAllItems; | |
private static AssetMoveResult OnWillMoveAsset(string sourcePath, string destinationPath) | |
{ | |
if (moveAllItems) return AssetMoveResult.DidNotMove; | |
var sourceDir = Path.GetDirectoryName(sourcePath); | |
var destinationDir = Path.GetDirectoryName(destinationPath); | |
if (sourceDir == destinationDir) return AssetMoveResult.DidNotMove; | |
var index = EditorUtility.DisplayDialogComplex | |
( | |
title: "Confirm Asset Move", | |
message: $"{sourcePath} -> {destinationPath} Move These Items?", | |
ok: "Ok", | |
cancel: "Cancel", | |
alt: "Move All Items" | |
); | |
switch (index) | |
{ | |
case 0: return AssetMoveResult.DidNotMove; | |
case 1: return AssetMoveResult.FailedMove; | |
case 2: | |
{ | |
moveAllItems = true; | |
EditorApplication.delayCall += () => moveAllItems = false; | |
return AssetMoveResult.DidNotMove; | |
} | |
} | |
throw new InvalidOperationException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment