示例#1
0
    void SaveGround()
    {
        if (!Directory.Exists("Assets/Script/Tools/GroundEditor/Save/"))
        {
            Directory.CreateDirectory("Assets/Script/Tools/GroundEditor/Save/" + nameMap);
        }

        height.Clear();
        foreach (GameObject obj in checker)
        {
            height.Add(obj.GetComponent <GroundBaseGenerator>().HeightChecker);
        }

        currentMapDataSave                       = new MapDataSave();
        currentMapDataSave.NameMap               = nameMap;
        currentMapDataSave.CheckerOnTheLenght    = checkerOnTheLenght;
        currentMapDataSave.CheckerOnTheHeight    = checkerOnTheHeight;
        currentMapDataSave.CellByLenghtChecker   = cellByLenghtChecker;
        currentMapDataSave.Density               = cellDensity;
        currentMapDataSave.Height                = height;
        currentMapDataSave.vertexColorRedValue   = vertexColorRedValue;
        currentMapDataSave.vertexColorGreenValue = vertexColorGreenValue;
        currentMapDataSave.vertexColorBlueValue  = vertexColorBlueValue;


        int index = 0;

        foreach (GameObject obj in checker)
        {
            obj.GetComponent <GroundBaseGenerator>().IndexInTheCheckboard = index;
            index++;
        }

        string json = JsonUtility.ToJson(currentMapDataSave, true);

        File.WriteAllText("Assets/Script/Tools/GroundGenerator/Save/" + nameMap, json);

        Repaint();
    }
示例#2
0
    void LoadGround()
    {
        if (skinLoadAndCreatGround)
        {
            if (!File.Exists("Assets/Script/Tools/GroundEditor/Save/" + NameJSONFile))
            {
                Debug.Log("File didn't exist !");
                return;
            }
            currentMapDataSave = (MapDataSave)JsonUtility.FromJson(File.ReadAllText("Assets/Script/Tools/GroundEditor/Save/" + NameJSONFile), typeof(MapDataSave));

            groundFolder = new GameObject();
            groundFolder.transform.position = Vector3.zero;
            groundFolder.name = "GroundFolder";

            vertexColorRedValue   = currentMapDataSave.vertexColorRedValue;
            vertexColorGreenValue = currentMapDataSave.vertexColorGreenValue;
            vertexColorBlueValue  = currentMapDataSave.vertexColorBlueValue;

            nameMap             = currentMapDataSave.NameMap;
            checkerOnTheLenght  = currentMapDataSave.CheckerOnTheLenght;
            checkerOnTheHeight  = currentMapDataSave.CheckerOnTheHeight;
            cellByLenghtChecker = currentMapDataSave.CellByLenghtChecker;
            cellDensity         = currentMapDataSave.Density;
            height = currentMapDataSave.Height;

            CreatGround();
        }

        else
        {
            GameObject[] initialisator = new GameObject[checkerOnTheHeight * checkerOnTheLenght];
            foreach (Transform child in groundFolder.transform)
            {
                if (child.GetComponent <GroundBaseGenerator>())
                {
                    int i = child.GetComponent <GroundBaseGenerator>().IndexInTheCheckboard;
                    initialisator[i] = child.gameObject;
                }
            }
            checker = new List <GameObject>(initialisator);

            vertexColorRedValue   = checker[0].GetComponent <GroundBaseGenerator>().RedColorByHeight;
            vertexColorGreenValue = checker[0].GetComponent <GroundBaseGenerator>().GreenColorByHeight;
            vertexColorBlueValue  = checker[0].GetComponent <GroundBaseGenerator>().BlueColorByHeight;

            cellByLenghtChecker = checker[0].GetComponent <GroundBaseGenerator>().NumberCellByLenght - 1;
            cellDensity         = checker[0].GetComponent <GroundBaseGenerator>().Density;
            checkerOnTheLenght  = 0;
            checkerOnTheHeight  = 0;

            for (int index = 0; index < checker.Count; index++)
            {
                if (checker[index].transform.position.z != 0)
                {
                    checkerOnTheLenght = index;
                    break;
                }
            }

            Debug.Log(checker.Count + " / " + checkerOnTheLenght + " = " + checker.Count / checkerOnTheLenght);
            checkerOnTheHeight = checker.Count / checkerOnTheLenght;
        }

        groundCreat            = true;
        skinCheckerVue         = true;
        skinLoadGroundVue      = false;
        skinLoadAndCreatGround = false;
    }