Esempio n. 1
0
 void SpawnObjects()
 {
     if (!isWispMoving)
     {
         int tempIndex = 0;
         objectsToSpawn = UnityEngine.Random.Range(minItemsPerSpwn, maxItemsPerSpwn + 1);
         for (int i = 0; i < objectsToSpawn; i++)
         {
             tempIndex = UnityEngine.Random.Range(0, objectToPlace.Count + 1);
             Vector3 tempPlace = new Vector3(newWisp.transform.position.x + UnityEngine.Random.Range(-15, 15),
                                             5f, newWisp.transform.position.z + UnityEngine.Random.Range(-15, 15));
             GameObject newObject = (GameObject)Instantiate(objectToPlace[tempIndex], tempPlace, Quaternion.identity);
             mainCam.enabled  = false;
             wispyCam.enabled = true;
             wispyCam.transform.LookAt(newObject.transform);
             StartCoroutine(waitForCam());
             count++;
             objectsInWorld.Add(objectToPlace[tempIndex].name);
             transformsInWorld.Add(tempPlace);
             Objectinfo objectinfo = new Objectinfo();
             objectinfo.objectNames.AddRange(objectsInWorld);
             objectinfo.objectTransforms.AddRange(transformsInWorld);
             objectinfo.orbTransforms.AddRange(orbsInWorld);
             string jsonData = JsonUtility.ToJson(objectinfo);
             saveData("World", jsonData);
         }
         currentObjects[currTerrainIndex] = currentObjects[currTerrainIndex] + objectsToSpawn;
     }
 }
Esempio n. 2
0
    void loadData(string dataFileName)
    {
        string tempPath = Path.Combine(Application.persistentDataPath, "data");

        tempPath = Path.Combine(tempPath, dataFileName + ".zombdata");

        //Exit if Directory or File does not exist
        if (!Directory.Exists(Path.GetDirectoryName(tempPath)))
        {
            Debug.LogWarning("Directory does not exist");
        }

        else if (!File.Exists(tempPath))
        {
            Debug.Log("File does not exist");
        }

        else
        {
            byte[] jsonByte = null;
            try
            {
                jsonByte = File.ReadAllBytes(tempPath);
                Debug.Log("Loaded Data from: " + tempPath.Replace("/", "\\"));
            }
            catch (System.Exception e)
            {
                Debug.LogWarning("Failed To Load Data from: " + tempPath.Replace("/", "\\"));
                Debug.LogWarning("Error: " + e.Message);
            }
            string     jsonData   = Encoding.ASCII.GetString(jsonByte);
            Objectinfo loadedData = JsonUtility.FromJson <Objectinfo>(jsonData);
            //spawn/load objects
            objectsInWorld    = loadedData.objectNames;
            transformsInWorld = loadedData.objectTransforms;
            orbsInWorld       = loadedData.orbTransforms;
            for (int i = 0; i < orbsInWorld.Count; i++)
            {
                Instantiate(wisp, orbsInWorld[i], Quaternion.identity);
            }
            for (int x = 0; x < objectsInWorld.Count + 1; x++)
            {
                for (int y = 0; y < objectToPlace.Count; y++)
                {
                    if (objectToPlace[y].name == objectsInWorld[x])
                    {
                        tempObject = objectToPlace[y];
                        Debug.Log(tempObject.name);
                        break;
                    }
                    Instantiate(tempObject, transformsInWorld[x], Quaternion.identity);
                }
            }
        }
    }