UGUISelectSpriteAtlasWindow.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEditor.UI;
  5. using UnityEngine;
  6. using UnityEngine.U2D;
  7. using UnityEngine.UI.PackgTool;
  8. namespace UnityEditor.UI
  9. {
  10. public class UGUISelectSpriteAtlasWindow : EditorWindow
  11. {
  12. private static System.Action<SpriteAtlas, Sprite> callBack;
  13. private static string jsonPackPath;
  14. private static string spriteAtlasPath = "/Res/UIAtlas";
  15. float mClickTime = 0f;
  16. private static List<SpriteAtlas> currSelectSpriteAtlas = new List<SpriteAtlas>();
  17. private static Sprite currSelectSprite;
  18. private static PackInfo packInfo;
  19. public static void OpenWidow(PackInfo packInfo, Sprite sprite, List<SpriteAtlas> currSelectSpriteAtlas, System.Action<SpriteAtlas, Sprite> callBack)
  20. {
  21. UGUISelectSpriteAtlasWindow.packInfo = packInfo;
  22. UGUISelectSpriteAtlasWindow.currSelectSpriteAtlas = currSelectSpriteAtlas;
  23. currSelectSprite = sprite;
  24. jsonPackPath = packInfo.packgJsonPath;
  25. UGUISelectSpriteAtlasWindow.callBack = callBack;
  26. UGUISelectSpriteAtlasWindow window = EditorWindow.GetWindow<UGUISelectSpriteAtlasWindow>();
  27. window.name = "选择一个一个当前图片";
  28. window.Show();
  29. }
  30. Vector2 pos = Vector2.zero;
  31. private void GUISpriteAtlas()
  32. {
  33. if (currSelectSprite != null)
  34. {
  35. GUI.DrawTexture(new Rect(EditorGUIUtility.currentViewWidth / 2 - 64, 0, 128, 128), currSelectSprite.texture);
  36. }
  37. GUILayout.Space(150);
  38. GUILayout.Label($"请选择{currSelectSprite.name}需要使用的图集");
  39. pos = GUILayout.BeginScrollView(pos);
  40. if (currSelectSpriteAtlas != null)
  41. {
  42. for (int i = 0; i < currSelectSpriteAtlas.Count; i++)
  43. {
  44. if (GUILayout.Button(currSelectSpriteAtlas[i].name))
  45. {
  46. GUILayout.EndScrollView();
  47. callBack?.Invoke(currSelectSpriteAtlas[i], currSelectSprite);
  48. Close();
  49. return;
  50. }
  51. }
  52. }
  53. GUILayout.EndScrollView();
  54. }
  55. void OnGUI()
  56. {
  57. GUISpriteAtlas();
  58. }
  59. }
  60. }