public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) { if (!data.IsString) { return(fsResult.Fail("Expected string in " + data)); } instance = new UnitCategory(data.AsString); return(fsResult.Success); }
public EditorTexture UnitCategory(UnitCategory category) { if (category == null) { return(unitCategory); } if (!unitCategoryIcons.ContainsKey(category)) { var path = $"Icons/Unit Categories/{category.fullName}.png"; unitCategoryIcons.Add(category, LoadSharedIcon(path, false) ?? unitCategory); } return(unitCategoryIcons[category]); }
public UnitCategory(string fullName) { Ensure.That(nameof(fullName)).IsNotNull(fullName); fullName = fullName.Replace('\\', '/'); this.fullName = fullName; var parts = fullName.Split('/'); name = parts[parts.Length - 1]; if (parts.Length > 1) { root = new UnitCategory(parts[0]); parent = new UnitCategory(fullName.Substring(0, fullName.LastIndexOf('/'))); } else { root = this; isRoot = true; } }
private IEnumerable <object> CategoryChildren(UnitCategory category, bool subCategories = true) { if (category != null && subCategories) { foreach (var subCategory in options.SelectMany(option => option.category == null ? Enumerable.Empty <UnitCategory>() : option.category.AndAncestors()) .Distinct() .Where(c => c.parent == category) .OrderBy(c => c.name)) { yield return(subCategory); } } foreach (var unit in options.Where(option => option.category == category) .Where(option => !option.unitType.HasAttribute <SpecialUnitAttribute>()) .OrderBy(option => option.order) .ThenBy(option => option.label)) { yield return(unit); } if (category != null) { if (category.root.name == "Events") { foreach (var eventChild in EventsChildren(category)) { yield return(eventChild); } } else if (category.fullName == "Codebase") { foreach (var codebaseChild in CodebaseChildren()) { yield return(codebaseChild); } } else if (category.fullName == "Variables") { foreach (var variableChild in VariablesChildren()) { yield return(variableChild); } } else if (category.fullName == "Math") { foreach (var mathChild in MathChildren()) { yield return(mathChild); } } else if (category.fullName == "Time") { foreach (var timeChild in TimeChildren()) { yield return(timeChild); } } else if (category.fullName == "Nesting") { foreach (var nestingChild in NestingChildren()) { yield return(nestingChild); } } else if (category.fullName == "Macros") { foreach (var macroChild in MacroChildren()) { yield return(macroChild); } } } }