UGUIIamgeTool.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. #if UNITY_EDITOR
  5. using UnityEngine;
  6. #endif
  7. namespace UnityEngine.UI
  8. {
  9. public class UGUIIamgeTool
  10. {
  11. public static ISpriteLoad SpriteLoad;
  12. public static int minDepth =-1;
  13. public static int renderOrder =0;
  14. public static void Load(string assetName, Action<UILoadSpriteHand> callBack)
  15. {
  16. if (!Application.isPlaying)
  17. {
  18. #if UNITY_EDITOR
  19. string[] assetsPath = AssetDatabase.FindAssets(assetName);
  20. for (int j = 0; j < assetsPath.Length; j++)
  21. {
  22. string assetPath = AssetDatabase.GUIDToAssetPath(assetsPath[j]);
  23. if (assetPath.Contains(".png"))
  24. {
  25. Sprite texture = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
  26. EditoUILoadSpriteHand editoUILoadSpriteHand = new EditoUILoadSpriteHand();
  27. editoUILoadSpriteHand.Sprite = texture;
  28. callBack?.Invoke(editoUILoadSpriteHand);
  29. }
  30. }
  31. #endif
  32. }
  33. else
  34. {
  35. if (SpriteLoad != null)
  36. {
  37. SpriteLoad.Load(assetName, callBack);
  38. }
  39. else
  40. {
  41. Debug.LogError("没有找到Load的工具" + assetName);
  42. }
  43. }
  44. }
  45. }
  46. }