/// <summary> /// Validates currently cached layout scopes (vertical and horizontal). /// </summary> /// <returns>true if scopes were clean.</returns> private static bool ValidateScopes() { if (vLayoutClips > 0 || hLayoutClips > 0) { if (!isExitedLayout) { ToolboxEditorLog.LogWarning("Invalid layout data. Check if created groups (vertical or horizontal) are properly closed."); } while (vLayoutClips > 0) { CloseVertical(); } while (hLayoutClips > 0) { CloseHorizontal(); } return(false); } else { return(true); } }
/// <summary> /// Creates all possible type-based drawers and add them to the related collection. /// </summary> /// <param name="settings"></param> private static void CreateTargetTypeDrawers(IToolboxInspectorSettings settings) { var childrenTypesMap = new Dictionary <ToolboxTargetTypeDrawer, List <Type> >(); targetTypeDrawers.Clear(); for (var i = 0; i < settings.TargetTypeDrawersCount; i++) { var drawerType = settings.GetTargetTypeDrawerTypeAt(i); if (drawerType == null) { if (validationEnabled) { ToolboxEditorLog.LogWarning("One of assigned drawer types in the " + nameof(ToolboxEditorSettings) + " is empty."); } continue; } var drawerInstance = Activator.CreateInstance(drawerType) as ToolboxTargetTypeDrawer; var targetBaseType = drawerInstance.GetTargetType(); if (targetBaseType != null) { if (targetTypeDrawers.ContainsKey(targetBaseType)) { if (validationEnabled) { ToolboxEditorLog.LogError("Type:" + targetBaseType + " is associated to more than one ToolboxDrawer."); } continue; } targetTypeDrawers[targetBaseType] = drawerInstance; if (drawerInstance.UseForChildren()) { childrenTypesMap[drawerInstance] = targetBaseType.GetAllChildClasses(); } } } foreach (var typesMap in childrenTypesMap) { var typesDrawer = typesMap.Key; var targetTypes = typesMap.Value; for (var i = 0; i < targetTypes.Count; i++) { var targetType = targetTypes[i]; if (targetTypeDrawers.ContainsKey(targetType)) { continue; } targetTypeDrawers[targetType] = typesDrawer; } } }
internal static void EndHorizontal() { if (horizontalScopes.Count == 0) { ToolboxEditorLog.LogWarning("There is no a horizontal group to end. Call will be ignored."); return; } horizontalScopes.Pop().Dispose(); }
internal static void CloseHorizontal() { if (hLayoutClips == 0) { ToolboxEditorLog.LogWarning("There is no horizontal group to end. Call will be ignored."); return; } hLayoutClips--; EditorGUILayout.EndHorizontal(); }
internal static void CloseVertical() { if (vLayoutClips == 0) { ToolboxEditorLog.LogWarning("There is no vertical group to end. Call will be ignored."); return; } vLayoutClips--; EditorGUILayout.EndVertical(); }
internal static Rect BeginVertical(GUIStyle style, params GUILayoutOption[] options) { if (!isEditorLayout) { ToolboxEditorLog.LogWarning("Begin vertical layout group action can be executed only within the Toolbox Editor."); return(Rect.zero); } vLayoutClips++; return(EditorGUILayout.BeginVertical(style, options)); }
internal static void BeginVertical(GUIStyle style, params GUILayoutOption[] options) { if (!inEditorLayout) { ToolboxEditorLog.LogWarning("Begin vertical layout group action can be executed only within the Toolbox Editor."); return; } var scope = style == null ? new EditorGUILayout.VerticalScope(options) : new EditorGUILayout.VerticalScope(style, options); verticalScopes.Push(scope); }
internal static ToolboxTargetTypeDrawer GetTargetTypeDrawer(Type propertyType) { var targetType = propertyType.IsGenericType ? propertyType.GetGenericTypeDefinition() : propertyType; if (targetTypeDrawers.TryGetValue(targetType, out var drawer)) { return(drawer); } else { ToolboxEditorLog.LogWarning("There is no type-based drawer associated to the " + propertyType + " type."); return(null); } }
internal static Rect BeginHorizontal(GUIStyle style, params GUILayoutOption[] options) { if (!isEditorLayout) { ToolboxEditorLog.LogWarning("Begin horizontal layout group action can be executed only within the Toolbox Editor."); return(Rect.zero); } if (hLayoutClips > 0) { ToolboxEditorLog.LogWarning("Nested horizontal layout groups are not supported."); return(Rect.zero); } hLayoutClips++; return(EditorGUILayout.BeginHorizontal(style, options)); }
internal static void BeginHorizontal(GUIStyle style, params GUILayoutOption[] options) { if (!inEditorLayout) { ToolboxEditorLog.LogWarning("Begin horizontal layout group action can be executed only within the Toolbox Editor."); return; } if (horizontalScopes.Count > 0) { ToolboxEditorLog.LogWarning("Nested horizontal layout groups are not supported."); return; } var scope = style == null ? new EditorGUILayout.HorizontalScope(options) : new EditorGUILayout.HorizontalScope(style, options); horizontalScopes.Push(scope); }
/// <summary> /// Returns and/or creates (if needed) <see cref="ToolboxPropertyHandler"/> for given property. /// </summary> internal static ToolboxPropertyHandler GetPropertyHandler(SerializedProperty property) { if (InspectorUtility.InToolboxEditor) { //NOTE: maybe type-based key? var propertyKey = property.GetPropertyHashKey(); if (propertyHandlers.TryGetValue(propertyKey, out var propertyHandler)) { return(propertyHandler); } else { return(propertyHandlers[propertyKey] = new ToolboxPropertyHandler(property)); } } else { ToolboxEditorLog.LogWarning("Do not use Toolbox-related drawers outside ToolboxEditor."); return(null); } }
/// <summary> /// Validates currently cached layout scopes (vertical and horizontal). /// </summary> /// <returns>true if scopes were clean.</returns> private static bool ValidateScope() { if (verticalScopes.Count == 0 && horizontalScopes.Count == 0) { return(true); } else { ToolboxEditorLog.LogWarning("Invalid layout data. Check if created groups (vertical or horizontal) are properly closed."); while (verticalScopes.Count > 0) { verticalScopes.Pop().Dispose(); } while (horizontalScopes.Count > 0) { horizontalScopes.Pop().Dispose(); } } return(false); }
/// <summary> /// Creates all possible attribute-based drawers and add them to proper collections. /// </summary> /// <param name="settings"></param> private static void CreateAttributeDrawers(IToolboxInspectorSettings settings) { void AddAttributeDrawer <T>(Type drawerType, Type attributeType, Dictionary <Type, T> drawersCollection) where T : ToolboxAttributeDrawer { if (drawerType == null) { return; } var drawerInstance = Activator.CreateInstance(drawerType) as T; if (drawersCollection.ContainsKey(attributeType)) { if (validationEnabled) { ToolboxEditorLog.LogError("Attribute:" + attributeType + " is associated to more than one ToolboxDrawer."); } return; } drawersCollection.Add(attributeType, drawerInstance); } Type GetDrawersGenericType(Type drawerType, Type drawerBaseType) { if (drawerType == null) { if (validationEnabled) { ToolboxEditorLog.LogWarning("One of assigned drawer types in the " + nameof(ToolboxEditorSettings) + " is empty."); } return(null); } while (!drawerType.IsGenericType || drawerType.GetGenericTypeDefinition() != drawerBaseType) { if (drawerType.BaseType == null) { return(null); } drawerType = drawerType.BaseType; } return(drawerType.IsGenericType ? drawerType.GetGenericArguments().FirstOrDefault() : null); } decoratorDrawers.Clear(); for (var i = 0; i < settings.DecoratorDrawersCount; i++) { var drawerType = settings.GetDecoratorDrawerTypeAt(i); var targetType = GetDrawersGenericType(settings.GetDecoratorDrawerTypeAt(i), decoratorDrawerBase); AddAttributeDrawer(drawerType, targetType, decoratorDrawers); } conditionDrawers.Clear(); for (var i = 0; i < settings.ConditionDrawersCount; i++) { var drawerType = settings.GetConditionDrawerTypeAt(i); var targetType = GetDrawersGenericType(settings.GetConditionDrawerTypeAt(i), conditionDrawerBase); AddAttributeDrawer(drawerType, targetType, conditionDrawers); } selfPropertyDrawers.Clear(); for (var i = 0; i < settings.SelfPropertyDrawersCount; i++) { var drawerType = settings.GetSelfPropertyDrawerTypeAt(i); var targetType = GetDrawersGenericType(settings.GetSelfPropertyDrawerTypeAt(i), selfPropertyDrawerBase); AddAttributeDrawer(drawerType, targetType, selfPropertyDrawers); } listPropertyDrawers.Clear(); for (var i = 0; i < settings.ListPropertyDrawersCount; i++) { var drawerType = settings.GetListPropertyDrawerTypeAt(i); var targetType = GetDrawersGenericType(settings.GetListPropertyDrawerTypeAt(i), listPropertyDrawerBase); AddAttributeDrawer(drawerType, targetType, listPropertyDrawers); } }