示例#1
0
        public static IEnumerator EquipItem(CharacterInternal character, Equipment equipment, Action callback)
        {
            string  url   = string.Format("https://backend.josiahkhoo.me/api/equipments/{0}", equipment.id.ToString());
            string  token = string.Format("Token {0}", PlayerPrefs.GetString("token", "").ToString());
            WWWForm form  = new WWWForm();

            form.AddField("character_id", character.id);
            using (var request = UnityWebRequest.Post(url, form))
            {
                request.SetRequestHeader("Authorization", token);
                yield return(request.SendWebRequest());

                var response = JSON.Parse(request.downloadHandler.text);
                if (request.responseCode == 200)
                {
                    var characterJson = response["data"]["character"];
                    CharacterInternal characterInternal = GetCharacterFromString(characterJson.ToString());
                    StaticClass.SelectedCharacter = characterInternal;
                }
                if (callback != null)
                {
                    callback();
                }
            }
        }
示例#2
0
 // Start is called before the first frame update
 void Start()
 {
     characterInternal = StaticClass.SelectedCharacter;
     CharacterManager.InstantiateCharacterObject(CharacterObject, characterInternal);
     EquipmentManager.RenderHelmetFromCharacterConfig(Helmet, characterInternal);
     EquipmentManager.RenderArmourFromCharacterConfig(Armour, characterInternal);
     EquipmentManager.RenderShieldFromCharacterConfig(Shield, characterInternal);
     EquipmentManager.RenderWeaponFromCharacterConfig(Weapon, characterInternal);
     Name.text = characterInternal.name;
 }
示例#3
0
        public static CharacterInternal GetCharacterFromString(string characterString)
        {
            var               characterJson    = JSON.Parse(characterString);
            int               characterId      = characterJson["id"];
            string            name             = characterJson["name"];
            var               appearanceConfig = characterJson["appearance_config"];
            bool              isActive         = characterJson["is_active"];
            CharacterInternal character        = new CharacterInternal(characterId, name, appearanceConfig.ToString(), isActive);

            return(character);
        }
示例#4
0
 public static void InstantiateCharacterObject(GameObject CharacterObject, CharacterInternal characterInternal)
 {
     if (Storage.User == null || StaticClass.SelectedCharacter == null)
     {
         SceneManager.LoadScene("Login Page");
     }
     else
     {
         if (characterInternal == null)
         {
             characterInternal = StaticClass.SelectedCharacter;
         }
         Assets.HeroEditor.Common.CharacterScripts.Character character = CharacterObject.GetComponent <Assets.HeroEditor.Common.CharacterScripts.Character>();
         character.LoadFromJson(characterInternal.appearanceConfig.ToString());
     }
 }