/// <summary> Gets every GunAspect that is referenced by a system version </summary> public GunAspect GetAllAspectsUsedInSystem(GunSystemsContainer systems) { GunAspect usedAspects = new GunAspect(); foreach (Type system in typeof(GunSystemBase).GetAllDerivedTypes(systems.GetType())) { GunAspect inclusive = system.GetCustomAttribute <InclusiveAspectsAttribute>(false)?.inclusive_aspects; GunAspect exclusive = system.GetCustomAttribute <ExclusiveAspectsAttribute>(false)?.exclusive_aspects; if (inclusive == null && exclusive == null) { continue; } if (inclusive == null) { usedAspects = usedAspects | exclusive; } else if (exclusive == null) { usedAspects = usedAspects | inclusive; } else { usedAspects = usedAspects | exclusive | inclusive; } } return(usedAspects); }
public void OnEnable() { gun_systems = GetGunSystems(); // Init aspect = aspect ^ (GunAspect.ALTERNATIVE_STANCE & aspect); // Remove ALTERNATIVE_STANCE if it is present gun_systems.LoadSystems(this, aspect); gun_systems.Initialize(); }
private void OnEnable() { gun_script = (GunScript)target; systems = gun_script.GetGunSystems(); possible_aspects = GetAllAspectsUsedInSystem(systems); possible_components = typeof(GunComponent).GetAllDerivedTypes(); possible_systems = typeof(GunSystemBase).GetAllDerivedTypes(systems.GetType()); Update(); }
public GunComponent GetComponentFromAspect(GunAspect aspect) { foreach (Type type in possible_components) { GunDataAttribute gun_data = type.GetCustomAttribute <GunDataAttribute>(); if (gun_data != null && gun_data.gun_aspect.HasFlag(aspect)) { return((GunComponent)gun_script.GetComponent(type)); } } return(null); }
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); } }
private GunAspect LoadedAspects() { GunAspect loaded_aspects = new GunAspect(); foreach (Type type in possible_systems) { if (systems.ShouldLoadSystem(type, gun_script.aspect)) { loaded_aspects = loaded_aspects | type.GetCustomAttribute <InclusiveAspectsAttribute>().inclusive_aspects; } } return(loaded_aspects); }
public static string GetGUIGroup(this GunAspect aspect) { if (aspect.value.Length != 1) { return("None"); } if (GUI_GROUP.ContainsKey(aspect.value[0])) { return(GUI_GROUP[aspect.value[0]]); } return("None"); }
private GunAspect ExcludedAspects() { GunAspect excluded_aspects = new GunAspect(); foreach (Type type in possible_systems) { ExclusiveAspectsAttribute exclusives = type.GetCustomAttribute <ExclusiveAspectsAttribute>(); if (exclusives != null && systems.ShouldLoadSystem(type, gun_script.aspect, true)) { excluded_aspects = excluded_aspects | exclusives.exclusive_aspects; } } return(excluded_aspects); }
private void Update() { loaded_aspects = LoadedAspects(); required_components = GetRequiredComponents(); UpdateComponents(); excluded_aspects = ExcludedAspects(); UpdateValidationCache(); // Hide all GunComponents foreach (GunComponent gun_component in gun_script.gameObject.GetComponents <GunComponent>()) { gun_component.hideFlags = HideFlags.HideInInspector; } }
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()); }
public bool HasAnyFlag(GunAspect aspect) { if (aspect.IsEmpty() || IsEmpty()) { return(false); } foreach (ushort bit in aspect.value) { if (value.Contains(bit)) { return(true); } } return(false); }
public static GUIContent GetGUIContent(this GunAspect aspect) { if (aspect.value.Length > 1) { return(new GUIContent(aspect.ToString())); } if (aspect.value.Length <= 0) { return(new GUIContent("GunAspect.NONE")); } if (GUI_CONTENT.ContainsKey(aspect.value[0])) { return(GUI_CONTENT[aspect.value[0]]); } Debug.LogWarning($"GUI_CONTENT missing for GunAspect {aspect.value[0]}!"); return(new GUIContent("null")); }
public static T GetAttribute <T>(this GunAspect aspect) { if (aspect.value.Length != 1) { throw new System.Exception("Tried to get fields of multiple aspects"); } int target = aspect.value[0]; foreach (FieldInfo field in typeof(GunAspect).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)) { if (field.FieldType == typeof(int) && (int)field.GetRawConstantValue() == target) { if (field.GetCustomAttribute(typeof(T)) is T attribute) { return(attribute); } } } return(default(T)); }
public GunDataAttribute(params ushort[] gun_aspect) { this.gun_aspect = gun_aspect; }
// Has component methods public bool HasGunComponent(GunAspect aspect) { return(this.aspect.HasFlag(aspect)); }
public bool IsConditionMet(GunAspect aspects) { return((exclusive_aspects & aspects).IsEmpty()); }
public ExclusiveAspectsAttribute(params ushort[] exclusive_aspects) { this.exclusive_aspects = exclusive_aspects; }
public bool IsConditionMet(GunAspect aspects) { return((inclusive_aspects & aspects) == inclusive_aspects); }
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(); } }
public abstract void LoadSystems(GunScript gs, GunAspect aspects);
public GunInspectorAspectAttribute(GunAspect gun_aspect) { aspect = gun_aspect; }
public abstract bool ShouldLoadSystem(Type system, GunAspect aspects, bool ignore_exclusives = false, bool ignore_inclusives = false);
public InclusiveAspectsAttribute(params ushort[] inclusive_aspects) { this.inclusive_aspects = inclusive_aspects; }