Beispiel #1
0
        public void OnCharacterReceived(UICharacterDetails characterDetails)
        {
            var path          = Utils.GetCharacterPath(characterDetails);
            var characterView = CreateAndShowCharacterView(path);

            if (characterView != null)
            {
                characterView.Id             = characterDetails.GetCharacterId();
                characterView.CharacterName  = characterDetails.GetCharacterName();
                characterView.CharacterIndex = characterDetails.GetCharacterIndex();
                characterView.CharacterClass = characterDetails.GetCharacterClass();

                var characterIndex = characterDetails.GetCharacterIndex();
                if (characterIndex != UICharacterIndex.Zero)
                {
                    if (characterViewCollection == null)
                    {
                        var views =
                            new IClickableCharacterView[] { null, null, null };
                        characterViewCollection =
                            new CharacterViewCollection(views);
                    }

                    var index = (int)characterIndex;
                    characterViewCollection?.Set(index, characterView);
                }
            }
        }
Beispiel #2
0
        public static string GetCharacterPath(UICharacterDetails characterDetails)
        {
            var characterClass = characterDetails.GetCharacterClass();
            var characterIndex = characterDetails.GetCharacterIndex();
            var name           = $"{characterClass} {(int)characterIndex}";

            return(string.Format(Paths.Resources.Sample.Characters, name));
        }
Beispiel #3
0
        private void OnGetCharactersCallback(long statusCode, string json)
        {
            var characters = GetSampleCharacterData();

            // Hack: "[]"
            if (json != "[]")
            {
                CharacterData[] characterData;

                // NOTE: Unity json allows getting "Items" only (from dummy api)
                if (json.Contains("Items"))
                {
                    characterData = JsonHelper.FromJsonString <CharacterData>(json);
                }
                else
                {
                    characterData = JsonHelper.ArrayFromJson <CharacterData>(json);
                }

                if (characterData != null && characterData.Length != 0)
                {
                    // Replaces sample character with existing characters
                    foreach (var character in characterData)
                    {
                        var index = character.index;

                        characters[index].id            = character.id;
                        characters[index].charactername = character.charactername;
                        characters[index].classindex    = character.classindex;
                    }
                }
            }

            // Create samples and/or existing characters
            foreach (var character in characters)
            {
                var id                 = character.id;
                var name               = character.charactername;
                var index              = (UICharacterIndex)character.index;
                var classindex         = (UICharacterClass)character.classindex;
                var uiCharacterDetails =
                    new UICharacterDetails(id, name, index, classindex);

                onCharacterReceivedListener.OnCharacterReceived(uiCharacterDetails);
            }

            onCharacterReceivedListener.OnAfterCharacterReceived();
        }