Esempio n. 1
0
    void Awake()
    {
//		string temp;
//		char[] charArray = new char[]{','};
//		char[] comment = new char[]{'/', '/'};

        wavesL.spawned    = 0;
        wavesR.spawned    = 0;
        wavesL.isFromLeft = true;
        wavesR.isFromLeft = false;

//		if (File.Exists ("Assets/stage.txt")) {
//			stage = new FileStream ("Assets/stage.txt", FileMode.Open, FileAccess.Read);
//		} else {
//			Debug.Log ("file error!");
//		}
//
//		sr = new StreamReader (stage);
//		while ((temp = sr.ReadLine ()) != null) {
//			if (temp.StartsWith ("//"))
//				continue;
//
//			int todelete = temp.IndexOfAny (comment);
//			if(todelete > 0)
//				temp = temp.Remove (todelete);
//
//			string[] strArray = temp.Split (charArray);
//			SpawnType elem = new SpawnType();
//
//			elem.tag = strArray [0];
//			if (strArray.Length > 5) {
//				elem.initPosition = Vector3.zero;
//				elem.speed = System.Convert.ToSingle (strArray [4]);
//			}
//
//			for (int i = 5; i < strArray.Length; i++)
//				elem.enemyInterval.Enqueue (System.Convert.ToInt32 (strArray [i]));
//
//			//			Debug.Log (temp);
//			enemyQueue.Enqueue (elem);
//		}
        // using json
        JSONNode level_json = JSONData.LoadFromFile(Application.streamingAssetsPath + "/stage.json");

        for (int i = 0; i < level_json.Count; i++)
        {
            SpawnType elem = new SpawnType();
            elem.tag          = level_json [i] ["tag"];
            elem.initPosition = new Vector3(level_json [i] ["pos"][0].AsFloat, level_json [i] ["pos"][1].AsFloat, level_json [i] ["pos"][2].AsFloat);
            elem.speed        = level_json [i] ["speed"].AsFloat;
            for (int j = 0; j < level_json [i] ["interval"].Count; j++)
            {
                elem.enemyInterval.Enqueue(level_json [i] ["interval"] [j].AsInt);
            }
            enemyQueue.Enqueue(elem);
        }
    }