ResourceSyncTools.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using UnityEditor;
  9. using UnityEngine;
  10. namespace UnityGameFramework.Editor.ResourceTools
  11. {
  12. /// <summary>
  13. /// 资源同步工具。
  14. /// </summary>
  15. internal sealed class ResourceSyncTools : EditorWindow
  16. {
  17. private const float ButtonHeight = 60f;
  18. private const float ButtonSpace = 5f;
  19. private ResourceSyncToolsController m_Controller = null;
  20. [MenuItem("Game Framework/Resource Tools/Resource Sync Tools", false, 44)]
  21. private static void Open()
  22. {
  23. ResourceSyncTools window = GetWindow<ResourceSyncTools>("Resource Sync Tools", true);
  24. #if UNITY_2019_3_OR_NEWER
  25. window.minSize = new Vector2(400, 195f);
  26. #else
  27. window.minSize = new Vector2(400, 205f);
  28. #endif
  29. }
  30. private void OnEnable()
  31. {
  32. m_Controller = new ResourceSyncToolsController();
  33. m_Controller.OnLoadingResource += OnLoadingResource;
  34. m_Controller.OnLoadingAsset += OnLoadingAsset;
  35. m_Controller.OnCompleted += OnCompleted;
  36. m_Controller.OnResourceDataChanged += OnResourceDataChanged;
  37. }
  38. private void OnGUI()
  39. {
  40. EditorGUILayout.BeginVertical(GUILayout.Width(position.width), GUILayout.Height(position.height));
  41. {
  42. GUILayout.Space(ButtonSpace);
  43. if (GUILayout.Button("Remove All Asset Bundle Names in Project", GUILayout.Height(ButtonHeight)))
  44. {
  45. if (!m_Controller.RemoveAllAssetBundleNames())
  46. {
  47. Debug.LogWarning("Remove All Asset Bundle Names in Project failure.");
  48. }
  49. else
  50. {
  51. Debug.Log("Remove All Asset Bundle Names in Project completed.");
  52. }
  53. AssetDatabase.Refresh();
  54. }
  55. GUILayout.Space(ButtonSpace);
  56. if (GUILayout.Button("Sync ResourceCollection.xml to Project", GUILayout.Height(ButtonHeight)))
  57. {
  58. if (!m_Controller.SyncToProject())
  59. {
  60. Debug.LogWarning("Sync ResourceCollection.xml to Project failure.");
  61. }
  62. else
  63. {
  64. Debug.Log("Sync ResourceCollection.xml to Project completed.");
  65. }
  66. AssetDatabase.Refresh();
  67. }
  68. GUILayout.Space(ButtonSpace);
  69. if (GUILayout.Button("Sync ResourceCollection.xml from Project", GUILayout.Height(ButtonHeight)))
  70. {
  71. if (!m_Controller.SyncFromProject())
  72. {
  73. Debug.LogWarning("Sync Project to ResourceCollection.xml failure.");
  74. }
  75. else
  76. {
  77. Debug.Log("Sync Project to ResourceCollection.xml completed.");
  78. }
  79. AssetDatabase.Refresh();
  80. }
  81. }
  82. EditorGUILayout.EndVertical();
  83. }
  84. private void OnLoadingResource(int index, int count)
  85. {
  86. EditorUtility.DisplayProgressBar("Loading Resources", Utility.Text.Format("Loading resources, {0}/{1} loaded.", index.ToString(), count.ToString()), (float)index / count);
  87. }
  88. private void OnLoadingAsset(int index, int count)
  89. {
  90. EditorUtility.DisplayProgressBar("Loading Assets", Utility.Text.Format("Loading assets, {0}/{1} loaded.", index.ToString(), count.ToString()), (float)index / count);
  91. }
  92. private void OnCompleted()
  93. {
  94. EditorUtility.ClearProgressBar();
  95. }
  96. private void OnResourceDataChanged(int index, int count, string assetName)
  97. {
  98. EditorUtility.DisplayProgressBar("Processing Assets", Utility.Text.Format("({0}/{1}) {2}", index.ToString(), count.ToString(), assetName), (float)index / count);
  99. }
  100. }
  101. }