private static void SetupThreaded(object threadTaskId) { #if DEV_MODE var timer = new ExecutionTimeLogger(); timer.Start("DefaultDrawerProviders.SetupThreaded"); #endif drawerProvidersByInspectorType.Clear(); #if DEV_MODE timer.StartInterval("FindDrawerProviderForAttributesInTypes"); #endif FindDrawerProviderForAttributesInTypes(TypeExtensions.GetAllTypesThreadSafe(false, true, true)); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("Add derived types"); #endif // Also add derived types of inspector types var addDerived = new List <KeyValuePair <Type, IDrawerProvider> >(); foreach (var drawerByType in drawerProvidersByInspectorType) { var exactInspectorType = drawerByType.Key; var derivedInspectorTypes = exactInspectorType.IsInterface ? TypeExtensions.GetImplementingTypes(exactInspectorType, true) : TypeExtensions.GetExtendingTypes(exactInspectorType, true); for (int n = derivedInspectorTypes.Length - 1; n >= 0; n--) { addDerived.Add(new KeyValuePair <Type, IDrawerProvider>(derivedInspectorTypes[n], drawerByType.Value)); } } for (int n = addDerived.Count - 1; n >= 0; n--) { var add = addDerived[n]; var derivedInspectorType = add.Key; if (!drawerProvidersByInspectorType.ContainsKey(derivedInspectorType)) { drawerProvidersByInspectorType.Add(derivedInspectorType, add.Value); } } #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(drawerProvidersByInspectorType[typeof(PowerInspector)] != null); #endif selfReady = true; #if DEV_MODE timer.FinishInterval(); timer.FinishAndLogResults(); #endif #if CACHE_TO_DISK && (!NET_2_0 && !NET_2_0_SUBSET && !NET_STANDARD_2_0) // HashSet.GetObjectData is not implemented in older versions EditorApplication.delayCall += Serialize; #endif }
private static void SetupThreaded(object threadTaskId) { #if DEV_MODE var timer = new ExecutionTimeLogger(); timer.Start("DefaultDrawerProviders.SetupThreaded"); #endif drawerProvidersByInspectorTypeRebuilt = new Dictionary <Type, IDrawerProvider>(2); #if DEV_MODE timer.StartInterval("FindDrawerProviderForAttributesInTypes"); #endif foreach (var type in TypeExtensions.GetAllTypesThreadSafe(false, true, true)) { if (!typeof(IDrawerProvider).IsAssignableFrom(type)) { continue; } foreach (var drawerProviderFor in AttributeUtility.GetAttributes <DrawerProviderForAttribute>(type)) { var inspectorType = drawerProviderFor.inspectorType; if (inspectorType == null) { UnityEngine.Debug.LogError(drawerProviderFor.GetType().Name + " on class " + type.Name + " NullReferenceException - inspectorType was null!"); continue; } IDrawerProvider drawerProvider; if (!drawerProvidersByInspectorTypeRebuilt.TryGetValue(inspectorType, out drawerProvider) || !drawerProviderFor.isFallback) { bool reusedExistingInstance = false; foreach (var createdDrawerProvider in drawerProvidersByInspectorTypeRebuilt.Values) { if (createdDrawerProvider.GetType() == type) { drawerProvidersByInspectorTypeRebuilt.Add(inspectorType, createdDrawerProvider); reusedExistingInstance = true; break; } } if (!reusedExistingInstance) { #if DEV_MODE && DEBUG_SETUP UnityEngine.Debug.Log("Creating new DrawerProvider instance of type " + type.Name + " for inspector" + inspectorType.Name); #endif #if DEV_MODE timer.StartInterval(type.Name + ".CreateInstance"); #endif var drawerProviderInstance = (IDrawerProvider)Activator.CreateInstance(type); #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(drawerProviderInstance != null); #endif drawerProvidersByInspectorTypeRebuilt.Add(inspectorType, drawerProviderInstance); #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(drawerProvidersByInspectorTypeRebuilt[inspectorType] != null); #endif #if DEV_MODE timer.FinishInterval(); #endif } } } } #if DEV_MODE timer.FinishInterval(); timer.StartInterval("Add derived types"); #endif // Also add derived types of inspector types var addDerived = new List <KeyValuePair <Type, IDrawerProvider> >(); foreach (var drawerByType in drawerProvidersByInspectorTypeRebuilt) { var exactInspectorType = drawerByType.Key; var derivedInspectorTypes = exactInspectorType.IsInterface ? TypeExtensions.GetImplementingTypes(exactInspectorType, true) : TypeExtensions.GetExtendingTypes(exactInspectorType, true); for (int n = derivedInspectorTypes.Length - 1; n >= 0; n--) { addDerived.Add(new KeyValuePair <Type, IDrawerProvider>(derivedInspectorTypes[n], drawerByType.Value)); } } for (int n = addDerived.Count - 1; n >= 0; n--) { var add = addDerived[n]; var derivedInspectorType = add.Key; if (!drawerProvidersByInspectorTypeRebuilt.ContainsKey(derivedInspectorType)) { drawerProvidersByInspectorTypeRebuilt.Add(derivedInspectorType, add.Value); } } #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(drawerProvidersByInspectorTypeRebuilt[typeof(PowerInspector)] != null); #endif //selfReady = true; threadedFullRebuildFinished = true; #if DEV_MODE timer.FinishInterval(); timer.FinishAndLogResults(); #endif #if CACHE_TO_DISK && (!NET_2_0 && !NET_2_0_SUBSET && !NET_STANDARD_2_0) // HashSet.GetObjectData is not implemented in older versions EditorApplication.delayCall += Serialize; #endif }
/// <summary> /// Important: this should be called before CharAdvances calculations are requested /// Currently handled by DrawGUI.Setup /// </summary> private void CacheCharAdvances() { if (charAdvancesCached) { return; } #if DEV_MODE && DEBUG_CACHE_CHAR_ADVANCES_TIME timer.Start("FontCharSizes.CacheCharAdvances"); Profiler.BeginSample("FontCharSizes.CacheCharAdvances"); #endif charAdvances.Clear(); #if DEV_MODE && DEBUG_CACHE_CHAR_ADVANCES_TIME timer.StartInterval("FontCharSizes.RequestCharactersInTexture"); Profiler.BeginSample("FontCharSizes.RequestCharactersInTexture"); #endif font.RequestCharactersInTexture(AllCharacters, fontSize, FontStyle.Normal); #if DEV_MODE && DEBUG_CACHE_CHAR_ADVANCES_TIME Profiler.EndSample(); timer.FinishInterval(); timer.StartInterval("FontCharSizes.GetCharacterInfos"); Profiler.BeginSample("FontCharSizes.GetCharacterInfo"); #endif CharacterInfo info; for (int i = AllCharacters.Length - 1; i >= 0; i--) { char c = AllCharacters[i]; font.GetCharacterInfo(c, out info, fontSize, FontStyle.Normal); charAdvances.Add(c, info.advance); } #if DEV_MODE && DEBUG_CACHE_CHAR_ADVANCES_TIME Profiler.EndSample(); timer.FinishInterval(); #endif if (charAdvances.Count == 0) { #if DEV_MODE Debug.LogError("Tried to cache chars from fron " + font.name + " with fontSize " + fontSize + " but failed with event " + StringUtils.ToString(Event.current)); #endif return; } // for some reason the advance for the tab character seems to always give the result of zero inside a for loop // but if we request the character info here separately, it seems to give a result of 6f every time. // However, even when a non-zero result is given, it seems to be too small compared to actual rendered width, // so we just set the value manually to 28. //font.GetCharacterInfo('\t', out info, fontSize, FontStyle.Normal); //CharAdvances['\t'] = info.advance; charAdvances['\t'] = 28f; charAdvancesCached = true; #if DEV_MODE && DEBUG_CACHE_CHAR_ADVANCES_TIME Profiler.EndSample(); timer.FinishAndLogResults(); #endif }
private static void SetupThreaded(object threadTaskId) { #if DEV_MODE var timer = new ExecutionTimeLogger(); timer.Start("MemberInfoBaseDrawerData.SetupThreaded"); timer.StartInterval("Generate PopupMenuItems"); #endif var sb = new System.Text.StringBuilder(); foreach (var type in TypeExtensions.AllVisibleAndUniqueTypes) { sb.Append(TypeExtensions.GetPopupMenuLabel(type, "")); sb.Append('/'); string typePrefix = sb.ToString(); sb.Length = 0; var fields = type.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); for (int f = fields.Length - 1; f >= 0; f--) { var field = fields[f]; sb.Append(typePrefix); sb.Append(field.Name); string menuPath = sb.ToString(); sb.Length = 0; PopupMenuUtility.BuildPopupMenuItemWithLabel(ref fieldRootItems, ref fieldGroupsByLabel, ref fieldItemsByLabel, field, menuPath, MenuItemValueType.Undefined); } var properties = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); for (int p = properties.Length - 1; p >= 0; p--) { var property = properties[p]; sb.Append(typePrefix); StringUtils.ToString(property, sb); string menuPath = sb.ToString(); sb.Length = 0; PopupMenuUtility.BuildPopupMenuItemWithLabel(ref propertyRootItems, ref propertyGroupsByLabel, ref propertyItemsByLabel, property, menuPath, MenuItemValueType.Undefined); } var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); for (int m = methods.Length - 1; m >= 0; m--) { var method = methods[m]; sb.Append(typePrefix); StringUtils.ToString(method, sb); string menuPath = sb.ToString(); sb.Length = 0; PopupMenuUtility.BuildPopupMenuItemWithLabel(ref methodRootItems, ref methodGroupsByLabel, ref methodItemsByLabel, method, menuPath, MenuItemValueType.Undefined); } } #if DEV_MODE timer.FinishInterval(); timer.StartInterval("allRootItems.AddRange(fieldRootItems)"); #endif allRootItems.AddRange(fieldRootItems); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allRootItems, propertyRootItems)"); #endif PopupMenuUtility.AddRange(ref allRootItems, propertyRootItems); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allRootItems, methodRootItems)"); #endif PopupMenuUtility.AddRange(ref allRootItems, methodRootItems); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allGroupsByLabel, fieldGroupsByLabel)"); #endif PopupMenuUtility.AddRange(ref allGroupsByLabel, fieldGroupsByLabel); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allGroupsByLabel, propertyGroupsByLabel)"); #endif PopupMenuUtility.AddRange(ref allGroupsByLabel, propertyGroupsByLabel); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allGroupsByLabel, methodGroupsByLabel)"); #endif PopupMenuUtility.AddRange(ref allGroupsByLabel, methodGroupsByLabel); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allItemsByLabel, fieldItemsByLabel)"); #endif PopupMenuUtility.AddRange(ref allItemsByLabel, fieldItemsByLabel); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allItemsByLabel, propertyItemsByLabel)"); #endif PopupMenuUtility.AddRange(ref allItemsByLabel, propertyItemsByLabel); #if DEV_MODE timer.FinishInterval(); timer.StartInterval("AddRange(allItemsByLabel, methodItemsByLabel)"); #endif PopupMenuUtility.AddRange(ref allItemsByLabel, methodItemsByLabel); #if DEV_MODE timer.FinishInterval(); timer.FinishAndLogResults(); #endif setupDone = SetupPhase.Done; lock (threadLock) { var action = onSetupFinished; if (action != null) { onSetupFinished = null; action(); } } }