Exemplo n.º 1
0
        protected virtual void LoadCharacters()
        {
            CacheCharacterSelectionManager.Clear();
            // Unenabled buttons
            buttonStart.gameObject.SetActive(false);
            buttonDelete.gameObject.SetActive(false);
            // Remove all models
            characterModelContainer.RemoveChildren();
            CharacterModelById.Clear();
            // Remove all cached data
            PlayerCharacterDataById.Clear();
            // Show list of created characters
            List <PlayerCharacterData> selectableCharacters = PlayerCharacterDataExtension.LoadAllPersistentCharacterData();

            for (int i = selectableCharacters.Count - 1; i >= 0; --i)
            {
                PlayerCharacterData selectableCharacter = selectableCharacters[i];
                if (selectableCharacter == null || !GameInstance.PlayerCharacters.ContainsKey(selectableCharacter.DataId))
                {
                    selectableCharacters.RemoveAt(i);
                }
            }
            selectableCharacters.Sort(new PlayerCharacterDataLastUpdateComparer().Desc());
            CacheCharacterList.Generate(selectableCharacters, (index, characterData, ui) =>
            {
                // Cache player character to dictionary, we will use it later
                PlayerCharacterDataById[characterData.Id] = characterData;
                // Setup UIs
                UICharacter uiCharacter = ui.GetComponent <UICharacter>();
                uiCharacter.Data        = characterData;
                // Select trigger when add first entry so deactivate all models is okay beacause first model will active
                BaseCharacterModel characterModel = characterData.InstantiateModel(characterModelContainer);
                if (characterModel != null)
                {
                    CharacterModelById[characterData.Id] = characterModel;
                    characterModel.gameObject.SetActive(false);
                    characterModel.SetEquipWeapons(characterData.EquipWeapons);
                    characterModel.SetEquipItems(characterData.EquipItems);
                    characterModel.UpdateAnimation(false, MovementState.IsGrounded);
                    CacheCharacterSelectionManager.Add(uiCharacter);
                }
            });
        }
Exemplo n.º 2
0
        protected virtual void LoadCharacters()
        {
            SelectionManager.Clear();
            // Unenabled buttons
            buttonStart.gameObject.SetActive(false);
            buttonDelete.gameObject.SetActive(false);
            // Remove all models
            characterModelContainer.RemoveChildren();
            CharacterModels.Clear();
            // Show list of created characters
            var selectableCharacters = PlayerCharacterDataExtension.LoadAllPersistentCharacterData();

            for (var i = selectableCharacters.Count - 1; i >= 0; --i)
            {
                var selectableCharacter = selectableCharacters[i];
                if (selectableCharacter == null || !GameInstance.PlayerCharacters.ContainsKey(selectableCharacter.DataId))
                {
                    selectableCharacters.RemoveAt(i);
                }
            }
            selectableCharacters.Sort(new PlayerCharacterDataLastUpdateComparer().Desc());
            CacheList.Generate(selectableCharacters, (index, character, ui) =>
            {
                var uiCharacter  = ui.GetComponent <UICharacter>();
                uiCharacter.Data = character;
                // Select trigger when add first entry so deactivate all models is okay beacause first model will active
                var characterModel = character.InstantiateModel(characterModelContainer);
                if (characterModel != null)
                {
                    CharacterModels[character.Id] = characterModel;
                    characterModel.gameObject.SetActive(false);
                    characterModel.SetEquipWeapons(character.EquipWeapons);
                    characterModel.SetEquipItems(character.EquipItems);
                    SelectionManager.Add(uiCharacter);
                }
            });
        }