Last active
August 29, 2015 14:02
-
-
Save tsubaki/40a31e4d6c60d44e302a to your computer and use it in GitHub Desktop.
Assets/Editorフォルダに入れると、ファイルをProjectビューへドラッグ&ドロップした時に、同名のファイルを上書きするようなケースの場合は上書きするスクリプト
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
using UnityEngine; | |
using System.Collections; | |
using System.Text.RegularExpressions; | |
using System.IO; | |
using UnityEditor; | |
public class OverrideFile : AssetPostprocessor { | |
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath) | |
{ | |
if(Event.current == null || Event.current.type != EventType.DragPerform ){ return; } | |
foreach( var asset in importedAssets ) | |
{ | |
var rootAsset = ParentFile(asset); | |
if( rootAsset == null) | |
continue; | |
if( EditorUtility.DisplayDialog("override", rootAsset + "を上書きしますか?","上書き", "両方残す" ) ) | |
{ | |
File.Copy(asset, rootAsset, true); | |
AssetDatabase.DeleteAsset(asset); | |
AssetDatabase.ImportAsset(rootAsset); | |
AssetDatabase.Refresh(); | |
} | |
} | |
} | |
static string ParentFile(string name) | |
{ | |
var match = Regex.Match(name, @"(?<item>.*) 1.(?<extension>.*)"); | |
if(! match.Success ) | |
return null; | |
return string.Format("{0}.{1}", match.Groups["item"] ,match.Groups["extension"]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ファイルの末尾が数値だった場合は上手く動作しない