A game about forced loneliness, made by TACStudios
1using System;
2using System.Reflection;
3using UnityEditor.ShortcutManagement;
4using UnityEditor.U2D.Sprites;
5using UnityEngine;
6using UnityEngine.Events;
7using UnityEngine.UIElements;
8
9namespace UnityEditor.U2D.Common
10{
11 internal static class InternalEditorBridge
12 {
13 public static void RenderSortingLayerFields(SerializedProperty order, SerializedProperty layer)
14 {
15 SortingLayerEditorUtility.RenderSortingLayerFields(order, layer);
16 }
17
18 public static void RepaintImmediately(EditorWindow window)
19 {
20 window.RepaintImmediately();
21 }
22
23 public static ISpriteEditorDataProvider GetISpriteEditorDataProviderFromPath(string importedAsset)
24 {
25 return AssetImporter.GetAtPath(importedAsset) as ISpriteEditorDataProvider;
26 }
27
28 public static void GenerateOutline(Texture2D texture, Rect rect, float detail, byte alphaTolerance, bool holeDetection, out Vector2[][] paths)
29 {
30 UnityEditor.Sprites.SpriteUtility.GenerateOutline(texture, rect, detail, alphaTolerance, holeDetection, out paths);
31 }
32
33 public static void GenerateOutlineFromSprite(Sprite sprite, float detail, byte alphaTolerance, bool holeDetection, out Vector2[][] paths)
34 {
35 UnityEditor.Sprites.SpriteUtility.GenerateOutlineFromSprite(sprite, detail, alphaTolerance, holeDetection, out paths);
36 }
37
38 public static bool DoesHardwareSupportsFullNPOT()
39 {
40 return ShaderUtil.hardwareSupportsFullNPOT;
41 }
42
43 public static Texture2D CreateTemporaryDuplicate(Texture2D tex, int width, int height)
44 {
45 return UnityEditor.SpriteUtility.CreateTemporaryDuplicate(tex, width, height);
46 }
47
48 public static void ShowSpriteEditorWindow(UnityEngine.Object obj = null)
49 {
50 SpriteUtilityWindow.ShowSpriteEditorWindow(obj);
51 }
52
53 public static void ApplySpriteEditorWindow()
54 {
55 SpriteUtilityWindow.ApplySpriteEditorWindow();
56 }
57
58 public static void ApplyWireMaterial()
59 {
60 HandleUtility.ApplyWireMaterial();
61 }
62
63 public static void ResetSpriteEditorView(ISpriteEditor spriteEditor)
64 {
65 if (spriteEditor != null)
66 {
67 Type t = spriteEditor.GetType();
68 var zoom = t.GetField("m_Zoom", BindingFlags.Instance | BindingFlags.NonPublic);
69 if (zoom != null)
70 {
71 zoom.SetValue(spriteEditor, -1);
72 }
73
74 var scrollPosition = t.GetField("m_ScrollPosition", BindingFlags.Instance | BindingFlags.NonPublic);
75 if (scrollPosition != null)
76 {
77 scrollPosition.SetValue(spriteEditor, new Vector2());
78 }
79 }
80 }
81
82#if UNITY_2023_3_OR_NEWER
83 public class ShortcutContext : IShortcutContext
84#else
85 public class ShortcutContext : IShortcutToolContext
86#endif
87 {
88 public Func<bool> isActive;
89 public bool active
90 {
91 get
92 {
93 if (isActive != null)
94 return isActive();
95 return true;
96 }
97 }
98 public object context { get; set; }
99 }
100
101 public static void RegisterShortcutContext(ShortcutContext context)
102 {
103 ShortcutIntegration.instance.contextManager.RegisterToolContext(context);
104 }
105
106 public static void UnregisterShortcutContext(ShortcutContext context)
107 {
108 ShortcutIntegration.instance.contextManager.DeregisterToolContext(context);
109 }
110
111 public static void AddEditorApplicationProjectLoadedCallback(UnityAction callback)
112 {
113 EditorApplication.projectWasLoaded += callback;
114 }
115
116 public static void RemoveEditorApplicationProjectLoadedCallback(UnityAction callback)
117 {
118 EditorApplication.projectWasLoaded -= callback;
119 }
120
121 public static string GetProjectWindowActiveFolderPath()
122 {
123 return ProjectWindowUtil.GetActiveFolderPath();
124 }
125
126 public static GUIContent GetIconContent<T>() where T : UnityEngine.Object
127 {
128 return EditorGUIUtility.IconContent<T>();
129 }
130
131 public static int GetAssetCreationInstanceID_ForNonExistingAssets()
132 {
133 return ProjectBrowser.kAssetCreationInstanceID_ForNonExistingAssets;
134 }
135
136 public static VisualElement SceneViewCameraViewVisualElement(SceneView sc)
137 {
138 return sc.cameraViewVisualElement;
139 }
140
141 public static Vector2 GetOverlaySize(UnityEditor.Overlays.Overlay o)
142 {
143 return o.rootVisualElement.layout.size;
144 }
145
146 public static Rect GetEditorGUILayoutLastRect()
147 {
148 return EditorGUILayout.s_LastRect;
149 }
150
151 public static string TextureImporterDefaultPlatformName()
152 {
153 return TextureImporter.defaultPlatformName;
154 }
155
156 public static bool IsAnimated(UnityEngine.Object obj, SerializedProperty property)
157 {
158 return AnimationMode.IsPropertyAnimated(obj, property.propertyPath);
159 }
160
161 public static bool IsCandidate(UnityEngine.Object obj, SerializedProperty property)
162 {
163 return AnimationMode.IsPropertyCandidate(obj, property.propertyPath);
164 }
165
166 public static bool InAnimationRecording()
167 {
168 return AnimationMode.InAnimationRecording();
169 }
170
171 public static bool InAnimationPlaybackMode()
172 {
173 return AnimationMode.InAnimationPlaybackMode();
174 }
175
176 internal class EditorLockTracker : EditorGUIUtility.EditorLockTracker
177 {
178 public bool ShowButtonAtRect(Rect position, GUIStyle lockButtonStyle, bool disabled = false)
179 {
180 return ShowButton(position, lockButtonStyle, disabled);
181 }
182
183 public bool IsLocked() => isLocked;
184 }
185
186 public static void SetAssetPreviewTextureCacheSize(int cacheSize, int clientId)
187 {
188 AssetPreview.SetPreviewTextureCacheSize(cacheSize, clientId);
189 }
190
191 public static Texture2D GetAssetPreview(int assetId, int clientId)
192 {
193 return AssetPreview.GetAssetPreview(assetId, clientId);
194 }
195
196 public static bool IsLoadingAssetPreview(int assetId, int clientId)
197 {
198 return AssetPreview.IsLoadingAssetPreview(assetId, clientId);
199 }
200
201 public static void ClearAssetPreviews(int clientId)
202 {
203 AssetPreview.DeletePreviewTextureManagerByID(clientId);
204 }
205 }
206
207#if ENABLE_SPRITEMODULE_MODE
208 [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
209 internal class SpriteFrameModuleModeAttribute : SpriteEditorModuleModeAttribute
210 {
211 public SpriteFrameModuleModeAttribute(bool showAsModule = false):base(showAsModule, typeof(SpriteFrameModule)) {}
212 }
213#endif
214}