Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4.  
  5. public static class CopyPath
  6. {
  7.     const string resources_folder = "Resources/";
  8.  
  9.     [MenuItem("Assets/Copy Resources Path")]
  10.     static void CopyResourcesPath()
  11.     {
  12.         var selected = Selection.activeObject;
  13.         var path = AssetDatabase.GetAssetPath(selected);
  14.         var textEditor = new TextEditor();
  15.        
  16.         if (path.Contains(resources_folder))
  17.         {
  18.             var lastIndexOf = path.LastIndexOf(resources_folder, StringComparison.Ordinal) + resources_folder.Length;
  19.             var respath = path.Substring(lastIndexOf, path.Length - lastIndexOf);
  20.            
  21.             Debug.Log("<color=green>" + respath + " - copied to clipboard.</color>");
  22.             textEditor.text = respath;
  23.         }
  24.         else
  25.         {
  26.             Debug.Log("<color=red>" + path + " is not in resources folder, copied anyway!</color>");
  27.             textEditor.text = path;
  28.         }
  29.        
  30.         textEditor.Copy();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement