2using System.Collections.Generic;
3using System.Diagnostics;
6using System.Reflection;
12 public static class UnityFeatureHelper
14 private static readonly Type _sceneManager = Type.GetType(
"UnityEngine.SceneManagement.SceneManager, UnityEngine",
false);
15 private static readonly Type _scene = Type.GetType(
"UnityEngine.SceneManagement.Scene, UnityEngine",
false);
16 private static readonly Type _vectrosity = Type.GetType(
"Vectrosity.VectorObject2D, Vectrosity",
false);
18 static UnityFeatureHelper()
20 SupportsScenes = _scene !=
null && _sceneManager !=
null;
22 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Warning,
"UnityEngine.SceneManager and/or UnityEngine.SceneManagement.Scene are not available, some features will be disabled");
25 SupportsCursorIndex = SupportsScenes;
26 if (!SupportsCursorIndex)
27 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Warning,
"TextEditor.cursorIndex is not available, some features will be disabled");
29 SupportsVectrosity = _vectrosity !=
null;
30 if (!SupportsVectrosity)
31 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Warning,
"Vectrosity.dll is not available, drawing gizmos will be disabled");
34 public static bool SupportsScenes {
get;
private set; }
35 public static bool SupportsCursorIndex {
get;
private set; }
36 public static bool SupportsVectrosity {
get;
private set; }
38 public static IEnumerable<GameObject> GetSceneGameObjects()
42 return GetSceneGameObjectsInternal();
46 SupportsScenes =
false;
47 return Enumerable.Empty<GameObject>();
51 public static GameObject[] GetSceneGameObjectsInternal()
53 return SceneManager.GetActiveScene().GetRootGameObjects();
56 public static void OpenLog()
59 if (TryOpen(Path.Combine(Application.dataPath,
"output_log.txt")))
return;
62 if (TryOpen(Path.Combine(Path.GetDirectoryName(Application.dataPath) ??
"",
"output_log.txt")))
return;
65 var prop = typeof(Application).GetProperty(
"consoleLogPath", BindingFlags.Static | BindingFlags.Public);
68 var path = prop.GetValue(
null,
null) as string;
69 if (TryOpen(path))
return;
72 if (
Directory.Exists(Application.persistentDataPath))
74 var file =
Directory.GetFiles(Application.persistentDataPath,
"output_log.txt", SearchOption.AllDirectories).FirstOrDefault();
75 if (TryOpen(file))
return;
79 var rootDir =
Directory.GetParent(Application.dataPath);
83 var result = rootDir.GetFiles(
"LogOutput.log", SearchOption.AllDirectories).FirstOrDefault();
85 result = rootDir.GetFiles(
"output_log.txt", SearchOption.AllDirectories).FirstOrDefault();
87 if (result !=
null && TryOpen(result.FullName))
return;
90 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Message |
LogLevel.Error,
"No log files were found");
93 private static bool TryOpen(
string path)
95 if (!
File.Exists(path))
return false;
107 public static Texture2D LoadTexture(
byte[] texData)
109 var tex =
new Texture2D(1, 1, TextureFormat.ARGB32,
false);
112 var loadMethod = typeof(Texture2D).GetMethod(
"LoadImage",
new[] { typeof(
byte[]) });
113 if (loadMethod !=
null)
115 loadMethod.Invoke(tex,
new object[] { texData });
119 var converter = Type.GetType(
"UnityEngine.ImageConversion, UnityEngine.ImageConversionModule");
120 if (converter ==
null)
throw new ArgumentNullException();
121 var converterMethod = converter.GetMethod(
"LoadImage",
new[] { typeof(Texture2D), typeof(
byte[]) });
122 if (converterMethod ==
null)
throw new ArgumentNullException();
123 converterMethod.Invoke(
null,
new object[] { tex, texData });
RuntimeUnityEditor.Core.LogLevel LogLevel