static BackgroundTaskRunner() { try { AsyncProgressBarType = typeof(EditorWindow).Assembly.GetType("UnityEditor.AsyncProgressBar", true); AsyncProgressBar_Display = AsyncProgressBarType.GetMethod("Display", BindingFlags.Static | BindingFlags.Public); AsyncProgressBar_Clear = AsyncProgressBarType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public); if (AsyncProgressBar_Display == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Display"); } if (AsyncProgressBar_Clear == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Clear"); } } catch (Exception ex) { throw new UnityEditorInternalException(ex); } Clear(); EditorApplication.update += Display; }
static BackgroundWorker() { try { AsyncProgressBarType = typeof(EditorWindow).Assembly.GetType("UnityEditor.AsyncProgressBar", true); AsyncProgressBar_Display = AsyncProgressBarType.GetMethod("Display", BindingFlags.Static | BindingFlags.Public); AsyncProgressBar_Clear = AsyncProgressBarType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public); if (AsyncProgressBar_Display == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Display"); } if (AsyncProgressBar_Clear == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Clear"); } } catch (Exception ex) { throw new UnityEditorInternalException(ex); } queue = new Queue <Action>(); ClearProgress(); foreach (var registration in Codebase.GetTypeRegistrations <RegisterBackgroundWorkerAttribute>()) { var backgroundWorkMethod = registration.type.GetMethod(registration.methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (backgroundWorkMethod != null) { tasks += () => backgroundWorkMethod.Invoke(null, new object[0]); } else { Debug.LogWarningFormat($"Missing '{registration.methodName}' method for '{registration.type}' background worker."); } } EditorApplication.update += DisplayProgress; EditorApplication.delayCall += delegate { new Thread(Work) { Name = "Background Worker" }.Start(); }; }
static BackgroundWorker() { if (useProgressApi) { try { ProgressType = typeof(EditorWindow).Assembly.GetType(("UnityEditor.Progress"), true); Progress_OptionsType = ProgressType.GetNestedType("Options"); Progress_Start = ProgressType.GetMethod("Start", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string), typeof(string), Progress_OptionsType, typeof(int) }, null); Progress_Report = ProgressType.GetMethod("Report", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(int), typeof(float), typeof(string) }, null); Progress_Remove = ProgressType.GetMethod("Remove", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(int) }, null); if (Progress_Start == null) { throw new MissingMemberException(ProgressType.FullName, "Start"); } if (Progress_Report == null) { throw new MissingMemberException(ProgressType.FullName, "Report"); } if (Progress_Remove == null) { throw new MissingMemberException(ProgressType.FullName, "Remove"); } } catch (Exception ex) { throw new UnityEditorInternalException(ex); } } else { try { AsyncProgressBarType = typeof(EditorWindow).Assembly.GetType("UnityEditor.AsyncProgressBar", true); AsyncProgressBar_Display = AsyncProgressBarType.GetMethod("Display", BindingFlags.Static | BindingFlags.Public); AsyncProgressBar_Clear = AsyncProgressBarType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public); if (AsyncProgressBar_Display == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Display"); } if (AsyncProgressBar_Clear == null) { throw new MissingMemberException(AsyncProgressBarType.FullName, "Clear"); } } catch (Exception ex) { throw new UnityEditorInternalException(ex); } } queue = new Queue <Action>(); ClearProgress(); foreach (var type in Codebase.ludiqEditorTypes.Where(type => type.HasAttribute <BackgroundWorkerAttribute>(false))) { foreach (var attribute in type.GetAttributes <BackgroundWorkerAttribute>().DistinctBy(bwa => bwa.methodName)) { var backgroundWorkMethod = type.GetMethod(attribute.methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (backgroundWorkMethod != null) { tasks += () => backgroundWorkMethod.Invoke(null, new object[0]); } else { Debug.LogWarningFormat($"Missing '{attribute.methodName}' method for '{type}' background worker."); } } } EditorApplication.update += DisplayProgress; EditorApplication.delayCall += delegate { new Thread(Work) { Name = "Background Worker" }.Start(); }; }