several optimisations

This commit is contained in:
Az committed 2026-11-07 04:57:50 -05:00
1 parent de37e4a3b0
commit 6887029657
7 files changed
+149 -184

No files matched your search

+67 -112
View File
@@ -24,10 +24,10 @@ namespace MiraAPI.GameOptions;
/// </summary>
public static class ModdedOptionsManager
{
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> GetterLookups = [];
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> SetterLookups = [];
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = [];
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> GetterLookup = [];
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> SetterLookup = [];
private static readonly HashSet<PropertyInfo> OptionAttributes = [];
private static readonly HashSet<Type> Types = [];
private static readonly MethodInfo OpenGetterPatch = typeof(ModdedOptionsManager)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
@@ -35,8 +35,8 @@ public static class ModdedOptionsManager
private static readonly MethodInfo OpenSetterPatch = typeof(ModdedOptionsManager)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(m => m.Name == nameof(PropertySetterPatch) && m.IsGenericMethodDefinition);
private static readonly Dictionary<Type, HarmonyMethod> ConcretisedGetters = [];
private static readonly Dictionary<Type, HarmonyMethod> ConcretisedSetters = [];
private static readonly Dictionary<RuntimeTypeHandle, HarmonyMethod> ConcretisedGetters = [];
private static readonly Dictionary<RuntimeTypeHandle, HarmonyMethod> ConcretisedSetters = [];
private static readonly Type OptionType = typeof(IModdedOption);
private static readonly Type OptionListType = typeof(IModdedOptionList);
@@ -83,7 +83,7 @@ public static class ModdedOptionsManager
return false;
}
if (TypeToGroup.ContainsKey(type))
if (!Types.Add(type))
{
Error($"Group {type.Name} already exists.");
return false;
@@ -109,30 +109,24 @@ public static class ModdedOptionsManager
pluginInfo.InternalOptionGroups.Add(group);
Groups.Add(group);
TypeToGroup.Add(type, group);
typeof(OptionGroupSingleton<>).MakeGenericType(type)
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)! // Suppression refers to this
.SetValue(null, group);
foreach (var property in type.GetProperties(MiraPluginManager.DeclaredInstanceMembers))
{
if (property.GetMethod == null)
{
Error($"Non-ignored option property {property.Name} in {type.Name} must at least have a getter.");
continue;
}
var propType = property.PropertyType;
if (propType.IsAssignableTo(OptionType))
{
RegisterPropertyOption(type, property, pluginInfo);
RegisterPropertyOption(type, property, pluginInfo, group);
continue;
}
if (propType.IsAssignableTo(OptionListType))
{
RegisterPropertyOptionList(type, property, pluginInfo);
RegisterPropertyOptionList(type, property, pluginInfo, group);
continue;
}
@@ -142,13 +136,13 @@ public static class ModdedOptionsManager
{
if (attr is ModdedOptionAttribute moddedAttr)
{
RegisterAttributeOption(type, moddedAttr, property, pluginInfo, propType, attributes);
RegisterAttributeOption(type, moddedAttr, property, pluginInfo, propType, attributes, group);
break;
}
if (attr is ModdedOptionListAttribute listAttr)
{
RegisterAttributeOptionList(type, listAttr, property, pluginInfo, propType, attributes);
RegisterAttributeOptionList(type, listAttr, property, pluginInfo, propType, attributes, group);
break;
}
}
@@ -167,21 +161,45 @@ public static class ModdedOptionsManager
return true;
}
private static void RegisterPropertyOption(Type type, PropertyInfo property, MiraPluginInfo pluginInfo)
private static void PatchProperty(PropertyInfo property, Type propType, PropertyOptionAttribute attribute)
{
if (!TypeToGroup.TryGetValue(type, out var group))
{
Error($"Failed to get group for {type.Name}");
return;
}
var handle = propType.TypeHandle;
ApplyPatch(handle, propType, ConcretisedGetters, GetterLookup, property.GetGetMethod(true), OpenGetterPatch, attribute);
ApplyPatch(handle, propType, ConcretisedSetters, SetterLookup, property.GetSetMethod(true), OpenSetterPatch, attribute);
}
private static void ApplyPatch(
RuntimeTypeHandle handle,
Type propType,
Dictionary<RuntimeTypeHandle, HarmonyMethod> concretised,
Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> lookup,
MethodInfo? toPatch,
MethodInfo patch,
PropertyOptionAttribute attribute)
{
if (toPatch == null)
return;
if (!concretised.TryGetValue(handle, out var concrete))
concretised[handle] = concrete = new(patch.MakeGenericMethod(propType));
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(toPatch, prefix: concrete);
lookup[toPatch.MethodHandle] = attribute;
}
private static void RegisterPropertyOption(
Type type,
PropertyInfo property,
MiraPluginInfo pluginInfo,
AbstractOptionGroup group)
{
if (property.GetValue(group) is not IModdedOption option)
{
Error($"Failed to get option for {property.Name}");
return;
}
RegisterOption(option, group, property.Name, pluginInfo);
RegisterOption(type, option, group, property.Name, pluginInfo);
}
private static void RegisterAttributeOption(
@@ -190,7 +208,8 @@ public static class ModdedOptionsManager
PropertyInfo property,
MiraPluginInfo pluginInfo,
Type propType,
object[] attributes)
object[] attributes,
AbstractOptionGroup group)
{
if (!OptionAttributes.Add(property))
{
@@ -198,12 +217,6 @@ public static class ModdedOptionsManager
return;
}
if (!TypeToGroup.TryGetValue(type, out var group))
{
Error($"Failed to get group for {type.Name}");
return;
}
var option = attribute.CreateOption(property.GetValue(group), property, group);
if (option == null)
@@ -212,29 +225,7 @@ public static class ModdedOptionsManager
return;
}
if (!ConcretisedGetters.TryGetValue(propType, out var concreteGetter))
{
concreteGetter = new(OpenGetterPatch.MakeGenericMethod(propType));
ConcretisedGetters[propType] = concreteGetter;
}
var getterOriginal = property.GetGetMethod(true)!;
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(getterOriginal, prefix: concreteGetter);
GetterLookups[getterOriginal.MethodHandle] = attribute;
var setterOriginal = property.GetSetMethod(true);
if (setterOriginal != null)
{
if (!ConcretisedSetters.TryGetValue(propType, out var concreteSetter))
{
concreteSetter = new(OpenSetterPatch.MakeGenericMethod(propType));
ConcretisedSetters[propType] = concreteSetter;
}
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(setterOriginal, postfix: concreteSetter);
SetterLookups[setterOriginal.MethodHandle] = attribute;
}
PatchProperty(property, propType, attribute);
attribute.HolderOption = option;
attribute.ValueType = propType;
@@ -258,17 +249,15 @@ public static class ModdedOptionsManager
}
}
RegisterOption(option, group, property.Name, pluginInfo);
RegisterOption(type, option, group, property.Name, pluginInfo);
}
private static void RegisterPropertyOptionList(Type type, PropertyInfo property, MiraPluginInfo pluginInfo)
private static void RegisterPropertyOptionList(
Type type,
PropertyInfo property,
MiraPluginInfo pluginInfo,
AbstractOptionGroup group)
{
if (!TypeToGroup.TryGetValue(type, out var group))
{
Error($"Failed to get group for {type.Name}");
return;
}
if (property.GetValue(group) is not IModdedOptionList optionList)
{
Error($"Failed to get option list for {property.Name}");
@@ -279,7 +268,7 @@ public static class ModdedOptionsManager
for (var i = 0; i < optionList.Count; i++)
{
RegisterOption(optionList[i], group, configName(i), pluginInfo);
RegisterOption(type, optionList[i], group, configName(i), pluginInfo);
}
}
@@ -289,7 +278,8 @@ public static class ModdedOptionsManager
PropertyInfo property,
MiraPluginInfo pluginInfo,
Type propType,
object[] attributes)
object[] attributes,
AbstractOptionGroup group)
{
if (!OptionAttributes.Add(property))
{
@@ -297,9 +287,10 @@ public static class ModdedOptionsManager
return;
}
if (!TypeToGroup.TryGetValue(type, out var group))
if (!propType.IsGenericType || propType.GetGenericTypeDefinition() != typeof(ModdedArray<>))
{
Error($"Failed to get group for {type.Name}");
var typeName = propType.IsGenericType ? propType.GetGenericArguments()[0].Name : "T";
Error($"Please use ModdedArray<{typeName}> for modded option lists.");
return;
}
@@ -323,42 +314,7 @@ public static class ModdedOptionsManager
return;
}
if (list.Count != optionList.Count)
{
Error("Mismatch in count between values and created options.");
return;
}
if (!propType.IsGenericType || propType.GetGenericTypeDefinition() != typeof(ModdedArray<>))
{
var typeName = propType.IsGenericType ? propType.GetGenericArguments()[0].Name : "T";
Error($"Please use ModdedArray<{typeName}> for modded option lists.");
return;
}
if (!ConcretisedGetters.TryGetValue(propType, out var concreteGetter))
{
concreteGetter = new(OpenGetterPatch.MakeGenericMethod(propType));
ConcretisedGetters[propType] = concreteGetter;
}
var getterOriginal = property.GetGetMethod(true)!;
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(getterOriginal, prefix: concreteGetter);
GetterLookups[getterOriginal.MethodHandle] = attribute;
var setterOriginal = property.GetSetMethod(true);
if (setterOriginal != null)
{
if (!ConcretisedSetters.TryGetValue(propType, out var concreteSetter))
{
concreteSetter = new(OpenSetterPatch.MakeGenericMethod(propType));
ConcretisedSetters[propType] = concreteSetter;
}
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(setterOriginal, postfix: concreteSetter);
SetterLookups[setterOriginal.MethodHandle] = attribute;
}
PatchProperty(property, propType, attribute);
var valueType = propType.GetGenericArguments()[0];
@@ -405,22 +361,21 @@ public static class ModdedOptionsManager
if (changedFactory != null)
option.ChangedEvent = changedFactory(i);
RegisterOption(option, group, property.Name + (i + 1), pluginInfo);
RegisterOption(type, option, group, property.Name + (i + 1), pluginInfo);
}
}
private static void RegisterOption(
Type type,
IModdedOption option,
AbstractOptionGroup group,
string propertyName,
MiraPluginInfo pluginInfo)
{
var groupName = group.GetType().FullName;
option.ConfigDefinition = new ConfigDefinition(groupName, propertyName);
option.ConfigDefinition = new ConfigDefinition(type.FullName, propertyName);
option.ParentGroup = group;
option.ParentMod = pluginInfo.MiraPlugin;
pluginInfo.InternalOptions.Add(option);
ModdedOptions.Add(option.Id, option);
group.Options.Add(option);
@@ -481,7 +436,7 @@ public static class ModdedOptionsManager
[Obsolete("Use PropertySetterPatch<T> instead. This will be removed in a future version.")]
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
{
if (!SetterLookups.TryGetValue(__originalMethod.MethodHandle, out var attribute))
if (!SetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
return;
attribute.SetValue(value);
@@ -500,7 +455,7 @@ public static class ModdedOptionsManager
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
public static void PropertySetterPatch<T>(MethodBase __originalMethod, T value)
{
if (!SetterLookups.TryGetValue(__originalMethod.MethodHandle, out var attribute))
if (!SetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
return;
if (attribute is ITypedOption<T> typedAttribute)
@@ -523,7 +478,7 @@ public static class ModdedOptionsManager
[Obsolete("Use PropertyGetterPatch<T> instead. This will be removed in a future version.")]
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
{
if (!GetterLookups.TryGetValue(__originalMethod.MethodHandle, out var attribute))
if (!GetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
return true;
__result = attribute.GetValue();
@@ -541,7 +496,7 @@ public static class ModdedOptionsManager
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
public static bool PropertyGetterPatch<T>(MethodBase __originalMethod, ref T __result)
{
if (!GetterLookups.TryGetValue(__originalMethod.MethodHandle, out var attribute))
if (!GetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
return true;
if (attribute is ITypedOption<T> typedAttribute)
@@ -43,6 +43,11 @@ public class ModdedNumberOption : ModdedOption<float>
/// </summary>
public string NegativeWordValue { get; }
/// <summary>
/// Gets the format string used to display the values.
/// </summary>
public string FormatString { get; }
/// <summary>
/// Gets a value indicating whether holding shift will divide the increment.
/// </summary>
@@ -92,6 +97,12 @@ public class ModdedNumberOption : ModdedOption<float>
ZeroWordValue = zeroBehavior;
ShiftIncrement = halfIncrements;
NegativeWordValue = negativeBehavior;
FormatString = formatString ??
(defaultValue.IsInteger() &&
Increment.IsInteger() &&
Value.IsInteger() &&
Min.IsInteger() &&
Max.IsInteger() ? "0" : "0.0");
Value = Mathf.Clamp(defaultValue, min, max);
@@ -101,12 +112,7 @@ public class ModdedNumberOption : ModdedOption<float>
data.Value = Value;
data.Increment = Increment;
data.ValidRange = new FloatRange(Min, Max);
data.FormatString = formatString ??
(defaultValue.IsInteger() &&
Increment.IsInteger() &&
Value.IsInteger() &&
Min.IsInteger() &&
Max.IsInteger() ? "0" : "0.0");
data.FormatString = FormatString;
data.ZeroIsInfinity = ZeroInfinity;
data.SuffixType = (NumberSuffixes)SuffixType;
@@ -223,7 +229,7 @@ public class ModdedNumberOption : ModdedOption<float>
numberOption.Value = Value;
numberOption.Increment = Increment;
numberOption.ValidRange = new FloatRange(Min, Max);
numberOption.FormatString = (Data as FloatGameSetting)?.FormatString ?? "0.0";
numberOption.FormatString = FormatString;
numberOption.ZeroIsInfinity = ZeroInfinity;
numberOption.SuffixType = (NumberSuffixes)SuffixType;
numberOption.floatOptionName = FloatOptionNames.Invalid;
+2 -2
View File
@@ -58,12 +58,12 @@ public class LocalSettingsButton(string text, Action onClick)
tmp.text = Text.Translate();
_btnText = tmp;
button.name = Text;
button.OnClick = new UnityEngine.UI.Button.ButtonClickedEvent();
rollover.OutColor = Tab!.TabAppearance.ButtonColor;
rollover.OverColor = Tab.TabAppearance.ButtonHoverColor;
rollover.Target = background;
background.color = Tab.TabAppearance.ButtonColor;
button.name = Text;
button.OnClick = new();
button.OnClick.AddListener((UnityAction)OnClick);
background.transform.localScale = new Vector3(1, 1.25f, 1);
+61 -44
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using BepInEx.Configuration;
using HarmonyLib;
using MiraAPI.Patches.LocalSettings;
@@ -126,7 +127,8 @@ public abstract class LocalSettingsTab(ConfigFile config)
/// <returns>The created tab <see cref="GameObject"/>.</returns>
public virtual GameObject CreateTab(OptionsMenuBehaviour instance)
{
var tab = Object.Instantiate(instance.transform.FindChild("GeneralTab").gameObject, instance.transform);
var genTab = instance.transform.FindChild("GeneralTab");
var tab = Object.Instantiate(genTab.gameObject, instance.transform);
tab.name = $"{TabName}Tab";
tab.transform.DestroyChildren();
tab.gameObject.SetActive(false);
@@ -143,25 +145,29 @@ public abstract class LocalSettingsTab(ConfigFile config)
TabButton.Content = tab.gameObject;
}
var generalLabel = instance.transform.FindChild("GeneralTab").FindChild("ControlGroup")
.FindChild("ControlText_TMP").gameObject;
var toggle = instance.transform.FindChild("GeneralTab").FindChild("ChatGroup").FindChild("CensorChatButton").GetComponent<ToggleButtonBehaviour>();
var slider = instance.transform.FindChild("GeneralTab").FindChild("SoundGroup").FindChild("SFXSlider").GetComponent<SlideBar>();
Dictionary<string, List<ILocalSetting>> entriesByGroup = [];
foreach (var entry in Settings)
{
var group = entry.ConfigEntry.Definition.Section;
if (!entriesByGroup.ContainsKey(group))
entriesByGroup.Add(group, []);
entriesByGroup[group].Add(entry);
if (!entriesByGroup.TryGetValue(group, out var list))
{
list = [];
entriesByGroup[group] = list;
}
list.Add(entry);
}
float contentOffset = 0;
var contentOffset = 0f;
var contentOrder = 1;
var contentIndex = 1;
var generalLabel = genTab.FindChild("ControlGroup").FindChild("ControlText_TMP").gameObject;
var toggle = genTab.FindChild("ChatGroup").FindChild("CensorChatButton").GetComponent<ToggleButtonBehaviour>();
var slider = genTab.FindChild("SoundGroup").FindChild("SFXSlider").GetComponent<SlideBar>();
foreach (var pair in entriesByGroup)
{
if (ShouldCreateLabels)
@@ -181,20 +187,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
ref contentOrder,
contentIndex == pair.Value.Count);
obj!.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
{
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
x.sortingOrder = 150;
x.sortingLayerName = "Default";
});
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
{
x.sortingOrder = 151;
x.sortingLayerName = "Default";
});
obj.GetComponentsInChildren<PassiveButton>().Do(x => { x.ClickMask = OptionsMenuPatches.MaskCollider; });
AdjustComponents(obj!);
contentIndex++;
}
@@ -204,6 +197,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
contentIndex = 1;
contentOrder = 1;
foreach (var button in Buttons)
{
var obj = button.CreateButton(
@@ -213,20 +207,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
ref contentOrder,
contentIndex == Buttons.Count);
obj.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
{
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
x.sortingOrder = 150;
x.sortingLayerName = "Default";
});
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
{
x.sortingOrder = 151;
x.sortingLayerName = "Default";
});
obj.GetComponentsInChildren<PassiveButton>().Do(x => { x.ClickMask = OptionsMenuPatches.MaskCollider; });
AdjustComponents(obj);
contentIndex++;
}
@@ -239,6 +220,24 @@ public abstract class LocalSettingsTab(ConfigFile config)
return tab;
}
private static void AdjustComponents(GameObject obj)
{
obj.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
{
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
x.sortingOrder = 150;
x.sortingLayerName = "Default";
});
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
{
x.sortingOrder = 151;
x.sortingLayerName = "Default";
});
obj.GetComponentsInChildren<PassiveButton>(true).Do(x => x.ClickMask = OptionsMenuPatches.MaskCollider);
}
/// <summary>
/// Creates the tab button.
/// </summary>
@@ -282,7 +281,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
var tabIndex = tabIdx; // Local copies of the tab variables so we can use them in the lambdas
var tabOffset = offset;
tabButton.OnClick.AddListener((UnityAction)(() => { instance.OpenTabGroup(tabIndex + 10); }));
tabButton.OnClick.AddListener((UnityAction)(() => instance.OpenTabGroup(tabIndex + 10)));
tabButton.OnMouseOver.AddListener((UnityAction)(() =>
{
tabButton.transform.localPosition = new Vector3(3.55f, 2.1f - tabOffset, 5.5f);
@@ -297,12 +296,13 @@ public abstract class LocalSettingsTab(ConfigFile config)
{
if (!tabButtonObject.Content.gameObject.activeSelf)
{
// tabButtonObject.Button.color = TabColor;
// tabButtonObject.Rollover.OutColor = TabColor;
tabButtonObject.Button.color = TabAppearance.TabColor;
tabButtonObject.Rollover.OutColor = TabAppearance.TabColor;
}
tabButton.transform.localPosition = new Vector3(2.4f, 2.1f - tabOffset, 5.5f);
tabButtonText.alignment = TextAlignmentOptions.Right;
if (tabButtonRend != null)
{
tabButtonRend.gameObject.SetActive(true);
@@ -338,8 +338,25 @@ public abstract class LocalSettingsTab(ConfigFile config)
internal static string GetShortName(string name)
{
var shortName = string.Empty;
name.Split(' ').Do(x => shortName += x[0]);
return shortName;
if (string.IsNullOrEmpty(name))
return string.Empty;
var sb = new StringBuilder();
var nextIsWord = true;
foreach (char c in name)
{
if (c == ' ')
{
nextIsWord = true;
}
else if (nextIsWord)
{
sb.Append(c);
nextIsWord = false;
}
}
return sb.ToString();
}
}
@@ -20,13 +20,8 @@ namespace MiraAPI.LocalSettings.SettingTypes;
/// <param name="name">The name of the setting.</param>
/// <param name="description">The description of the setting.</param>
/// <param name="values">The optional values array to replace the <see langword="enum"/> names.</param>
public class LocalEnumSetting(
Type tab,
ConfigEntryBase configEntry,
Type enumType,
string? name = null,
string? description = null,
string[]? values = null) : LocalSettingBase<int>(tab, configEntry, name, description)
public class LocalEnumSetting(Type tab, ConfigEntryBase configEntry, Type enumType, string? name = null, string? description = null, string[]? values = null)
: LocalSettingBase<int>(tab, configEntry, name, description)
{
/// <summary>
/// Gets the <see cref="Enum"/> type of the setting.
@@ -62,7 +57,7 @@ public class LocalEnumSetting(
var highlight = button.transform.FindChild("ButtonHighlight")?.GetComponent<SpriteRenderer>();
if (highlight != null)
{
this._highlight = highlight;
_highlight = highlight;
highlight.color = Tab!.TabAppearance.EnumHoverColor;
highlight.gameObject.SetActive(false);
}
@@ -375,12 +375,7 @@ internal static class GameOptionsMenuPatch
foreach (var mode in CustomGameModeManager.IdToModeMap.Values)
{
var filteredGroups =
ModdedOptionsManager.GameModeOptionGroups
.Where(x => x.Key == mode.GetType())
.Select(y => y.Value)
.SelectMany(y => y)
.ToList();
var filteredGroups = ModdedOptionsManager.GameModeOptionGroups.GetValueOrDefault(mode.GetType(), []);
GameModeGroups.Add(mode, [.. filteredGroups]);
var optionBehaviours = new List<OptionBehaviour>();
+2 -5
View File
@@ -183,12 +183,9 @@ public static class Helpers
/// <param name="amount">How much you want to divide by.</param>
public static void DivideSize(GameObject obj, float amount)
{
foreach (var collider in obj.GetComponentsInChildren<Collider2D>(true))
foreach (var col in obj.GetComponentsInChildren<BoxCollider2D>(true))
{
if (collider.TryCast<BoxCollider2D>() is { } col)
{
col.size = new Vector2(col.size.x / amount, col.size.y);
}
col.size = new Vector2(col.size.x / amount, col.size.y);
}
foreach (var rend in obj.GetComponentsInChildren<SpriteRenderer>(true))