Skip to content

Instantly share code, notes, and snippets.

@nicoplv
Last active May 18, 2018 10:06
Show Gist options
  • Select an option

  • Save nicoplv/ef774d1c82a5bdedb88085775c61e6da to your computer and use it in GitHub Desktop.

Select an option

Save nicoplv/ef774d1c82a5bdedb88085775c61e6da to your computer and use it in GitHub Desktop.

Revisions

  1. nicoplv revised this gist May 9, 2018. No changes.
  2. nicoplv revised this gist May 9, 2018. No changes.
  3. nicoplv created this gist May 8, 2018.
    44 changes: 44 additions & 0 deletions ReimportAsset.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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
    }