FR2_WindowAll.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using Object = UnityEngine.Object;
  8. #if UNITY_5_3_OR_NEWER
  9. #endif
  10. namespace vietlabs.fr2
  11. {
  12. // filter, ignore anh huong ket qua thi hien mau do
  13. // optimize lag duplicate khi use
  14. public class FR2_WindowAll : FR2_WindowBase, IHasCustomMenu
  15. {
  16. [MenuItem("Window/Find Reference 2")]
  17. private static void ShowWindow()
  18. {
  19. var _window = CreateInstance<FR2_WindowAll>();
  20. _window.InitIfNeeded();
  21. FR2_Unity.SetWindowTitle(_window, "FR2");
  22. _window.Show();
  23. }
  24. [NonSerialized] internal FR2_Bookmark bookmark;
  25. [NonSerialized] internal FR2_Selection selection;
  26. [NonSerialized] internal FR2_UsedInBuild UsedInBuild;
  27. [NonSerialized] internal FR2_DuplicateTree2 Duplicated;
  28. [NonSerialized] internal FR2_RefDrawer RefUnUse;
  29. [NonSerialized] internal FR2_RefDrawer UsesDrawer; // [Selected Assets] are [USING] (depends on / contains reference to) ---> those assets
  30. [NonSerialized] internal FR2_RefDrawer UsedByDrawer; // [Selected Assets] are [USED BY] <---- those assets
  31. [NonSerialized] internal FR2_RefDrawer SceneToAssetDrawer; // [Selected GameObjects in current Scene] are [USING] ---> those assets
  32. [NonSerialized] internal FR2_RefDrawer RefInScene; // [Selected Assets] are [USED BY] <---- those components in current Scene
  33. [NonSerialized] internal FR2_RefDrawer SceneUsesDrawer; // [Selected GameObjects] are [USING] ---> those components / GameObjects in current scene
  34. [NonSerialized] internal FR2_RefDrawer RefSceneInScene; // [Selected GameObjects] are [USED BY] <---- those components / GameObjects in current scene
  35. internal int level;
  36. private Vector2 scrollPos;
  37. private string tempGUID;
  38. private Object tempObject;
  39. protected bool lockSelection
  40. {
  41. get { return selection != null && selection.isLock; }
  42. }
  43. private void OnEnable()
  44. {
  45. Repaint();
  46. }
  47. protected void InitIfNeeded()
  48. {
  49. if (UsesDrawer != null) return;
  50. UsesDrawer = new FR2_RefDrawer(this)
  51. {
  52. messageEmpty = "[Selected Assets] are not [USING] (depends on / contains reference to) any other assets!"
  53. };
  54. UsedByDrawer = new FR2_RefDrawer(this)
  55. {
  56. messageEmpty = "[Selected Assets] are not [USED BY] any other assets!"
  57. };
  58. Duplicated = new FR2_DuplicateTree2(this);
  59. SceneToAssetDrawer = new FR2_RefDrawer(this)
  60. {
  61. messageEmpty = "[Selected GameObjects] (in current open scenes) are not [USING] any assets!"
  62. };
  63. RefUnUse = new FR2_RefDrawer(this);
  64. RefUnUse.groupDrawer.hideGroupIfPossible = true;
  65. UsedInBuild = new FR2_UsedInBuild(this);
  66. bookmark = new FR2_Bookmark(this);
  67. selection = new FR2_Selection(this);
  68. SceneUsesDrawer = new FR2_RefDrawer(this)
  69. {
  70. messageEmpty = "[Selected GameObjects] are not [USING] any other GameObjects in scenes"
  71. };
  72. RefInScene = new FR2_RefDrawer(this)
  73. {
  74. messageEmpty = "[Selected Assets] are not [USED BY] any GameObjects in opening scenes!"
  75. };
  76. RefSceneInScene = new FR2_RefDrawer(this)
  77. {
  78. messageEmpty = "[Selected GameObjects] are not [USED BY] by any GameObjects in opening scenes!"
  79. };
  80. #if UNITY_2018_OR_NEWER
  81. UnityEditor.SceneManagement.EditorSceneManager.activeSceneChangedInEditMode -= OnSceneChanged;
  82. UnityEditor.SceneManagement.EditorSceneManager.activeSceneChangedInEditMode += OnSceneChanged;
  83. #elif UNITY_2017_OR_NEWER
  84. UnityEditor.SceneManagement.EditorSceneManager.activeSceneChanged -= OnSceneChanged;
  85. UnityEditor.SceneManagement.EditorSceneManager.activeSceneChanged += OnSceneChanged;
  86. #endif
  87. FR2_Cache.onReady -= OnReady;
  88. FR2_Cache.onReady += OnReady;
  89. FR2_Setting.OnIgnoreChange -= OnIgnoreChanged;
  90. FR2_Setting.OnIgnoreChange += OnIgnoreChanged;
  91. Repaint();
  92. }
  93. #if UNITY_2018_OR_NEWER
  94. private void OnSceneChanged(Scene arg0, Scene arg1)
  95. {
  96. if (IsFocusingFindInScene || IsFocusingSceneToAsset || IsFocusingSceneInScene)
  97. {
  98. OnSelectionChange();
  99. }
  100. }
  101. #endif
  102. protected void OnIgnoreChanged()
  103. {
  104. RefUnUse.ResetUnusedAsset();
  105. UsedInBuild.SetDirty();
  106. OnSelectionChange();
  107. }
  108. protected void OnCSVClick()
  109. {
  110. FR2_Ref[] csvSource = null;
  111. var drawer = GetAssetDrawer();
  112. if (drawer != null) csvSource = drawer.source;
  113. if (IsFocusingUnused && csvSource == null)
  114. {
  115. csvSource = RefUnUse.source;
  116. //if (csvSource != null) Debug.Log("d : " + csvSource.Length);
  117. }
  118. if (IsFocusingUsedInBuild && csvSource == null)
  119. {
  120. csvSource = FR2_Ref.FromDict(UsedInBuild.refs);
  121. //if (csvSource != null) Debug.Log("e : " + csvSource.Length);
  122. }
  123. if (IsFocusingDuplicate && csvSource == null)
  124. {
  125. csvSource = FR2_Ref.FromList(Duplicated.list);
  126. //if (csvSource != null) Debug.Log("f : " + csvSource.Length);
  127. }
  128. FR2_Export.ExportCSV(csvSource);
  129. }
  130. protected void OnReady()
  131. {
  132. OnSelectionChange();
  133. }
  134. public override void OnSelectionChange()
  135. {
  136. Repaint();
  137. isNoticeIgnore = false;
  138. if (!FR2_Cache.isReady)
  139. {
  140. return;
  141. }
  142. if (focusedWindow == null)
  143. {
  144. return;
  145. }
  146. if (SceneUsesDrawer == null)
  147. {
  148. InitIfNeeded();
  149. }
  150. if (UsesDrawer == null)
  151. {
  152. InitIfNeeded();
  153. }
  154. if (!lockSelection)
  155. {
  156. ids = FR2_Unity.Selection_AssetGUIDs;
  157. selection.Clear();
  158. //ignore selection on asset when selected any object in scene
  159. if (Selection.gameObjects.Length > 0 && !FR2_Unity.IsInAsset(Selection.gameObjects[0]))
  160. {
  161. ids = new string[0];
  162. selection.AddRange(Selection.gameObjects);
  163. }
  164. else
  165. {
  166. selection.AddRange(ids);
  167. }
  168. level = 0;
  169. if (selection.isSelectingAsset)
  170. {
  171. UsesDrawer.Reset(ids, true);
  172. UsedByDrawer.Reset(ids, false);
  173. RefInScene.Reset(ids, this as IWindow);
  174. }
  175. else
  176. {
  177. RefSceneInScene.ResetSceneInScene(Selection.gameObjects);
  178. SceneToAssetDrawer.Reset(Selection.gameObjects, true, true);
  179. SceneUsesDrawer.ResetSceneUseSceneObjects(Selection.gameObjects);
  180. }
  181. // auto disable enable scene / asset
  182. if (IsFocusingUses)
  183. {
  184. sp2.splits[0].visible = !selection.isSelectingAsset;
  185. sp2.splits[1].visible = true;
  186. sp2.CalculateWeight();
  187. }
  188. if (IsFocusingUsedBy)
  189. {
  190. sp2.splits[0].visible = true;
  191. sp2.splits[1].visible = selection.isSelectingAsset;
  192. sp2.CalculateWeight();
  193. }
  194. }
  195. if (IsFocusingGUIDs)
  196. {
  197. //objs = new Object[ids.Length];
  198. objs = new Dictionary<string, Object>();
  199. var objects = Selection.objects;
  200. for (var i = 0; i < objects.Length; i++)
  201. {
  202. var item = objects[i];
  203. #if UNITY_2018_1_OR_NEWER
  204. {
  205. var guid = "";
  206. long fileid =-1;
  207. try
  208. {
  209. if(AssetDatabase.TryGetGUIDAndLocalFileIdentifier(item, out guid, out fileid))
  210. {
  211. objs.Add(guid+"/"+ fileid, objects[i]);
  212. //Debug.Log("guid: " + guid + " fileID: " + fileid);
  213. }
  214. }
  215. catch{}
  216. }
  217. #else
  218. {
  219. var path = AssetDatabase.GetAssetPath(item);
  220. if (string.IsNullOrEmpty(path)) continue;
  221. var guid = AssetDatabase.AssetPathToGUID(path);
  222. System.Reflection.PropertyInfo inspectorModeInfo =
  223. typeof(SerializedObject).GetProperty("inspectorMode", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  224. SerializedObject serializedObject = new SerializedObject(item);
  225. inspectorModeInfo.SetValue(serializedObject, InspectorMode.Debug, null);
  226. SerializedProperty localIdProp =
  227. serializedObject.FindProperty("m_LocalIdentfierInFile"); //note the misspelling!
  228. var localId = localIdProp.longValue;
  229. if (localId <= 0)
  230. {
  231. localId = localIdProp.intValue;
  232. }
  233. if (localId <= 0)
  234. {
  235. continue;
  236. }
  237. if (!string.IsNullOrEmpty(guid)) objs.Add(guid + "/" + localId, objects[i]);
  238. }
  239. #endif
  240. }
  241. }
  242. if (IsFocusingUnused)
  243. {
  244. RefUnUse.ResetUnusedAsset();
  245. }
  246. if (FR2_SceneCache.Api.Dirty && !Application.isPlaying)
  247. {
  248. FR2_SceneCache.Api.refreshCache(this);
  249. }
  250. EditorApplication.delayCall -= Repaint;
  251. EditorApplication.delayCall += Repaint;
  252. }
  253. public FR2_SplitView sp1; // container : Selection / sp2 / Bookmark
  254. public FR2_SplitView sp2; // Scene / Assets
  255. void InitPanes()
  256. {
  257. sp2 = new FR2_SplitView(this)
  258. {
  259. isHorz = false,
  260. splits = new List<FR2_SplitView.Info>()
  261. {
  262. new FR2_SplitView.Info(){ title = new GUIContent("Scene", FR2_Icon.Scene.image), draw = DrawScene },
  263. new FR2_SplitView.Info(){ title = new GUIContent("Assets", FR2_Icon.Asset.image), draw = DrawAsset },
  264. }
  265. };
  266. sp2.CalculateWeight();
  267. sp1 = new FR2_SplitView(this)
  268. {
  269. isHorz = true,
  270. splits = new List<FR2_SplitView.Info>()
  271. {
  272. new FR2_SplitView.Info(){ title = new GUIContent("Selection", FR2_Icon.Selection.image), weight = 0.4f, visible = false, draw = (rect) => selection.Draw(rect) },
  273. new FR2_SplitView.Info(){ draw = (r) =>
  274. {
  275. if (IsFocusingUses || IsFocusingUsedBy)
  276. {
  277. sp2.Draw(r);
  278. }
  279. else
  280. {
  281. DrawTools(r);
  282. }
  283. } },
  284. new FR2_SplitView.Info(){ title = new GUIContent("Bookmark", FR2_Icon.Favorite.image), weight = 0.4f, visible = false, draw = (rect) => bookmark.Draw(rect) },
  285. }
  286. };
  287. sp1.CalculateWeight();
  288. }
  289. private FR2_TabView tabs;
  290. private FR2_TabView bottomTabs;
  291. private FR2_SearchView search;
  292. void DrawScene(Rect rect)
  293. {
  294. FR2_RefDrawer drawer = IsFocusingUses
  295. ? (selection.isSelectingAsset ? null : SceneUsesDrawer)
  296. : (selection.isSelectingAsset ? RefInScene : RefSceneInScene);
  297. if (drawer == null) return;
  298. if (!FR2_SceneCache.ready)
  299. {
  300. var rr = rect;
  301. rr.height = 16f;
  302. int cur = FR2_SceneCache.Api.current, total = FR2_SceneCache.Api.total;
  303. EditorGUI.ProgressBar(rr, cur * 1f / total, string.Format("{0} / {1}", cur, total));
  304. WillRepaint = true;
  305. return;
  306. }
  307. drawer.Draw(rect);
  308. var refreshRect = new Rect(rect.xMax-16f, rect.yMin-14f, 18f, 18f);
  309. if (GUI2.ColorIconButton(refreshRect, FR2_Icon.Refresh.image,
  310. FR2_SceneCache.Api.Dirty ? (Color?)GUI2.lightRed : null))
  311. {
  312. FR2_SceneCache.Api.refreshCache(drawer.window);
  313. }
  314. }
  315. FR2_RefDrawer GetAssetDrawer()
  316. {
  317. if (IsFocusingUses)
  318. {
  319. return selection.isSelectingAsset ? UsesDrawer : SceneToAssetDrawer;
  320. }
  321. if (IsFocusingUsedBy)
  322. {
  323. return selection.isSelectingAsset ? UsedByDrawer : null;
  324. }
  325. return null;
  326. }
  327. void DrawAsset(Rect rect)
  328. {
  329. var drawer = GetAssetDrawer();
  330. if (drawer != null) drawer.Draw(rect);
  331. }
  332. void DrawSearch()
  333. {
  334. if (search == null) search = new FR2_SearchView();
  335. search.DrawLayout();
  336. }
  337. protected override void OnGUI()
  338. {
  339. OnGUI2();
  340. }
  341. protected bool CheckDrawImport()
  342. {
  343. if (EditorApplication.isCompiling)
  344. {
  345. EditorGUILayout.HelpBox("Compiling scripts, please wait!", MessageType.Warning);
  346. Repaint();
  347. return false;
  348. }
  349. if (EditorApplication.isUpdating)
  350. {
  351. EditorGUILayout.HelpBox("Importing assets, please wait!", MessageType.Warning);
  352. Repaint();
  353. return false;
  354. }
  355. InitIfNeeded();
  356. if (EditorSettings.serializationMode != SerializationMode.ForceText)
  357. {
  358. EditorGUILayout.HelpBox("FR2 requires serialization mode set to FORCE TEXT!", MessageType.Warning);
  359. if (GUILayout.Button("FORCE TEXT"))
  360. {
  361. EditorSettings.serializationMode = SerializationMode.ForceText;
  362. }
  363. return false;
  364. }
  365. if (FR2_Cache.hasCache && !FR2_Cache.CheckSameVersion())
  366. {
  367. EditorGUILayout.HelpBox("Incompatible cache version found!!!\nFR2 will need a full refresh and this may take quite some time to finish but you would be able to work normally while the scan works in background!",
  368. MessageType.Warning);
  369. FR2_Cache.DrawPriorityGUI();
  370. if (GUILayout.Button("Scan project"))
  371. {
  372. FR2_Cache.DeleteCache();
  373. FR2_Cache.CreateCache();
  374. }
  375. return false;
  376. }
  377. if (!FR2_Cache.isReady)
  378. {
  379. if (!FR2_Cache.hasCache)
  380. {
  381. EditorGUILayout.HelpBox(
  382. "FR2 cache not found!\nFirst scan may takes quite some time to finish but you would be able to work normally while the scan works in background...",
  383. MessageType.Warning);
  384. FR2_Cache.DrawPriorityGUI();
  385. if (GUILayout.Button("Scan project"))
  386. {
  387. FR2_Cache.CreateCache();
  388. Repaint();
  389. }
  390. return false;
  391. }
  392. else
  393. {
  394. FR2_Cache.DrawPriorityGUI();
  395. }
  396. if (!DrawEnable())
  397. {
  398. return false;
  399. }
  400. FR2_Cache api = FR2_Cache.Api;
  401. string text = "Refreshing ... " + (int) (api.progress * api.workCount) + " / " + api.workCount;
  402. Rect rect = GUILayoutUtility.GetRect(1f, Screen.width, 18f, 18f);
  403. EditorGUI.ProgressBar(rect, api.progress, text);
  404. Repaint();
  405. return false;
  406. }
  407. if (!DrawEnable())
  408. {
  409. return false;
  410. }
  411. return true;
  412. }
  413. protected bool IsFocusingUses { get { return tabs != null && tabs.current == 0; }}
  414. protected bool IsFocusingUsedBy { get { return tabs != null && tabs.current == 1; }}
  415. protected bool IsFocusingDuplicate { get { return tabs != null && tabs.current == 2; }}
  416. protected bool IsFocusingGUIDs { get { return tabs != null && tabs.current == 3; }}
  417. protected bool IsFocusingUnused { get { return tabs != null && tabs.current == 4; }}
  418. protected bool IsFocusingUsedInBuild { get { return tabs != null && tabs.current == 5; }}
  419. void OnTabChange()
  420. {
  421. if (deleteUnused != null) deleteUnused.hasConfirm = false;
  422. if (UsedInBuild != null) UsedInBuild.SetDirty();
  423. }
  424. void InitTabs()
  425. {
  426. tabs = FR2_TabView.Create(this, false,
  427. "Uses", "Used By", "Duplicate", "GUIDs", "Unused Assets", "Uses in Build"
  428. );
  429. tabs.onTabChange = OnTabChange;
  430. tabs.callback = new DrawCallback()
  431. {
  432. BeforeDraw = ()=>
  433. {
  434. if (GUI2.ToolbarToggle(ref selection.isLock,
  435. selection.isLock ? FR2_Icon.Lock.image : FR2_Icon.Unlock.image,
  436. new Vector2(-1, 2), "Lock Selection"))
  437. {
  438. WillRepaint = true;
  439. }
  440. },
  441. AfterDraw = () =>
  442. {
  443. //GUILayout.Space(16f);
  444. if (GUI2.ToolbarToggle(ref sp1.isHorz, FR2_Icon.Panel.image, Vector2.zero, "Layout"))
  445. {
  446. sp1.CalculateWeight();
  447. Repaint();
  448. }
  449. if (GUI2.ToolbarToggle(ref sp1.splits[0].visible, FR2_Icon.Selection.image, Vector2.zero, "Show / Hide Selection"))
  450. {
  451. sp1.CalculateWeight();
  452. Repaint();
  453. }
  454. if (GUI2.ToolbarToggle(ref sp2.splits[0].visible, FR2_Icon.Scene.image, Vector2.zero, "Show / Hide Scene References"))
  455. {
  456. sp2.CalculateWeight();
  457. Repaint();
  458. }
  459. if (GUI2.ToolbarToggle(ref sp2.splits[1].visible, FR2_Icon.Asset.image, Vector2.zero, "Show / Hide Asset References"))
  460. {
  461. sp2.CalculateWeight();
  462. Repaint();
  463. }
  464. if (GUI2.ToolbarToggle(ref sp1.splits[2].visible, FR2_Icon.Favorite.image, Vector2.zero, "Show / Hide Bookmarks"))
  465. {
  466. sp1.CalculateWeight();
  467. Repaint();
  468. }
  469. }
  470. };
  471. }
  472. protected bool DrawHeader()
  473. {
  474. if (tabs == null) InitTabs();
  475. if (bottomTabs == null)
  476. {
  477. bottomTabs = FR2_TabView.Create(this, true,
  478. new GUIContent(FR2_Icon.Setting.image, "Settings"),
  479. new GUIContent(FR2_Icon.Ignore.image, "Ignore"),
  480. new GUIContent(FR2_Icon.Filter.image, "Filter by Type")
  481. );
  482. bottomTabs.current = -1;
  483. }
  484. tabs.DrawLayout();
  485. return true;
  486. }
  487. protected bool DrawFooter()
  488. {
  489. GUILayout.BeginHorizontal(EditorStyles.toolbar);
  490. {
  491. bottomTabs.DrawLayout();
  492. GUILayout.FlexibleSpace();
  493. DrawAssetViewSettings();
  494. GUILayout.FlexibleSpace();
  495. DrawViewModes();
  496. }
  497. GUILayout.EndHorizontal();
  498. return false;
  499. }
  500. void DrawAssetViewSettings()
  501. {
  502. var isDisable = !sp2.splits[1].visible;
  503. EditorGUI.BeginDisabledGroup(isDisable);
  504. {
  505. GUI2.ToolbarToggle(ref FR2_Setting.s.displayAssetBundleName, FR2_Icon.AssetBundle.image, Vector2.zero, "Show / Hide Assetbundle Names");
  506. #if UNITY_2017_1_OR_NEWER
  507. GUI2.ToolbarToggle(ref FR2_Setting.s.displayAtlasName, FR2_Icon.Atlas.image, Vector2.zero, "Show / Hide Atlas packing tags");
  508. #endif
  509. GUI2.ToolbarToggle(ref FR2_Setting.s.showUsedByClassed, FR2_Icon.Material.image, Vector2.zero, "Show / Hide usage icons");
  510. GUI2.ToolbarToggle(ref FR2_Setting.s.displayFileSize, FR2_Icon.Filesize.image, Vector2.zero, "Show / Hide file size");
  511. if (GUILayout.Button("CSV", EditorStyles.toolbarButton))
  512. {
  513. OnCSVClick();
  514. }
  515. }
  516. EditorGUI.EndDisabledGroup();
  517. }
  518. void DrawViewModes()
  519. {
  520. var gMode = FR2_Setting.GroupMode;
  521. if (GUI2.EnumPopup(ref gMode, new GUIContent(FR2_Icon.Group.image, "Group by"), EditorStyles.toolbarPopup, GUILayout.Width(80f)))
  522. {
  523. FR2_Setting.GroupMode = gMode;
  524. markDirty();
  525. }
  526. GUILayout.Space(16f);
  527. var sMode = FR2_Setting.SortMode;
  528. if (GUI2.EnumPopup(ref sMode, new GUIContent(FR2_Icon.Sort.image, "Sort by"), EditorStyles.toolbarPopup, GUILayout.Width(50f)))
  529. {
  530. FR2_Setting.SortMode = sMode;
  531. RefreshSort();
  532. }
  533. }
  534. protected void OnGUI2()
  535. {
  536. if (!CheckDrawImport())
  537. {
  538. return;
  539. }
  540. if (sp1 == null) InitPanes();
  541. DrawHeader();
  542. sp1.DrawLayout();
  543. DrawSettings();
  544. DrawFooter();
  545. if (WillRepaint)
  546. {
  547. Repaint();
  548. }
  549. }
  550. private FR2_DeleteButton deleteUnused;
  551. void DrawTools(Rect rect)
  552. {
  553. if (IsFocusingDuplicate)
  554. {
  555. rect = GUI2.Padding(rect, 2f, 2f);
  556. GUILayout.BeginArea(rect);
  557. Duplicated.DrawLayout();
  558. GUILayout.EndArea();
  559. return;
  560. }
  561. if (IsFocusingUnused)
  562. {
  563. rect = GUI2.Padding(rect, 2f, 2f);
  564. if ((RefUnUse.refs != null && RefUnUse.refs.Count == 0))
  565. {
  566. GUILayout.BeginArea(rect);
  567. {
  568. EditorGUILayout.HelpBox("Wow! So clean!?", MessageType.Info);
  569. EditorGUILayout.HelpBox("Your project does not has have any unused assets, or have you just hit DELETE ALL?", MessageType.Info);
  570. EditorGUILayout.HelpBox("Your backups are placed at Library/FR2/ just in case you want your assets back!", MessageType.Info);
  571. }
  572. GUILayout.EndArea();
  573. }
  574. else
  575. {
  576. rect.yMax -= 40f;
  577. GUILayout.BeginArea(rect);
  578. RefUnUse.DrawLayout();
  579. GUILayout.EndArea();
  580. var toolRect = rect;
  581. toolRect.yMin = toolRect.yMax;
  582. var lineRect = toolRect;
  583. lineRect.height = 1f;
  584. GUI2.Rect(lineRect, Color.black, 0.5f);
  585. toolRect.xMin += 2f;
  586. toolRect.xMax -= 2f;
  587. toolRect.height = 40f;
  588. if (deleteUnused == null)
  589. {
  590. deleteUnused = new FR2_DeleteButton()
  591. {
  592. warningMessage = "It's absolutely safe to delete them all!\nA backup (.unitypackage) will be created so you can import it back later!",
  593. deleteLabel = new GUIContent("DELETE ASSETS", FR2_Icon.Delete.image),
  594. confirmMessage = "Create backup at Library/FR2/"
  595. };
  596. }
  597. GUILayout.BeginArea(toolRect);
  598. deleteUnused.Draw(()=> { FR2_Unity.BackupAndDeleteAssets(RefUnUse.source); });
  599. GUILayout.EndArea();
  600. }
  601. return;
  602. }
  603. if (IsFocusingUsedInBuild)
  604. {
  605. UsedInBuild.Draw(rect);
  606. return;
  607. }
  608. if (IsFocusingGUIDs)
  609. {
  610. rect = GUI2.Padding(rect, 2f, 2f);
  611. GUILayout.BeginArea(rect);
  612. DrawGUIDs();
  613. GUILayout.EndArea();
  614. return;
  615. }
  616. }
  617. void DrawSettings()
  618. {
  619. if (bottomTabs.current == -1) return;
  620. GUILayout.BeginVertical(GUILayout.Height(100f));
  621. {
  622. GUILayout.Space(2f);
  623. switch (bottomTabs.current)
  624. {
  625. case 0:
  626. {
  627. FR2_Setting.s.DrawSettings();
  628. break;
  629. }
  630. case 1:
  631. {
  632. if (AssetType.DrawIgnoreFolder())
  633. {
  634. markDirty();
  635. }
  636. break;
  637. }
  638. case 2:
  639. {
  640. if (AssetType.DrawSearchFilter())
  641. {
  642. markDirty();
  643. }
  644. break;
  645. }
  646. }
  647. }
  648. GUILayout.EndVertical();
  649. var rect = GUILayoutUtility.GetLastRect();
  650. rect.height = 1f;
  651. GUI2.Rect(rect, Color.black, 0.4f);
  652. }
  653. protected void markDirty()
  654. {
  655. UsedByDrawer.SetDirty();
  656. UsesDrawer.SetDirty();
  657. Duplicated.SetDirty();
  658. SceneToAssetDrawer.SetDirty();
  659. RefUnUse.SetDirty();
  660. RefInScene.SetDirty();
  661. RefSceneInScene.SetDirty();
  662. SceneUsesDrawer.SetDirty();
  663. UsedInBuild.SetDirty();
  664. WillRepaint = true;
  665. }
  666. protected void RefreshSort()
  667. {
  668. UsedByDrawer.RefreshSort();
  669. UsesDrawer.RefreshSort();
  670. Duplicated.RefreshSort();
  671. SceneToAssetDrawer.RefreshSort();
  672. RefUnUse.RefreshSort();
  673. UsedInBuild.RefreshSort();
  674. }
  675. // public bool isExcludeByFilter;
  676. protected bool checkNoticeFilter()
  677. {
  678. var rsl = false;
  679. if (IsFocusingUsedBy && !rsl)
  680. {
  681. rsl = UsedByDrawer.isExclueAnyItem();
  682. }
  683. if (IsFocusingDuplicate)
  684. {
  685. return Duplicated.isExclueAnyItem();
  686. }
  687. if (IsFocusingUses && rsl == false)
  688. {
  689. rsl = UsesDrawer.isExclueAnyItem();
  690. }
  691. //tab use by
  692. return rsl;
  693. }
  694. protected bool checkNoticeIgnore()
  695. {
  696. bool rsl = isNoticeIgnore;
  697. return rsl;
  698. }
  699. private Dictionary<string, Object> objs;
  700. private string[] ids;
  701. private void DrawGUIDs()
  702. {
  703. GUILayout.Label("GUID to Object", EditorStyles.boldLabel);
  704. GUILayout.BeginHorizontal();
  705. {
  706. string guid = EditorGUILayout.TextField(tempGUID ?? string.Empty);
  707. EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f));
  708. if (GUILayout.Button("Paste", EditorStyles.miniButton, GUILayout.Width(70f)))
  709. {
  710. guid = EditorGUIUtility.systemCopyBuffer;
  711. }
  712. if (guid != tempGUID && !string.IsNullOrEmpty(guid))
  713. {
  714. tempGUID = guid;
  715. tempObject = FR2_Unity.LoadAssetAtPath<Object>
  716. (
  717. AssetDatabase.GUIDToAssetPath(tempGUID)
  718. );
  719. }
  720. }
  721. GUILayout.EndHorizontal();
  722. GUILayout.Space(10f);
  723. if (objs == null)// || ids == null)
  724. {
  725. return;
  726. }
  727. //GUILayout.Label("Selection", EditorStyles.boldLabel);
  728. //if (ids.Length == objs.Count)
  729. {
  730. scrollPos = GUILayout.BeginScrollView(scrollPos);
  731. {
  732. //for (var i = 0; i < ids.Length; i++)
  733. foreach (var item in objs)
  734. {
  735. //if (!objs.ContainsKey(ids[i])) continue;
  736. GUILayout.BeginHorizontal();
  737. {
  738. //var obj = objs[ids[i]];
  739. var obj = item.Value;
  740. EditorGUILayout.ObjectField(obj, typeof(Object), false, GUILayout.Width(150));
  741. string idi = item.Key;
  742. GUILayout.TextField(idi, GUILayout.Width(240f));
  743. if (GUILayout.Button("Copy", EditorStyles.miniButton, GUILayout.Width(50f)))
  744. {
  745. tempObject = obj;
  746. //EditorGUIUtility.systemCopyBuffer = tempGUID = item.Key;
  747. tempGUID = item.Key;
  748. //string guid = "";
  749. //long file = -1;
  750. //if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out guid, out file))
  751. //{
  752. // EditorGUIUtility.systemCopyBuffer = tempGUID = idi + "/" + file;
  753. // if (!string.IsNullOrEmpty(tempGUID))
  754. // {
  755. // tempObject = obj;
  756. // }
  757. //}
  758. }
  759. }
  760. GUILayout.EndHorizontal();
  761. }
  762. }
  763. GUILayout.EndScrollView();
  764. }
  765. GUILayout.BeginHorizontal();
  766. if (GUILayout.Button("Merge Selection To"))
  767. {
  768. FR2_Export.MergeDuplicate(tempGUID);
  769. }
  770. EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f));
  771. GUILayout.EndHorizontal();
  772. GUILayout.FlexibleSpace();
  773. }
  774. }
  775. }