Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InternalEditorBridge.cs 4.7KB

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