예제 #1
0
    IEnumerator GetRequest(string url)
    {
        UnityWebRequest webRequest       = UnityWebRequest.Get(url);
        levelInfo       levelInfoCurrent = new levelInfo();

        yield return(webRequest.SendWebRequest());

        //string[] jsonList = JsonUtility. (webRequest.downloadHandler.text);
        List <string> jsonList = GetJsonParse(webRequest.downloadHandler.text);

        foreach (string jsonItem in jsonList)
        {
            Debug.Log(jsonItem);
            levelInfoCurrent = levelInfo.CreateFromJson(jsonItem);

            CreateButton(levelInfoCurrent.id, levelInfoCurrent.imageurl);
        }
        if (webRequest.isNetworkError)
        {
            Debug.Log(": Error: " + webRequest.error);
        }
        else
        {
            Debug.Log(":\nReceived: " + webRequest.downloadHandler.text);

            /*string jsonString = webRequest.downloadHandler.text.Replace("[", "").Replace("]", "");
             * levelInfo levelInstance = levelInfo.CreateFromJson(jsonString);
             * Debug.Log(levelInstance.id);*/
        }
    }
예제 #2
0
    IEnumerator GetIdRequest(string url, string ID)
    {
        UnityWebRequest webRequest = UnityWebRequest.Get(url + "/" + ID);

        yield return(webRequest.SendWebRequest());

        if (webRequest.isNetworkError)
        {
            Debug.Log(": Error: " + webRequest.error);
        }
        else
        {
            Debug.Log(":\nReceived: " + webRequest.downloadHandler.text);
        }
        //remove "[]" from json format
        string jsonString = webRequest.downloadHandler.text.Replace("[", "").Replace("]", "");

        Debug.Log("Res : " + (webRequest.downloadHandler.text));
        List <string> jsonList = GetJsonParse(webRequest.downloadHandler.text);

        //Convert {"field1":"myfield1", ...} to field1=myfield1 ... variables in a class
        levelInfo levelInstance = levelInfo.CreateFromJson(jsonList[0]);

        Debug.Log(levelInstance.leveltext);

        PublicLevel.id        = levelInstance.id;
        PublicLevel.sceneText = levelInstance.leveltext;
        PublicLevel.highScore = levelInstance.highscore;

        SceneManager.LoadScene("BaseScene");
    }
예제 #3
0
    //自定义的属性数据在这里读取
    void LoadLevelPropertiesJsonData(String Jsondata)
    {
        JsonObject Jobj = SimpleJson.SimpleJson.DeserializeObject <JsonObject> (Jsondata);
        // Debug.Log(jsonObject);

        levelInfo info = allData[curLevel];

        info.oneStarScore   = int.Parse(Jobj.GetString("OneStart"));
        info.twoStarScore   = int.Parse(Jobj.GetString("TwoStart"));
        info.threeStarScore = int.Parse(Jobj.GetString("ThreeStart"));
        info.rowStart       = int.Parse(Jobj.GetString("RowStart"));

        if (!int.TryParse(Jobj.GetString("ballStartNum"), out info.ballStartNum))
        {
            info.ballStartNum = 1;
        }

        if (!float.TryParse(Jobj.GetString("blockScale"), out info.blockScale))
        {
            info.blockScale = 1;
        }

        if (!int.TryParse(Jobj.GetString("maxCol"), out info.maxCol))
        {
            info.maxCol = 7;
        }
    }
예제 #4
0
    JSONNode CrateThisLevel(levelInfo level)
    {
        JSONClass N = new JSONClass();

        N ["supportCount"].AsInt = level.supportCount;
        N ["soldeirCount"].AsInt = level.supportCount;
        return(N);
    }
예제 #5
0
    // Start is called before the first frame update
    void Start()
    {
        info = GameObject.FindObjectOfType <levelInfo>();

        downSpeed = -1.5f;
        //Destroy(gameObject);
        rb          = GetComponent <Rigidbody>();
        rb.velocity = new Vector3(0f, downSpeed, 0f);
    }
예제 #6
0
 public void setLevel(int level)
 {
     if (!allData.ContainsKey(level))
     {
         curLevel = level;
         string path = "LevelData/Level" + level;
         LoadLevelUsingPath(path);
     }
     curLevelData = allData[level];
 }
예제 #7
0
    // Method that loads one layer
    void LoadLevelFromString(int layer, string content)
    {
        // Split our layer on rows by the new lines (\n)
        List <string> lines = new List <string>(content.Split('\n'));
        // Place each block in order in the correct x and y position
        levelInfo data = new levelInfo();

        data.dataLst = new List <List <blockInfo> >();
        for (int i = 0; i < lines.Count; i++)
        {
            string[] blockIDs = lines[i].Split(',');
            //	Debug.Log(">>>>>>>>>>>>level lines i:"+i+"  "+lines[i]);
            List <blockInfo> rowdata = new List <blockInfo>();
            data.dataLst.Add(rowdata);
            bool haveData = false;
            for (int j = 0; j < blockIDs.Length - 1; j++)
            {
                blockInfo colData = new blockInfo();
                if (blockIDs[j] != "EMPTY")
                {
                    //Debug.Log(">>>>>>>>>>>>>blockIDs:"+j+"  "+blockIDs[j]);
                    // 名字|分数|角度|类型
                    string[] temp = blockIDs[j].Split('|');
                    colData.row = j;
                    colData.col = lines.Count - i - 1;
                    if (temp[1] != "")
                    {
                        colData.score = int.Parse(temp[1]);
                    }
                    colData.angle = float.Parse(temp[2]);
                    colData.type  = int.Parse(temp[3]);
                    haveData      = true;
                }
                else
                {
                    colData.type = -1;
                }
                rowdata.Add(colData);
            }
            if (haveData)
            {
                data.maxRow = i + 1;
            }
        }

        allData[curLevel] = data;
    }
예제 #8
0
    // Start is called before the first frame update
    void Start()
    {
        info = GameObject.FindObjectOfType <levelInfo>();

        InvokeRepeating("SpawnObject", spawnTime, spawnDelay);
    }