Skip to content

Instantly share code, notes, and snippets.

@HassakuTb
Created May 2, 2016 01:21
Show Gist options
  • Save HassakuTb/a7b9f279a3e31d9db0a5b2a6fb4174d7 to your computer and use it in GitHub Desktop.
Save HassakuTb/a7b9f279a3e31d9db0a5b2a6fb4174d7 to your computer and use it in GitHub Desktop.
[InitializeOnLoadMethod]
public static void RefreshItemAssetPath() {
EditorApplication.projectWindowChanged += () => {
foreach (string guid in AssetDatabase.FindAssets("t:Item")) {
string path = AssetDatabase.GUIDToAssetPath(guid);
Item item = AssetDatabase.LoadAssetAtPath<Item>(path);
Match match = new Regex(@"Assets\/Resources\/(?<resource_path>.*)\.asset").Match(path);
if (!match.Success) {
Debug.Log("Cannot extract resource Path. : " + path);
return;
}
string resourcePath = match.Groups["resource_path"].Value;
item.assetPath = resourcePath;
}
AssetDatabase.SaveAssets();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment