private Type[] GetRequiredComponents() { List <Type> types = new List <Type>(); foreach (Type type in possible_components) { GunAspect component_aspect = type.GetCustomAttribute <GunDataAttribute>().gun_aspect; if (loaded_aspects.HasFlag(component_aspect)) { types.Add(type); } } return(types.ToArray()); }
private void DrawAspectButtons() { GUIStyle style = new GUIStyle(EditorStyles.miniButton); style.fontSize = 10; style.clipping = TextClipping.Clip; style.margin = new RectOffset(); foreach (var group in aspect_groups) { GUILayout.BeginHorizontal(); GunAspect group_aspect = GunAspect.ALL.Where((value) => { return(possible_aspects.HasFlag(value) && group.Value.HasFlag(value)); }).ToArray(); for (int i = 0; i < group_aspect.value.Length; i++) { GunAspect current_aspect = group_aspect.value[i]; if (i % 2 == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } // Prepare color Color color = GUI.color; if (loaded_aspects.HasFlag(current_aspect)) { GUI.color = ASPECT_LOADED; } else if (gun_script.aspect.HasFlag(current_aspect)) { GUI.color = ASPECT_SELECTED; } // Draw Button if (GUILayout.Button(current_aspect.GetGUIContent(), style, GUILayout.MinWidth(20))) { gun_script.aspect = gun_script.aspect ^ current_aspect; EditorUtility.SetDirty(gun_script); } // Restore color GUI.color = color; } GUILayout.EndHorizontal(); GUILayout.Space(10); } if (validation_cache_components.ContainsValue(false)) { EditorGUILayout.HelpBox("One or more Gun Components report an issue!\n\nMake sure every required field is set below!", MessageType.Warning); } }
public void DrawAspects() { // Draw Header EditorGUI.BeginChangeCheck(); foreach (GunAspect aspect in possible_aspects) { if (aspect.IsEmpty() || !loaded_aspects.HasFlag(aspect)) { continue; } GunComponent component = GetComponentFromAspect(aspect); if (!component || !ShouldShowComponent(component.GetType())) { continue; } bool show_error = !IsValid(component); if (show_error) { BeginError(); } GUILayout.BeginVertical("Box"); EditorGUI.indentLevel++; // Show Aspect Header bool unfold = EditorGUILayout.Foldout(expanded_aspects.HasFlag(aspect), aspect.GetGUIContent(), true, EditorStyles.label); // Display Aspect Data if (unfold) { DrawAspectData(component); } // Update folded Aspects if (unfold != expanded_aspects.HasFlag(aspect)) { if (unfold) { expanded_aspects = expanded_aspects | aspect; } else { expanded_aspects = ~(~expanded_aspects | aspect); } } // Endgroup EditorGUI.indentLevel--; GUILayout.EndVertical(); if (show_error) { EndError(); } } if (EditorGUI.EndChangeCheck()) { UpdateValidationCache(); } }