InternalEditorBridge.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Reflection;
  3. using UnityEditor.ShortcutManagement;
  4. using UnityEditor.U2D.Sprites;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. namespace UnityEditor.U2D.Common
  8. {
  9. internal static class InternalEditorBridge
  10. {
  11. public static void RenderSortingLayerFields(SerializedProperty order, SerializedProperty layer)
  12. {
  13. SortingLayerEditorUtility.RenderSortingLayerFields(order, layer);
  14. }
  15. public static void RepaintImmediately(EditorWindow window)
  16. {
  17. window.RepaintImmediately();
  18. }
  19. public static ISpriteEditorDataProvider GetISpriteEditorDataProviderFromPath(string importedAsset)
  20. {
  21. return AssetImporter.GetAtPath(importedAsset) as ISpriteEditorDataProvider;
  22. }
  23. public static void GenerateOutline(Texture2D texture, Rect rect, float detail, byte alphaTolerance, bool holeDetection, out Vector2[][] paths)
  24. {
  25. UnityEditor.Sprites.SpriteUtility.GenerateOutline(texture, rect, detail, alphaTolerance, holeDetection, out paths);
  26. }
  27. public static bool DoesHardwareSupportsFullNPOT()
  28. {
  29. return ShaderUtil.hardwareSupportsFullNPOT;
  30. }
  31. public static Texture2D CreateTemporaryDuplicate(Texture2D tex, int width, int height)
  32. {
  33. return UnityEditor.SpriteUtility.CreateTemporaryDuplicate(tex, width, height);
  34. }
  35. public static void ShowSpriteEditorWindow(UnityEngine.Object obj = null)
  36. {
  37. SpriteUtilityWindow.ShowSpriteEditorWindow(obj);
  38. }
  39. public static void ApplyWireMaterial()
  40. {
  41. HandleUtility.ApplyWireMaterial();
  42. }
  43. public static void ResetSpriteEditorView(ISpriteEditor spriteEditor)
  44. {
  45. if (spriteEditor != null)
  46. {
  47. Type t = spriteEditor.GetType();
  48. var zoom = t.GetField("m_Zoom", BindingFlags.Instance | BindingFlags.NonPublic);
  49. if (zoom != null)
  50. {
  51. zoom.SetValue(spriteEditor, -1);
  52. }
  53. var scrollPosition = t.GetField("m_ScrollPosition", BindingFlags.Instance | BindingFlags.NonPublic);
  54. if (scrollPosition != null)
  55. {
  56. scrollPosition.SetValue(spriteEditor, new Vector2());
  57. }
  58. }
  59. }
  60. public class ShortcutContext : IShortcutToolContext
  61. {
  62. public Func<bool> isActive;
  63. public bool active
  64. {
  65. get
  66. {
  67. if (isActive != null)
  68. return isActive();
  69. return true;
  70. }
  71. }
  72. public object context { get; set; }
  73. }
  74. public static void RegisterShortcutContext(ShortcutContext context)
  75. {
  76. ShortcutIntegration.instance.contextManager.RegisterToolContext(context);
  77. }
  78. public static void UnregisterShortcutContext(ShortcutContext context)
  79. {
  80. ShortcutIntegration.instance.contextManager.DeregisterToolContext(context);
  81. }
  82. public static void AddEditorApplicationProjectLoadedCallback(UnityAction callback)
  83. {
  84. EditorApplication.projectWasLoaded += callback;
  85. }
  86. public static void RemoveEditorApplicationProjectLoadedCallback(UnityAction callback)
  87. {
  88. EditorApplication.projectWasLoaded -= callback;
  89. }
  90. public static string GetProjectWindowActiveFolderPath()
  91. {
  92. return ProjectWindowUtil.GetActiveFolderPath();
  93. }
  94. public static GUIContent GetIconContent<T>() where T : UnityEngine.Object
  95. {
  96. return EditorGUIUtility.IconContent<T>();
  97. }
  98. public static int GetAssetCreationInstanceID_ForNonExistingAssets()
  99. {
  100. return ProjectBrowser.kAssetCreationInstanceID_ForNonExistingAssets;
  101. }
  102. }
  103. }