示例#1
0
    public bool Load(string nameFile)
    {
        Debug.Log("Load " + nameFile);
        if (string.IsNullOrEmpty(nameFile))
        {
            Debug.LogWarning("isNull");
            return(false);
        }


        var pathSavedMaps = $"{pathMaps}/{nameFile}";
        //ici load les donnée de nameFile dans les data courante
        //string dataToLoad = "";

        string content = "";

        Debug.Log("path map to load: " + pathSavedMaps);
        bool openFile = ExtFile.LoadFromResource(pathSavedMaps, ref content);


        if (!openFile)
        {
            Debug.LogWarning("file doesn't exist");
            return(false);
        }

        string[] contentLine = content.Split('\n');

        int sizeXData = 0;
        int sizeYData = 0;

        ushort[,] gridData = new ushort[0, 0];

        int index = 0;

        for (int k = 0; k < contentLine.Length; k++)
        {
            //Debug.Log(contentLine[k]);
            //dataToLoad += s + "\n";
            if (index == 0)
            {
                string[] sizes = contentLine[k].Split(' ');
                sizeXData = sizes[0].ToInt(0);
                sizeYData = sizes[1].ToInt(0);

                gridData = new ushort[sizeXData, sizeYData];
            }
            else
            {
                string[] lineDatas = contentLine[k].Split(' ');
                for (int i = 0; i < lineDatas.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(lineDatas[i]))
                    {
                        continue;
                    }
                    //Debug.Log(lineDatas[i]);
                    gridData[i, index - 1] = (ushort)(lineDatas[i].ToInt(0));
                    //Debug.Log("done");
                }
            }

            index++;
        }

        GridManager.Instance.LoadNewGrid(sizeXData, sizeYData, gridData);
        //Debug.Log(dataToLoad);
        return(true);
    }