Beispiel #1
0
        protected virtual void OnClickStart()
        {
            UICharacter selectedUI = CacheCharacterSelectionManager.SelectedUI;

            if (selectedUI == null)
            {
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UILocaleKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UILocaleKeys.UI_ERROR_NO_CHOSEN_CHARACTER_TO_START.ToString()));
                Debug.LogWarning("Cannot start game, No chosen character");
                return;
            }
            // Load gameplay scene, we're going to manage maps in gameplay scene later
            // So we can add gameplay UI just once in gameplay scene
            PlayerCharacterData  characterData   = new PlayerCharacterData();
            IPlayerCharacterData playerCharacter = selectedUI.Data as IPlayerCharacterData;

            playerCharacter.CloneTo(characterData);
            GameInstance         gameInstance   = GameInstance.Singleton;
            LanRpgNetworkManager networkManager = BaseGameNetworkManager.Singleton as LanRpgNetworkManager;

            if (!gameInstance.GetGameMapIds().Contains(characterData.CurrentMapName))
            {
                MapInfo startMap = (characterData.GetDatabase() as PlayerCharacter).StartMap;
                characterData.CurrentMapName  = startMap.Id;
                characterData.CurrentPosition = startMap.startPosition;
            }
            networkManager.Assets.onlineScene.SceneName = characterData.CurrentMapName;
            networkManager.selectedCharacter            = characterData;
            networkManager.StartGame();
        }
        protected virtual void OnSelectCharacter(UICharacter ui)
        {
            buttonStart.gameObject.SetActive(true);
            buttonDelete.gameObject.SetActive(true);
            characterModelContainer.SetChildrenActive(false);
            var playerCharacter = ui.Data as IPlayerCharacterData;

            ShowCharacter(playerCharacter.Id);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        protected virtual void OnClickDelete()
        {
            UICharacter selectedUI = CacheCharacterSelectionManager.SelectedUI;

            if (selectedUI == null)
            {
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UILocaleKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UILocaleKeys.UI_ERROR_NO_CHOSEN_CHARACTER_TO_DELETE.ToString()));
                Debug.LogWarning("Cannot delete character, No chosen character");
                return;
            }

            IPlayerCharacterData playerCharacter = selectedUI.Data as IPlayerCharacterData;

            playerCharacter.DeletePersistentCharacterData();
            // Reload characters
            LoadCharacters();
        }
Beispiel #5
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);
                }
            });
        }
Beispiel #6
0
 protected void OnSelectCharacter(UICharacter uiCharacter)
 {
     OnSelectCharacter(uiCharacter.Data as IPlayerCharacterData);
 }
 protected virtual void OnSelectCharacter(UICharacter ui)
 {
     characterModelContainer.SetChildrenActive(false);
     ShowCharacter(ui.Data.EntityId);
 }