Last active
May 18, 2018 10:06
-
-
Save nicoplv/ef774d1c82a5bdedb88085775c61e6da to your computer and use it in GitHub Desktop.
Automatize the reimportation of working file from a folder ended with '~' (a demo video is available here https://youtu.be/S-yyK3Fzw3c)
This file contains hidden or 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 UnityEditor; | |
using System.Text.RegularExpressions; | |
using System.IO; | |
public class ReimportAsset : MonoBehaviour | |
{ | |
#region MenuItem Methods | |
[MenuItem("Assets/Reimport from ~ &R", false, priority = 40)] | |
public static void ReimportFromWorkFile() | |
{ | |
if (Selection.activeObject == null) | |
return; | |
bool refresh = false; | |
Regex regex = new Regex("Assets/([^/]*)(.*)"); | |
string dataPath = Application.dataPath.Replace("Assets", ""); | |
foreach (UnityEngine.Object iObject in Selection.objects) | |
{ | |
string assetPath = dataPath + AssetDatabase.GetAssetPath(iObject); | |
string assetPathWork = regex.Replace(assetPath, "Assets/" + "$1" + "~" + "$2"); | |
if (!File.Exists(assetPathWork)) | |
Debug.Log("File " + iObject.name + "can't be reimport, the work file doesn't exist :("); | |
else | |
{ | |
File.Copy(assetPathWork, assetPath, true); | |
refresh = true; | |
} | |
} | |
if(refresh) | |
AssetDatabase.Refresh(); | |
} | |
[MenuItem("Assets/Reimport from ~ &R", true, priority = 40)] | |
public static bool ReimportFromWorkFileValidate() | |
{ | |
if (Selection.activeObject == null) | |
return false; | |
return true; | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment