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 }