Exemplo n.º 1
0
    void LoadSetObject(LevelSaveStructure saveFormat_)
    {
        //string array for each element in vector
        string[] vectorStringArray;
        //loaded the right object
        string     pathToObject = "LevelBuilder/Objects/" + saveFormat_.GetName();
        GameObject prefab       = Resources.Load <GameObject>(pathToObject);
        GameObject loadedObject = Instantiate(prefab);

        loadedObject.name = saveFormat_.GetName();
        //make string to represent what vector will be converted
        vectorStringArray = StringToVector(saveFormat_.GetPositon());
        loadedObject.transform.position = new Vector3(float.Parse(vectorStringArray[0]), float.Parse(vectorStringArray[1]), float.Parse(vectorStringArray[2]));
        vectorStringArray = StringToVector(saveFormat_.GetRotation());
        loadedObject.transform.eulerAngles = new Vector3(float.Parse(vectorStringArray[0]), float.Parse(vectorStringArray[1]), float.Parse(vectorStringArray[2]));
        vectorStringArray = StringToVector(saveFormat_.GetScale());
        loadedObject.transform.localScale = new Vector3(float.Parse(vectorStringArray[0]), float.Parse(vectorStringArray[1]), float.Parse(vectorStringArray[2]));
    }
Exemplo n.º 2
0
    void LoadingFile(string path_)
    {
        LevelSaveStructure saveFormat = new LevelSaveStructure();
        string             path       = path_;
        StreamReader       reader     = new StreamReader(path, true);
        string             text       = "";
        int counter = 0;

        while (text != "END")
        {
            text = reader.ReadLine();
            switch (counter)
            {
            case 0:
                saveFormat.SetName(text);
                break;

            case 1:
                saveFormat.SetPosition(text);
                break;

            case 2:
                saveFormat.SetRotation(text);
                break;

            case 3:
                saveFormat.SetScale(text);
                break;
            }
            counter++;
            if (text != "END")
            {
                if (counter > 3)
                {
                    LoadSetObject(saveFormat);
                    counter = 0;
                }
            }
        }
        reader.Close();
    }