コード例 #1
0
    public void LoadMaze(string filePath)
    {
        if (filePath == "")
        {
            return;
        }

        try
        {
            TextAsset binData = Resources.Load(filePath) as TextAsset;
            lines = binData.text.Split('\n');
        }
        catch (Exception e)
        {
            Debug.Log("could not load level");
        }

        // Generate Ground
        GameObject ground = Instantiate <GameObject>(Ground, new Vector3(5f, -0.5f, 5f) * WALL_SIZE, Quaternion.identity);

        ground.transform.localScale = Vector3.one * WALL_SIZE * LENGTH * 100;

        // Generate walls and stuff
        for (int i = 0; i < LENGTH; i++)
        {
            for (int j = 0; j < WIDTH; j++)
            {
                char tileChar = lines[i][j];



                switch (tileChar)
                {
                case (WALL_CHAR):
                    //GameObject wall = Instantiate<GameObject>(Wall, new Vector3(i, 0, j) * WALL_SIZE, Quaternion.identity);

                    GameObject wall = generateCube((int)UnityEngine.Random.Range(0, 8), new Vector3(i, 0, j) * WALL_SIZE, Vector3.zero);
                    wall.transform.localScale = Vector3.one * WALL_SIZE * 10;
                    wall.transform.parent     = gameObject.transform;
                    break;

                case (FLOOR_CHAR):
                    randomfloat = UnityEngine.Random.Range(0.0f, 10.0f);
                    if (randomfloat > 7.0f)
                    {
                        int        bloodint = ((int)randomfloat) % 3;
                        GameObject blood;
                        if (bloodint == 0)
                        {
                            blood = BloodFloor1;
                        }
                        else if (bloodint == 1)
                        {
                            blood = BloodFloor2;
                        }
                        else if (bloodint == 2)
                        {
                            blood = BloodFloor3;
                        }
                        else
                        {
                            blood = BloodFloor1;
                        }
                        GameObject floor = Instantiate <GameObject>(blood, new Vector3(i, -0.4995f, j) * WALL_SIZE, Quaternion.AngleAxis(90, Vector3.right));
                        floor.transform.localScale = Vector3.one * WALL_SIZE;
                        floor.transform.parent     = gameObject.transform;
                        break;
                    }
                    break;

                case (START_CHAR):
                    GameObject startWall = Instantiate <GameObject>(StartGate, new Vector3(i + 1, 0.75f, j) * WALL_SIZE, Quaternion.identity);
                    //GameObject startGate = Instantiate<GameObject>(StartGate, new Vector3(i - 1, 0, j) * WALL_SIZE, Quaternion.identity);

                    GameObject startGate = Instantiate <GameObject>(StartGate, new Vector3(i - 1, 0, j) * WALL_SIZE, Quaternion.Euler(new Vector3(0, 1, 1) * 90));



                    startWall.transform.localScale = Vector3.one * WALL_SIZE * 10;
                    startGate.transform.localScale = Vector3.one * WALL_SIZE * 10;

                    startWall.transform.parent = gameObject.transform;
                    startGate.transform.parent = gameObject.transform;

                    GateScript gs = startWall.GetComponent <GateScript>();
                    gs.SetDirection(-1);

                    //spawning player
                    GameObject harry = Instantiate <GameObject>(Harry, new Vector3(i, 0, j) * WALL_SIZE, Quaternion.identity);
                    harry.transform.Rotate(Vector3.down * 90);
                    harry.transform.parent = gameObject.transform;
                    break;

                case (FIN_CHAR):
                    GameObject finGate = Instantiate <GameObject>(StartGate, new Vector3(i - 1, 0, j) * WALL_SIZE, Quaternion.Euler(new Vector3(0, 1, 1) * 90));
                    finGate.transform.localScale = Vector3.one * WALL_SIZE * 10;
                    finGate.transform.parent     = gameObject.transform;
                    GateScript fgs    = finGate.GetComponent <GateScript>();
                    GameObject finish = Instantiate <GameObject>(Finish, new Vector3(i, 0, j) * WALL_SIZE, Quaternion.identity);
                    finish.transform.parent = gameObject.transform;
                    break;

                default: break;
                }
            }
        }
    }