Пример #1
0
    // remember to use StartCoroutine when calling this function!
    // this is only ever called after a user is logged in, there is no way to save a monster
    // without having logged in, however, there should be a way to output monsters made by guests.
    public static IEnumerator SaveMonster(string monsterJSON, TMP_Dropdown creationsDropdown)
    {
        //This connects to a server side php script that will add the String and score to a MySQL DB.
        // Supply it with a string representing the players String and the players score.
        string hash = MD5.Md5Sum(currentUser + currentProfile + monsterJSON + secretKey);

        List <IMultipartFormSection> formData = new List <IMultipartFormSection>();

        formData.Add(new MultipartFormDataSection("User", currentUser));
        formData.Add(new MultipartFormDataSection("Profile", currentProfile));
        formData.Add(new MultipartFormDataSection("Monster", monsterJSON));
        formData.Add(new MultipartFormDataSection("hash", hash));

        UnityWebRequest monster_post = UnityWebRequest.Post(SaveMonsterURL, formData);

        yield return(monster_post.SendWebRequest());

        if (monster_post.error != null)
        {
            Debug.Log("There was an error saving the model: " + monster_post.error);
        }
        else
        {
            Debug.Log(monster_post.downloadHandler.text);
            MonsterJSON   savedCreation = JsonUtility.FromJson <MonsterJSON>(monsterJSON);
            List <string> savedName     = new List <string>();
            savedName.Add(savedCreation.charName);
            creationsDropdown.AddOptions(savedName);
        }
    }
Пример #2
0
    // remember to use StartCoroutine when calling this function!
    public static IEnumerator FetchMonsters(TMP_Dropdown creationsDropdown)
    {
        creationsDropdown.ClearOptions();
        // loads model that matches the current user, profile and specified monster name
        string hash = MD5.Md5Sum(currentUser + currentProfile + secretKey);

        List <IMultipartFormSection> formData = new List <IMultipartFormSection>();

        formData.Add(new MultipartFormDataSection("User", currentUser));
        formData.Add(new MultipartFormDataSection("Profile", currentProfile));
        formData.Add(new MultipartFormDataSection("hash", hash));

        UnityWebRequest monster_post = UnityWebRequest.Post(FetchMonsterURL, formData);

        yield return(monster_post.SendWebRequest());

        if (monster_post.error != null)
        {
            Debug.Log("There was an error loading your creations: " + monster_post.error);
        }
        else
        {
            Debug.Log(monster_post.downloadHandler.text);
            string []          creations      = monster_post.downloadHandler.text.Split('\t');
            List <string>      creationNames  = new List <string>();
            List <MonsterJSON> creationImport = new List <MonsterJSON>();
            foreach (string json in creations)
            {
                if ("END!" == json)
                {
                    break;
                }
                MonsterJSON loadedMonster = JsonUtility.FromJson <MonsterJSON>(json);
                Debug.Log(loadedMonster.charName);
                creationNames.Add(loadedMonster.charName);
                Debug.Log(creationNames[0]);
                creationImport.Add(loadedMonster);
            }
            creationsDropdown.AddOptions(creationNames);
            setCreations(creationImport);
        }
    }
    public void SaveCharacter()
    {
        MonsterJSON saveMon = new MonsterJSON();

        saveMon.baseCharacter   = characters[characterDropdown.value];
        saveMon.charName        = customNameField.text;
        saveMon.bodyColour      = colours[bodyColourDropdown.value];
        saveMon.hasAccessory    = accessory;
        saveMon.accessoryColour = colours[accessoryColourDropdown.value];
        saveMon.shoeColour      = colours[shoeColourDropdown.value];
        Debug.Log(characters[characterDropdown.value] + " "
                  + customNameField.text + " "
                  + colours[bodyColourDropdown.value] + " "
                  + accessory + " "
                  + colours[accessoryColourDropdown.value] + " "
                  + colours[shoeColourDropdown.value]);
        string monster = JsonUtility.ToJson(saveMon);

        Debug.Log(monster);
        StartCoroutine(ServerConnect.SaveMonster(monster, creationsDropdown));
    }
Пример #4
0
 public static void addCreations(MonsterJSON newCreation)
 {
     currentCreationList.Add(newCreation);
 }