public static void InitializePage(FloatingHoldable holdable) { Selectable holdableSelectable = holdable.GetComponent <Selectable>(); var currentPage = holdable.GetComponentsInChildren <Selectable>(false).FirstOrDefault(x => x != holdableSelectable); _currentSelectable = currentPage?.GetCurrentChild(); _currentSelectable?.HandleSelect(true); _currentSelectables = currentPage?.Children; _currentSelectableIndex = _currentSelectables?.IndexOf(sel => sel == _currentSelectable) ?? -1; }
public TwitchHoldable(FloatingHoldable holdable, Type commandType = null, bool allowModded = false, string id = null) { Holdable = holdable; CommandType = commandType; _defaultId = id ?? holdable.name.ToLowerInvariant().Replace("(clone)", ""); if (TwitchGame.BombActive) { var gameCommands = holdable.GetComponent <KMGameCommands>(); if (gameCommands != null) { gameCommands.OnCauseStrike += OnStrike; } } if (allowModded) { // Find a suitable ProcessTwitchCommand method foreach (var component in holdable.GetComponentsInChildren <Component>(true)) { if (component == null) { continue; } var type = component.GetType(); var candidateMethod = type.GetMethod("ProcessTwitchCommand", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (candidateMethod == null) { continue; } if (ValidateMethodCommandMethod(type, candidateMethod)) { HandlerMethod = candidateMethod; CommandComponent = component; HelpMessageField = type.GetField("TwitchHelpMessage", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); // Find a suitable TwitchShouldCancelCommand boolean field FieldInfo f; if ((f = type.GetField("TwitchShouldCancelCommand", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) != null && f.FieldType == typeof(bool)) { CancelBool = f; } break; } } if (HandlerMethod == null) { // No method found. LogAllComponentTypes(holdable); } } }