InspectSingleBundle.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.IO;
  4. namespace AssetBundleBrowser
  5. {
  6. class SingleBundleInspector
  7. {
  8. internal static string currentPath { get; set; }
  9. internal SingleBundleInspector() { }
  10. private Editor m_Editor = null;
  11. private Rect m_Position;
  12. [SerializeField]
  13. private Vector2 m_ScrollPosition;
  14. private AssetBundleInspectTab m_assetBundleInspectTab = null;
  15. private AssetBundleInspectTab.InspectTabData m_inspectTabData = null;
  16. internal void SetBundle(AssetBundle bundle, string path = "", AssetBundleInspectTab.InspectTabData inspectTabData = null, AssetBundleInspectTab assetBundleInspectTab = null)
  17. {
  18. //static var...
  19. currentPath = path;
  20. m_inspectTabData = inspectTabData;
  21. m_assetBundleInspectTab = assetBundleInspectTab;
  22. //members
  23. m_Editor = null;
  24. if(bundle != null)
  25. {
  26. m_Editor = Editor.CreateEditor(bundle);
  27. }
  28. }
  29. internal void OnGUI(Rect pos)
  30. {
  31. m_Position = pos;
  32. DrawBundleData();
  33. }
  34. private void DrawBundleData()
  35. {
  36. if (m_Editor != null)
  37. {
  38. GUILayout.BeginArea(m_Position);
  39. m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
  40. m_Editor.OnInspectorGUI();
  41. EditorGUILayout.EndScrollView();
  42. GUILayout.EndArea();
  43. }
  44. else if(!string.IsNullOrEmpty(currentPath))
  45. {
  46. var style = new GUIStyle(GUI.skin.label);
  47. style.alignment = TextAnchor.MiddleCenter;
  48. style.wordWrap = true;
  49. GUI.Label(m_Position, new GUIContent("Invalid bundle selected"), style);
  50. if (m_inspectTabData != null && GUI.Button(new Rect(new Vector2((m_Position.position.x + m_Position.width / 2f) - 37.5f, (m_Position.position.y + m_Position.height / 2f) + 15), new Vector2(75, 30)), "Ignore file"))
  51. {
  52. var possibleFolderData = m_inspectTabData.FolderDataContainingFilePath(currentPath);
  53. if (possibleFolderData != null)
  54. {
  55. if (!possibleFolderData.ignoredFiles.Contains(currentPath))
  56. possibleFolderData.ignoredFiles.Add(currentPath);
  57. if(m_assetBundleInspectTab != null)
  58. m_assetBundleInspectTab.RefreshBundles();
  59. }
  60. }
  61. }
  62. }
  63. }
  64. [CustomEditor(typeof(AssetBundle))]
  65. internal class AssetBundleEditor : Editor
  66. {
  67. internal bool pathFoldout = false;
  68. internal bool advancedFoldout = false;
  69. public override void OnInspectorGUI()
  70. {
  71. AssetBundle bundle = target as AssetBundle;
  72. using (new EditorGUI.DisabledScope(true))
  73. {
  74. var leftStyle = new GUIStyle(GUI.skin.GetStyle("Label"));
  75. leftStyle.alignment = TextAnchor.UpperLeft;
  76. GUILayout.Label(new GUIContent("Name: " + bundle.name), leftStyle);
  77. long fileSize = -1;
  78. if(!System.String.IsNullOrEmpty(SingleBundleInspector.currentPath) && File.Exists(SingleBundleInspector.currentPath) )
  79. {
  80. System.IO.FileInfo fileInfo = new System.IO.FileInfo(SingleBundleInspector.currentPath);
  81. fileSize = fileInfo.Length;
  82. }
  83. if (fileSize < 0)
  84. GUILayout.Label(new GUIContent("Size: unknown"), leftStyle);
  85. else
  86. GUILayout.Label(new GUIContent("Size: " + EditorUtility.FormatBytes(fileSize)), leftStyle);
  87. var assetNames = bundle.GetAllAssetNames();
  88. pathFoldout = EditorGUILayout.Foldout(pathFoldout, "Source Asset Paths");
  89. if (pathFoldout)
  90. {
  91. EditorGUI.indentLevel++;
  92. foreach (var asset in assetNames)
  93. EditorGUILayout.LabelField(asset);
  94. EditorGUI.indentLevel--;
  95. }
  96. advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced Data");
  97. }
  98. if (advancedFoldout)
  99. {
  100. EditorGUI.indentLevel++;
  101. base.OnInspectorGUI();
  102. EditorGUI.indentLevel--;
  103. }
  104. }
  105. }
  106. }