IEnumerator RunQueue() { while (ops.Count > 0) { using (var timer = StopWatchPool.New()) { timer.stopWatch.Start(); for (int i = 0; i < ops.Count;) { try { if (ops[i].Run()) { ops.RemoveAt(i); } else { ++i; } } catch (System.Exception e) { Debug.LogException(e); ops.RemoveAt(i); } if (timer.stopWatch.ElapsedMilliseconds >= maxMilliseconds) { break; } } } if (ops.Count == 0) { break; } yield return(null); } _running = false; }
public static Dictionary <string, CFuncMethod> GetCFuncs(Assembly[] assemblies) { Dictionary <string, CFuncMethod> cvarMethods = new Dictionary <string, CFuncMethod>(); using (var stopWatch = StopWatchPool.New()) { stopWatch.stopWatch.Start(); foreach (var a in assemblies) { foreach (var t in a.GetTypes()) { if (!t.IsClass) { continue; } foreach (var m in t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)) { if (!m.IsConstructor && (m.DeclaringType == t)) { var cvarAttrs = m.GetCustomAttributes(typeof(CFunc), false); if (cvarAttrs.Length > 0) { var cfuncMethod = new CFuncMethod(); cfuncMethod.cfunc = (CFunc)cvarAttrs[0]; cfuncMethod.method = m; var nameList = cfuncMethod.cfunc.shortcuts; if ((nameList != null) && (nameList.Length > 0)) { foreach (var cvarName in nameList) { var name = cvarName.ToLower(); CFuncMethod collision; if (cvarMethods.TryGetValue(name, out collision)) { throw new System.Exception("CFunc defined multiple times, first at: " + collision.method.DeclaringType.FullName + "." + collision.method.Name + ", and then at: " + cfuncMethod.method.DeclaringType.FullName + "." + cfuncMethod.method.Name); } else { cvarMethods.Add(name, cfuncMethod); } } } { var cvarName = m.Name.ToLower(); CFuncMethod collision; if (cvarMethods.TryGetValue(cvarName, out collision)) { throw new System.Exception("CFunc defined multiple times, first at: " + collision.method.DeclaringType.FullName + "." + collision.method.Name + ", and then at: " + cfuncMethod.method.DeclaringType.FullName + "." + cfuncMethod.method.Name); } else { cvarMethods.Add(cvarName, cfuncMethod); } } } } } } } Debug.Log("Loaded CFuncs in " + stopWatch.stopWatch.Elapsed); } return(cvarMethods); }