Пример #1
0
        protected virtual void LoadCharacters()
        {
            // Remove all models
            characterModelContainer.RemoveChildren();
            CharacterModelByEntityId.Clear();
            // Remove all cached data
            PlayerCharacterDataByEntityId.Clear();
            // Clear character selection
            CacheCharacterSelectionManager.Clear();
            CacheCharacterList.HideAll();
            // Show list of characters that can be create
            PlayerCharacterData firstData = null;
            List <BasePlayerCharacterEntity> selectableCharacters = GetCreatableCharacters();

            CacheCharacterList.Generate(selectableCharacters, (index, characterEntity, ui) =>
            {
                // Cache player character to dictionary, we will use it later
                PlayerCharacterDataByEntityId[characterEntity.EntityId] = characterEntity.playerCharacters;
                // Prepare data
                BaseCharacter playerCharacter           = characterEntity.playerCharacters[0];
                PlayerCharacterData playerCharacterData = new PlayerCharacterData();
                playerCharacterData.SetNewPlayerCharacterData(characterEntity.characterTitle, playerCharacter.DataId, characterEntity.EntityId);
                // Hide all model, the first one will be shown later
                BaseCharacterModel characterModel = playerCharacterData.InstantiateModel(characterModelContainer);
                CharacterModelByEntityId[playerCharacterData.EntityId] = characterModel;
                characterModel.gameObject.SetActive(false);
                characterModel.UpdateAnimation(false, MovementState.IsGrounded);
                // Setup UI
                if (ui != null)
                {
                    UICharacter uiCharacter = ui.GetComponent <UICharacter>();
                    uiCharacter.Data        = playerCharacterData;
                    CacheCharacterSelectionManager.Add(uiCharacter);
                }
                if (index == 0)
                {
                    firstData = playerCharacterData;
                }
            });
            // Select first entry
            if (CacheCharacterSelectionManager.Count > 0)
            {
                CacheCharacterSelectionManager.Select(0);
            }
            else
            {
                OnSelectCharacter(firstData);
            }
        }
Пример #2
0
 public override void Show()
 {
     buttonStart.onClick.RemoveListener(OnClickStart);
     buttonStart.onClick.AddListener(OnClickStart);
     buttonDelete.onClick.RemoveListener(OnClickDelete);
     buttonDelete.onClick.AddListener(OnClickDelete);
     // Clear selection
     CacheCharacterSelectionManager.eventOnSelect.RemoveListener(OnSelectCharacter);
     CacheCharacterSelectionManager.eventOnSelect.AddListener(OnSelectCharacter);
     CacheCharacterSelectionManager.Clear();
     CacheCharacterList.HideAll();
     // Unenabled buttons
     buttonStart.gameObject.SetActive(false);
     buttonDelete.gameObject.SetActive(false);
     // Load characters
     LoadCharacters();
     base.Show();
 }
Пример #3
0
        private void OnRequestedCharacters(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseCharactersMessage response)
        {
            // Clear character list
            CacheCharacterSelectionManager.Clear();
            CacheCharacterList.HideAll();
            // Unable buttons
            buttonStart.gameObject.SetActive(false);
            buttonDelete.gameObject.SetActive(false);
            // Remove all models
            characterModelContainer.RemoveChildren();
            CharacterModelById.Clear();
            // Remove all cached data
            PlayerCharacterDataById.Clear();
            // Proceed response
            List <PlayerCharacterData> selectableCharacters = new List <PlayerCharacterData>();

            if (!responseCode.ShowUnhandledResponseMessageDialog(response.message))
            {
                // Success, so set selectable characters by response's data
                selectableCharacters = response.characters;
            }
            // Show list of created characters
            for (int i = selectableCharacters.Count - 1; i >= 0; --i)
            {
                PlayerCharacterData selectableCharacter = selectableCharacters[i];
                if (selectableCharacter == null ||
                    !GameInstance.PlayerCharacterEntities.ContainsKey(selectableCharacter.EntityId) ||
                    !GameInstance.PlayerCharacters.ContainsKey(selectableCharacter.DataId))
                {
                    // If invalid entity id or data id, remove from selectable character list
                    selectableCharacters.RemoveAt(i);
                }
            }

            if (GameInstance.Singleton.maxCharacterSaves > 0 &&
                selectableCharacters.Count >= GameInstance.Singleton.maxCharacterSaves)
            {
                eventOnNotAbleToCreateCharacter.Invoke();
            }
            else
            {
                eventOnAbleToCreateCharacter.Invoke();
            }

            // Clear selected character data, will select first in list if available
            selectedPlayerCharacterData = null;

            // Generate list entry by saved characters
            if (selectableCharacters.Count > 0)
            {
                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.SetEquipWeapons(characterData.EquipWeapons);
                        characterModel.SetEquipItems(characterData.EquipItems);
                        characterModel.gameObject.SetActive(false);
                        CacheCharacterSelectionManager.Add(uiCharacter);
                    }
                });
            }
            else
            {
                eventOnNoCharacter.Invoke();
            }
        }
Пример #4
0
        private void OnRequestedCharacters(AckResponseCode responseCode, BaseAckMessage message)
        {
            ResponseCharactersMessage castedMessage = (ResponseCharactersMessage)message;

            CacheCharacterSelectionManager.Clear();
            CacheCharacterList.HideAll();
            // Unenabled buttons
            buttonStart.gameObject.SetActive(false);
            buttonDelete.gameObject.SetActive(false);
            // Remove all models
            characterModelContainer.RemoveChildren();
            CharacterModelById.Clear();
            // Remove all cached data
            PlayerCharacterDataById.Clear();

            List <PlayerCharacterData> selectableCharacters = new List <PlayerCharacterData>();

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedMessage.error)
                {
                case ResponseCharactersMessage.Error.NotLoggedin:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_NOT_LOGGED_IN.ToString());
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), errorMessage);
                break;

            case AckResponseCode.Timeout:
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UITextKeys.UI_ERROR_CONNECTION_TIMEOUT.ToString()));
                break;

            default:
                selectableCharacters = castedMessage.characters;
                break;
            }

            // Show list of created characters
            for (int i = selectableCharacters.Count - 1; i >= 0; --i)
            {
                PlayerCharacterData selectableCharacter = selectableCharacters[i];
                if (selectableCharacter == null ||
                    !GameInstance.PlayerCharacterEntities.ContainsKey(selectableCharacter.EntityId) ||
                    !GameInstance.PlayerCharacters.ContainsKey(selectableCharacter.DataId))
                {
                    // If invalid entity id or data id, remove from selectable character list
                    selectableCharacters.RemoveAt(i);
                }
            }

            if (GameInstance.Singleton.maxCharacterSaves > 0 &&
                selectableCharacters.Count >= GameInstance.Singleton.maxCharacterSaves)
            {
                eventOnNotAbleToCreateCharacter.Invoke();
            }
            else
            {
                eventOnAbleToCreateCharacter.Invoke();
            }

            if (selectableCharacters.Count > 0)
            {
                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.SetEquipWeapons(characterData.EquipWeapons);
                        characterModel.SetEquipItems(characterData.EquipItems);
                        characterModel.gameObject.SetActive(false);
                        CacheCharacterSelectionManager.Add(uiCharacter);
                    }
                });
            }
            else
            {
                eventOnNoCharacter.Invoke();
            }
        }