コード例 #1
0
        public void RandomizeCharacter()
        {
            if ((!PreGameController.instance || !PreGameController.instance.IsCharacterSwitchingCurrentlyAllowed() || !characterSelectController) && !eclipseRunScreenController)
            {
                return;
            }

            var localUser              = ((MPEventSystem)EventSystem.current).localUser;
            var currentIndex           = characterSelectController?.selectedSurvivorIndex ?? (SurvivorIndex)EclipseRun.cvEclipseSurvivorIndex.value;
            var canSelectSameCharacter = ConfigHelper.CanSelectSameCharacter.Value;
            var survivors              = SurvivorCatalog.orderedSurvivorDefs.Where(survivorDef => (canSelectSameCharacter || currentIndex != survivorDef.survivorIndex) && !survivorDef.hidden && SurvivorCatalog.SurvivorIsUnlockedOnThisClient(survivorDef.survivorIndex));
            var randomIndex            = survivors.ElementAt(UnityEngine.Random.Range(0, survivors.Count())).survivorIndex;

            if (characterSelectController)
            {
                characterSelectController.SelectSurvivor(randomIndex);
                characterSelectController.SetSurvivorInfoPanelActive(true);
            }
            if (eclipseRunScreenController)
            {
                eclipseRunScreenController.SelectSurvivor(randomIndex);
            }
            if (RandomCharacterSelectionPlugin.ScrollableLobbyUILoaded)
            {
                ScrollableLobbyUISelectCharacter(randomIndex);
            }
            localUser.currentNetworkUser?.CallCmdSetBodyPreference(BodyCatalog.FindBodyIndex(SurvivorCatalog.GetSurvivorDef(randomIndex).bodyPrefab));
        }
        private void RebuildPage()
        {
            var survivorIndicies = survivorIndexList.Skip(currentPageIndex * survivorsPerPage).Take(survivorsPerPage).ToArray();

            var elements = survivorIconControllers.elements;

            for (var index = 0; index < elements.Count; ++index)
            {
                var element = elements[index];
                if (index >= survivorIndicies.Length)
                {
                    element.gameObject.SetActive(false);
                    continue;
                }
                element.gameObject.SetActive(true);

                var survivorIndex = survivorIndicies[index];
                var survivorDef   = SurvivorCatalog.GetSurvivorDef(survivorIndex);
                element.survivorIndex = survivorIndex;
                var buttonComponent = element.GetComponent <HGButton>();

                var survivorDescription = Language.GetString(survivorDef.descriptionToken);
                var length = survivorDescription.IndexOf(Environment.NewLine);
                if (length != -1)
                {
                    survivorDescription = survivorDescription.Substring(0, length);
                }

                var unlockableDef = UnlockableCatalog.GetUnlockableDef(survivorDef.unlockableName);
                if (unlockableDef != null)
                {
                    if (SurvivorCatalog.SurvivorIsUnlockedOnThisClient(survivorIndex))
                    {
                        buttonComponent.hoverToken = Language.GetStringFormatted("CHARACTER_DESCRIPTION_AND_UNLOCK_FORMAT", survivorDescription, unlockableDef.getUnlockedString());
                    }
                    else
                    {
                        buttonComponent.hoverToken = Language.GetStringFormatted("CHARACTER_DESCRIPTION_AND_UNLOCK_FORMAT", Language.GetString("UNIDENTIFIED"), unlockableDef.getHowToUnlockString());
                    }
                }
                else
                {
                    buttonComponent.hoverToken = survivorDescription;
                }
                element.shouldRebuild = true;
            }

            for (var index = 0; index < fillerCount; index++)
            {
                fillerIcons[index].gameObject.SetActive(IsOnLastPage);
            }

            if (buttonHistory && buttonHistory.lastRememberedGameObject)
            {
                if (eventSystemLocator && eventSystemLocator.eventSystem)
                {
                    if (eventSystemLocator.eventSystem.currentInputSource == MPEventSystem.InputSource.Gamepad)
                    {
                        if (buttonHistory.lastRememberedGameObject.activeInHierarchy)
                        {
                            buttonHistory.lastRememberedGameObject.GetComponent <HGButton>().OnSelect(new BaseEventData(EventSystem.current));
                        }
                        else
                        {
                            elements.LastOrDefault(el => el.gameObject.activeInHierarchy)?.GetComponent <HGButton>().Select();
                        }
                    }
                }
            }

            previousButtonComponent.interactable = !IsOnFirstPage;
            nextButtonComponent.interactable     = !IsOnLastPage;
        }