Skip to content

Instantly share code, notes, and snippets.

@instance-id
Created November 24, 2021 16:09
Show Gist options
  • Save instance-id/5bbe6772a045e6ab89bb7bf8bfc528e9 to your computer and use it in GitHub Desktop.
Save instance-id/5bbe6772a045e6ab89bb7bf8bfc528e9 to your computer and use it in GitHub Desktop.
Unity Project View Asset Drag/Move Confirmation
// ----------------------------------------------
// -- 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