示例#1
0
    private void OnClickCreate()
    {
        var gameInstance = GameInstance.Singleton;
        var selectedUI   = SelectionManager.SelectedUI;

        if (selectedUI == null)
        {
            UISceneGlobal.Singleton.ShowMessageDialog("Cannot create character", "Please select character class");
            Debug.LogWarning("Cannot create character, did not selected character class");
            return;
        }
        var dataId                 = selectedUI.dataId;
        var characterName          = inputCharacterName.text.Trim();
        var minCharacterNameLength = gameInstance.minCharacterNameLength;
        var maxCharacterNameLength = gameInstance.maxCharacterNameLength;

        if (characterName.Length < minCharacterNameLength)
        {
            UISceneGlobal.Singleton.ShowMessageDialog("Cannot create character", "Character name is too short");
            Debug.LogWarning("Cannot create character, character name is too short");
            return;
        }
        if (characterName.Length > maxCharacterNameLength)
        {
            UISceneGlobal.Singleton.ShowMessageDialog("Cannot create character", "Character name is too long");
            Debug.LogWarning("Cannot create character, character name is too long");
            return;
        }

        var characterId   = GenericUtils.GetUniqueId();
        var characterData = new PlayerCharacterData();

        characterData.Id = characterId;
        characterData.SetNewCharacterData(characterName, dataId);
        characterData.SavePersistentCharacterData();

        if (eventOnCreateCharacter != null)
        {
            eventOnCreateCharacter.Invoke();
        }
    }