static UnityLogEntries() { // TODO Unity <5.6 backward compatibility? Type logEntriesType = typeof(InternalEditorUtility).Assembly.GetType("UnityEditorInternal.LogEntries") ?? UnityAssemblyVerifier.TryGetType(typeof(Editor).Assembly, "UnityEditor.LogEntries"); if (logEntriesType != null) { PropertyInfo consoleFlagsProperty = UnityAssemblyVerifier.TryGetProperty(logEntriesType, "consoleFlags", BindingFlags.Static | BindingFlags.Public); if (consoleFlagsProperty != null) { UnityLogEntries.SetConsoleFlags = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), null, consoleFlagsProperty.GetSetMethod()); UnityLogEntries.GetConsoleFlags = (Func <int>)Delegate.CreateDelegate(typeof(Func <int>), null, consoleFlagsProperty.GetGetMethod()); } UnityLogEntries.StartGettingEntries = (Func <int>)Delegate.CreateDelegate(typeof(Func <int>), null, UnityAssemblyVerifier.TryGetMethod(logEntriesType, "StartGettingEntries", BindingFlags.Static | BindingFlags.Public)); UnityLogEntries.SetConsoleFlag = (Action <int, bool>)Delegate.CreateDelegate(typeof(Action <int, bool>), null, UnityAssemblyVerifier.TryGetMethod(logEntriesType, "SetConsoleFlag", BindingFlags.Static | BindingFlags.Public)); UnityLogEntries.EndGettingEntries = (Action)Delegate.CreateDelegate(typeof(Action), null, UnityAssemblyVerifier.TryGetMethod(logEntriesType, "EndGettingEntries", BindingFlags.Static | BindingFlags.Public)); UnityLogEntries.GetCount = (Func <int>)Delegate.CreateDelegate(typeof(Func <int>), null, UnityAssemblyVerifier.TryGetMethod(logEntriesType, "GetCount", BindingFlags.Static | BindingFlags.Public)); Type logEntryType = typeof(InternalEditorUtility).Assembly.GetType("UnityEditorInternal.LogEntry") ?? UnityAssemblyVerifier.TryGetType(typeof(Editor).Assembly, "UnityEditor.LogEntry"); Type delegateType = Type.GetType("System.Func`3[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[" + logEntryType.AssemblyQualifiedName + "],[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); MethodInfo GetEntryInternal = UnityAssemblyVerifier.TryGetMethod(logEntriesType, "GetEntryInternal", BindingFlags.Static | BindingFlags.Public); UnityLogEntries.GetEntryInternalMethod = Delegate.CreateDelegate(delegateType, null, GetEntryInternal); UnityLogEntries.GetEntryCount = (Func <int, int>)Delegate.CreateDelegate(typeof(Func <int, int>), null, UnityAssemblyVerifier.TryGetMethod(logEntriesType, "GetEntryCount", BindingFlags.Static | BindingFlags.Public)); UnityLogEntries.Clear = (Action)Delegate.CreateDelegate(typeof(Action), null, UnityAssemblyVerifier.TryGetMethod(logEntriesType, "Clear", BindingFlags.Static | BindingFlags.Public)); } }
static NGConsoleWindow() { NGConsoleWindow.nativeConsoleType = UnityAssemblyVerifier.TryGetType(typeof(EditorWindow).Assembly, "UnityEditor.ConsoleWindow"); if (NGConsoleWindow.nativeConsoleType != null) { NGConsoleWindow.nativeConsoleWindowField = UnityAssemblyVerifier.TryGetField(NGConsoleWindow.nativeConsoleType, "ms_ConsoleWindow", BindingFlags.NonPublic | BindingFlags.Static); if (NGConsoleWindow.nativeConsoleWindowField != null) { EditorApplication.update += NGConsoleWindow.AutoReplaceNativeConsole; } } }
static NGHierarchyEnhancer() { HQ.SettingsChanged += NGHierarchyEnhancer.Preferences_SettingsChanged; NGHierarchyEnhancer.hierarchyType = UnityAssemblyVerifier.TryGetType(typeof(EditorWindow).Assembly, "UnityEditor.SceneHierarchyWindow"); string[] names = Enum.GetNames(typeof(EventModifiers)); NGHierarchyEnhancer.eventModifierNames = new string[names.Length - 1]; for (int i = 1; i < names.Length; i++) { NGHierarchyEnhancer.eventModifierNames[i - 1] = names[i]; } }
public UnityLogEntry() { // TODO Unity <5.6 backward compatibility? Type logEntryType = typeof(InternalEditorUtility).Assembly.GetType("UnityEditorInternal.LogEntry") ?? UnityAssemblyVerifier.TryGetType(typeof(Editor).Assembly, "UnityEditor.LogEntry"); if (logEntryType != null) { this.instance = Activator.CreateInstance(logEntryType); this.conditionField = UnityAssemblyVerifier.TryGetField(logEntryType, "condition", BindingFlags.Instance | BindingFlags.Public); this.errorNumField = UnityAssemblyVerifier.TryGetField(logEntryType, "errorNum", BindingFlags.Instance | BindingFlags.Public); this.fileField = UnityAssemblyVerifier.TryGetField(logEntryType, "file", BindingFlags.Instance | BindingFlags.Public); this.lineField = UnityAssemblyVerifier.TryGetField(logEntryType, "line", BindingFlags.Instance | BindingFlags.Public); this.modeField = UnityAssemblyVerifier.TryGetField(logEntryType, "mode", BindingFlags.Instance | BindingFlags.Public); this.instanceIDField = UnityAssemblyVerifier.TryGetField(logEntryType, "instanceID", BindingFlags.Instance | BindingFlags.Public); this.identifierField = UnityAssemblyVerifier.TryGetField(logEntryType, "identifier", BindingFlags.Instance | BindingFlags.Public); this.isWorldPlayingField = UnityAssemblyVerifier.TryGetField(logEntryType, "isWorldPlaying", BindingFlags.Instance | BindingFlags.Public); } }
static ConsoleUtility() { if (ConsoleUtility.ContainerWindow != null) { ConsoleUtility.windows = UnityAssemblyVerifier.TryGetProperty(ConsoleUtility.ContainerWindow, "windows", BindingFlags.Static | BindingFlags.Public); // After 5.5, they renamed mainView by rootView. ConsoleUtility.mainView = ConsoleUtility.ContainerWindow.GetProperty("mainView", BindingFlags.Instance | BindingFlags.Public) ?? UnityAssemblyVerifier.TryGetProperty(ConsoleUtility.ContainerWindow, "rootView", BindingFlags.Instance | BindingFlags.Public); } if (ConsoleUtility.View != null) { ConsoleUtility.allChildren = UnityAssemblyVerifier.TryGetProperty(ConsoleUtility.View, "allChildren", BindingFlags.Instance | BindingFlags.Public); } if (ConsoleUtility.DockArea != null) { ConsoleUtility.m_Panes = UnityAssemblyVerifier.TryGetField(ConsoleUtility.DockArea, "m_Panes", BindingFlags.Instance | BindingFlags.NonPublic); ConsoleUtility.AddTab = ConsoleUtility.DockArea.GetMethod("AddTab", new Type[] { typeof(EditorWindow) }) ?? UnityAssemblyVerifier.TryGetMethod(ConsoleUtility.DockArea, "AddTab", new Type[] { typeof(EditorWindow), typeof(Boolean) }); } }
static UnityEventBaseFinder() { Type type = UnityAssemblyVerifier.TryGetType(typeof(UnityEventBase).Assembly, "UnityEngine.Events.PersistentCallGroup"); if (type != null) { UnityEventBaseFinder.PersistentCallGroup = UnityAssemblyVerifier.TryGetField(type, "m_Calls", BindingFlags.NonPublic | BindingFlags.Instance); } type = UnityAssemblyVerifier.TryGetType(typeof(UnityEventBase).Assembly, "UnityEngine.Events.PersistentCall"); if (type != null) { UnityEventBaseFinder.PersistentCall = UnityAssemblyVerifier.TryGetField(type, "m_Target", BindingFlags.NonPublic | BindingFlags.Instance); } if (UnityEventBaseFinder.PersistentCallGroup == null || UnityEventBaseFinder.PersistentCall == null) { UnityEventBaseFinder.m_persistantCalls = null; } }
static DragObjectDrawer() { if (DragObjectDrawer.ScriptAttributeUtility != null) { DragObjectDrawer.s_DrawerTypeForType = UnityAssemblyVerifier.TryGetField(DragObjectDrawer.ScriptAttributeUtility, "s_DrawerTypeForType", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); DragObjectDrawer.BuildDrawerTypeForTypeDictionary = UnityAssemblyVerifier.TryGetMethod(DragObjectDrawer.ScriptAttributeUtility, "BuildDrawerTypeForTypeDictionary", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); DragObjectDrawer.DrawerKeySet = UnityAssemblyVerifier.TryGetNestedType(DragObjectDrawer.ScriptAttributeUtility, "DrawerKeySet", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (DragObjectDrawer.DrawerKeySet != null) { DragObjectDrawer.drawer = UnityAssemblyVerifier.TryGetField(DragObjectDrawer.DrawerKeySet, "drawer", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); DragObjectDrawer.type = UnityAssemblyVerifier.TryGetField(DragObjectDrawer.DrawerKeySet, "type", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); } if (DragObjectDrawer.s_DrawerTypeForType == null || DragObjectDrawer.BuildDrawerTypeForTypeDictionary == null || DragObjectDrawer.DrawerKeySet == null || DragObjectDrawer.drawer == null || DragObjectDrawer.type == null) { DragObjectDrawer.ScriptAttributeUtility = null; } } HQ.SettingsChanged += () => { if (HQ.Settings == null) { return; } if (HQ.Settings.Get <DraggableObjectSettings>().active == true) { DragObjectDrawer.AddType(); } else { DragObjectDrawer.RemoveType(); } }; }
static ScenesImporter() { EditorSceneManager.sceneLoaded += ScenesImporter.OnSceneLoaded; EditorSceneManager.sceneUnloaded += ScenesImporter.OnSceneUnloaded; EditorSceneManager.newSceneCreated += ScenesImporter.OnNewSceneCreated; EditorSceneManager.sceneOpened += ScenesImporter.OnSceneOpened; EditorSceneManager.sceneClosed += ScenesImporter.OnSceneClosed; // TODO Unity <5.6 backward compatibility? MethodInfo OnActiveSceneChangedInEditModeMethod = typeof(ScenesImporter).GetMethod("OnActiveSceneChangedInEditMode", BindingFlags.Static | BindingFlags.NonPublic); try { EventInfo activeSceneChangedInEditModeEvent = typeof(EditorSceneManager).GetEvent("activeSceneChangedInEditMode"); activeSceneChangedInEditModeEvent.AddEventHandler(null, Delegate.CreateDelegate(activeSceneChangedInEditModeEvent.EventHandlerType, null, OnActiveSceneChangedInEditModeMethod)); //EditorSceneManager.activeSceneChangedInEditMode += ScenesImporter.OnActiveSceneChangedInEditMode; } catch { } // TODO Unity <5.6 backward compatibility? MethodInfo OnHierarchyChangedMethod = typeof(ScenesImporter).GetMethod("OnHierarchyChanged", BindingFlags.Static | BindingFlags.NonPublic); try { EventInfo hierarchyChangedEvent = typeof(EditorApplication).GetEvent("hierarchyChanged"); hierarchyChangedEvent.AddEventHandler(null, Delegate.CreateDelegate(hierarchyChangedEvent.EventHandlerType, null, OnHierarchyChangedMethod)); //EditorApplication.hierarchyChanged += ScenesImporter.OnHierarchyChanged; } catch { FieldInfo hierarchyWindowChangedField = UnityAssemblyVerifier.TryGetField(typeof(EditorApplication), "hierarchyWindowChanged", BindingFlags.Static | BindingFlags.Public); if (hierarchyWindowChangedField != null) { hierarchyWindowChangedField.SetValue(null, Delegate.Combine((Delegate)hierarchyWindowChangedField.GetValue(null), Delegate.CreateDelegate(hierarchyWindowChangedField.FieldType, null, OnHierarchyChangedMethod))); } //EditorApplication.hierarchyWindowChanged += ScenesImporter.OnHierarchyChanged; } }
static NGScenesWindow() { NGEditorApplication.ChangeScene += NGScenesWindow.UpdateLastScenes; // Force update allScenes at next restart. // TODO Unity <5.6 backward compatibility? MethodInfo ResetAllScenesMethod = typeof(NGScenesWindow).GetMethod("ResetAllScenes", BindingFlags.Static | BindingFlags.NonPublic); try { EventInfo projectChangedEvent = typeof(EditorApplication).GetEvent("projectChanged"); projectChangedEvent.AddEventHandler(null, Delegate.CreateDelegate(projectChangedEvent.EventHandlerType, null, ResetAllScenesMethod)); //EditorApplication.projectChanged += NGScenesWindow.ResetAllScenes; } catch { FieldInfo projectWindowChangedField = UnityAssemblyVerifier.TryGetField(typeof(EditorApplication), "projectWindowChanged", BindingFlags.Static | BindingFlags.Public); if (projectWindowChangedField != null) { projectWindowChangedField.SetValue(null, Delegate.Combine((Delegate)projectWindowChangedField.GetValue(null), Delegate.CreateDelegate(projectWindowChangedField.FieldType, null, ResetAllScenesMethod))); } //EditorApplication.projectWindowChanged += NGScenesWindow.ResetAllScenes; } }