Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        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) });
            }
        }