AssetsViewWindow.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace BeinLab.Util
  6. {
  7. public class AssetsViewWindow : EditorWindow
  8. {
  9. private Rect rectOfAsset;
  10. private string assetPath;
  11. //public bool IsRelativelyPath = true;
  12. public UnityEngine.Object targetObj;
  13. private bool isToLower;
  14. [MenuItem("Tools/AssetView %Y")]
  15. static void BuildViewWindow()
  16. {
  17. AssetsViewWindow bw = EditorWindow.GetWindow(typeof(AssetsViewWindow), false, "资源路径浏览器", true) as AssetsViewWindow;
  18. bw.ShowPopup();
  19. }
  20. private void OnGUI()
  21. {
  22. rectOfAsset = EditorGUILayout.GetControlRect(GUILayout.Width(600));
  23. assetPath = EditorGUI.TextField(rectOfAsset, "对象路径", assetPath);
  24. if (GUILayout.Button("刷新", GUILayout.Width(100)))
  25. {
  26. targetObj = AssetDatabase.LoadAssetAtPath("Assets/" + assetPath, typeof(UnityEngine.Object));
  27. }
  28. bool isChange = isToLower;
  29. isToLower = EditorGUILayout.ToggleLeft("自动小写", isToLower);
  30. if (isChange != isToLower)
  31. {
  32. isChange = isToLower;
  33. if (targetObj)
  34. {
  35. assetPath = AssetDatabase.GetAssetPath(targetObj).Replace("Assets/", "");
  36. if (isToLower)
  37. {
  38. assetPath = assetPath.ToLower();
  39. }
  40. }
  41. }
  42. //targetObj = EditorGUILayout.ObjectField(targetObj, typeof(UnityEngine.Object), null) as UnityEngine.Object;
  43. //targetObj = EditorGUI.ObjectField(new Rect(0, 5, 300, 20), targetObj, typeof(UnityEngine.Object), true);
  44. //IsRelativelyPath = EditorGUILayout.ToggleLeft("美术包相对路径", IsRelativelyPath);
  45. if (Event.current.type == EventType.DragUpdated
  46. || Event.current.type == EventType.DragExited)
  47. {
  48. if (rectOfAsset.Contains(Event.current.mousePosition))
  49. {
  50. DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
  51. if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
  52. {
  53. assetPath = DragAndDrop.paths[0].Replace("Assets/", "");
  54. if (isToLower)
  55. {
  56. assetPath = assetPath.ToLower();
  57. }
  58. //if (IsRelativelyPath)
  59. //{
  60. // assetPath = assetPath.Substring(assetPath.IndexOf("/") + 1);
  61. //}
  62. targetObj = AssetDatabase.LoadAssetAtPath(DragAndDrop.paths[0], typeof(UnityEngine.Object));
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }