示例#1
0
    void GenerateMap()
    {
        f = new FileLibrary();
        f.ReadFile (GameData.path + "/stage"+GameData.currentStage);
        deathText.GetComponent<Text>().text = GameData.currentDeath + " / " + GameData.maxDeath + " deaths";
        stageText.GetComponent<Text>().text = GameData.currentStage + " / " + GameData.maxStage;
        title.GetComponent<Text>().text = f.stageData.StageTitle;
        background.transform.localScale = new Vector3 ((f.stageData.width + 2) * f.stageData.blockSize / 10, 1, (f.stageData.height + 2) * f.stageData.blockSize / 10);
        startPosition.transform.localScale = new Vector3 (f.stageData.blockSize / 10, 1, f.stageData.blockSize / 10);
        startPosition.transform.position = new Vector3(f.stageData.startPosition[0]*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,1,-f.stageData.startPosition[1]*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);
        endPosition.transform.localScale = new Vector3 (f.stageData.blockSize / 10, 1, f.stageData.blockSize / 10);
        endPosition.transform.position = new Vector3(f.stageData.endPosition[0]*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,1,-f.stageData.endPosition[1]*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);

        int mCount = f.stageData.graphicSource.Length;
        ts = new Texture[mCount];
        for (int i=0; i<mCount; i++) {
            ts[i] = new Texture();
            ts[i] = Resources.Load ("Stage/"+GameData.path+"/"+f.stageData.graphicSource[i], typeof(Texture)) as Texture;
        }
        for (int i=0; i<f.stageData.width; i++) {
            for (int j=0; j<f.stageData.height; j++) {
                if(f.stageData.map[i, j] == '1'){
                    GameObject t = Instantiate(obstacle) as GameObject;
                    t.transform.position = new Vector3(i*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,0,-j*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);
                    t.transform.localScale = new Vector3(f.stageData.blockSize,f.stageData.blockSize,1);
                    t.GetComponent<Renderer>().material.mainTexture = ts[f.stageData.graphic[i, j] - 'a'];
                    oList.Add (t);
                }else{
                    GameObject t = Instantiate(movable) as GameObject;
                    t.transform.position = new Vector3(i*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,0,-j*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);
                    t.transform.localScale = new Vector3(f.stageData.blockSize,f.stageData.blockSize,1);
                    t.GetComponent<Renderer>().material.mainTexture = ts[f.stageData.graphic[i, j] - 'a'];
                    mList.Add (t);
                }
            }
        }
        /*
        foreach(var locations in f.stageData.locations){
            GameObject t = Instantiate(location) as GameObject;
            t.transform.position = new Vector3(locations.Value[0]*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,0,-locations.Value[1]*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);
            t.transform.localScale = new Vector3(f.stageData.blockSize,f.stageData.blockSize,1);
            lList.Add (locations.Key, t);
        }*/
        seeker.transform.position = new Vector3(f.stageData.startPosition[0]*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,0,-f.stageData.startPosition[1]*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);
        target.transform.position = new Vector3(f.stageData.startPosition[0]*f.stageData.blockSize-(f.stageData.width - 1) * f.stageData.blockSize / 2,0,-f.stageData.startPosition[1]*f.stageData.blockSize+(f.stageData.height - 1) * f.stageData.blockSize / 2);
        //UnityEditor.NavMeshBuilder.BuildNavMesh ();
    }