Пример #1
0
    public void CreateMap(int number)
    {
        Map map = InitMap(number);

        buttonCount = map.buttonCount;

        for (int i = 0; i < map.heigth; i++)
        {
            for (int j = 0; j < map.width; j++)
            {
                Vector3    placePosition = startPosition + new Vector3(SharedData.widhtUnit * j, 0, i * -1 * SharedData.widhtUnit);
                MapElement id            = map.mapMatrix[i, j];
                actMap[i, j] = id;
                switch (id)
                {
                case MapElement.Column:
                    GameObject brick = Instantiate(columnModel.gameObject, placePosition + new Vector3(0, columnModel.ModelGround, 0), columnModel.GetQuat(), ColumnsParent);
                    objectMap[i, j] = brick;
                    break;

                case MapElement.Edge:
                    GameObject edge = Instantiate(edgeModel.gameObject, placePosition + new Vector3(0, edgeModel.ModelGround, 0), edgeModel.GetQuat(), EdgesParent);
                    objectMap[i, j] = edge;
                    break;

                case MapElement.Trap:
                    GameObject trap = Instantiate(trapModel.gameObject, placePosition + new Vector3(0, trapModel.ModelGround, 0), trapModel.GetQuat(), TrapsParent) as GameObject;
                    objectMap[i, j] = trap;
                    AddToNotStaticElements(trap, new Vector3(placePosition.x, placePosition.y + trapModel.ModelGround, placePosition.z), MapElement.Trap);
                    break;

                case MapElement.Button:
                    GameObject Button = Instantiate(buttonModel.gameObject, placePosition + new Vector3(0, buttonModel.ModelGround, 0), buttonModel.GetQuat(), ButtonsParent) as GameObject;
                    objectMap[i, j] = Button;
                    AddToNotStaticElements(Button, new Vector3(placePosition.x, placePosition.y + buttonModel.ModelGround, placePosition.z), MapElement.Button);
                    break;

                case MapElement.Hole:
                    GameObject hole = Instantiate(holeModel.gameObject, placePosition + new Vector3(0, holeModel.ModelGround, 0), holeModel.GetQuat(), ColumnsParent);
                    objectMap[i, j] = hole;
                    break;

                case MapElement.Door:
                    GameObject door = Instantiate(doorModel.gameObject, placePosition + new Vector3(0, doorModel.ModelGround, 0), doorModel.GetQuat(), DoorsParent) as GameObject;
                    objectMap[i, j] = door;
                    AddToNotStaticElements(door, new Vector3(placePosition.x, placePosition.y + doorModel.ModelGround, placePosition.z), MapElement.Door);
                    Door doorScript = door.GetComponent <Door>();
                    doorScript.SetCount(map.buttonCount);
                    doors.Add(door.GetComponent <Door>());
                    break;

                case MapElement.Key:
                    GameObject Key = Instantiate(keyModel.gameObject, placePosition + new Vector3(0, keyModel.ModelGround, 0), keyModel.GetQuat(), mapGeneratorGO.transform) as GameObject;
                    objectMap[i, j] = Key;
                    AddToNotStaticElements(Key, new Vector3(placePosition.x, placePosition.y + keyModel.ModelGround, placePosition.z), MapElement.Key);
                    break;

                case MapElement.DoorEdge:
                    GameObject doorEdge = Instantiate(doorEdgeModel.gameObject, placePosition + new Vector3(0, doorEdgeModel.ModelGround, 0), doorEdgeModel.GetQuat(), DoorsParent) as GameObject;
                    objectMap[i, j] = doorEdge;
                    break;

                case MapElement.StoneLifter:
                    GameObject StoneLifter = Instantiate(stoneLifterModel.gameObject, placePosition + new Vector3(0, stoneLifterModel.ModelGround, 0), stoneLifterModel.GetQuat(), RisingStonesParent) as GameObject;
                    objectMap[i, j] = StoneLifter;
                    AddToNotStaticElements(StoneLifter, placePosition + new Vector3(0, stoneLifterModel.ModelGround, 0), MapElement.StoneLifter);
                    break;

                case MapElement.RisingStone:
                    GameObject RisingStone = Instantiate(risingStoneModel.gameObject, placePosition + new Vector3(0, risingStoneModel.ModelGround, 0), risingStoneModel.GetQuat(), RisingStonesParent);
                    objectMap[i, j] = RisingStone;
                    AddToNotStaticElements(RisingStone, placePosition + new Vector3(0, risingStoneModel.ModelGround, 0), MapElement.RisingStone);
                    RisingStones.Add(RisingStone.GetComponent <RiseElement>());
                    break;

                case MapElement.LaserGate:
                    GameObject laserGate = Instantiate(laserGateModel.gameObject, placePosition + new Vector3(0, laserGateModel.ModelGround, 0), laserGateModel.GetQuat(), LaserGatesParent) as GameObject;
                    objectMap[i, j] = laserGate;
                    LaserGate laserGateScript = laserGate.GetComponent <LaserGate>();
                    laserGateScript.SetLasers(map.laserSwitchCount, laserGateModel.ModelGround);
                    laserGates.Add(laserGateScript);
                    break;

                case MapElement.LaserGateEdge:
                    GameObject laserGateEdge = Instantiate(laserGateEdgeModel.gameObject, placePosition + new Vector3(0, laserGateEdgeModel.ModelGround, 0), laserGateEdgeModel.GetQuat(), LaserGatesParent) as GameObject;
                    objectMap[i, j] = laserGateEdge;
                    break;

                case MapElement.LaserSwitch:
                    GameObject laserSwitch = Instantiate(laserSwitchModel.gameObject, placePosition + new Vector3(0, laserSwitchModel.ModelGround, 0), laserSwitchModel.GetQuat(), LaserSwitchesParent) as GameObject;
                    objectMap[i, j] = laserSwitch;
                    AddToNotStaticElements(laserSwitch, new Vector3(placePosition.x, placePosition.y + laserSwitchModel.ModelGround, placePosition.z), MapElement.LaserSwitch);
                    break;

                case MapElement.Gem:
                    GameObject Gem = Instantiate(gemModel.gameObject, placePosition + new Vector3(0, gemModel.ModelGround, 0), gemModel.GetQuat(), mapGeneratorGO.transform) as GameObject;
                    objectMap[i, j] = Gem;
                    AddToNotStaticElements(Gem, new Vector3(placePosition.x, placePosition.y + gemModel.ModelGround, placePosition.z), MapElement.Gem);
                    break;

                case MapElement.Relic:
                    GameObject Relic = Instantiate(relicModel.gameObject, placePosition + new Vector3(0, relicModel.ModelGround, 0), relicModel.GetQuat(), mapGeneratorGO.transform) as GameObject;
                    objectMap[i, j] = Relic;
                    AddToNotStaticElements(Relic, new Vector3(placePosition.x, placePosition.y + relicModel.ModelGround, placePosition.z), MapElement.Relic);
                    break;

                default:
                    break;
                }
            }
        }

        int boxNumber = map.boxNumber;

        for (int i = 0; i < boxNumber; i++)
        {
            Vector3    position = map.boxLocations[i];
            GameObject box      = Instantiate(boxModel.gameObject, position, boxModel.GetQuat(), BoxesParent) as GameObject;
            objectMap[(int)(startPosition.z - position.z) / SharedData.widhtUnit, (int)(position.x - startPosition.x) / SharedData.widhtUnit].GetComponent <HeightData>().AddBox(box);

            Transform onIt       = objectMap[(int)(startPosition.z - position.z) / SharedData.widhtUnit, (int)(position.x - startPosition.x) / SharedData.widhtUnit].transform;
            int       onItNumber = objectMap[(int)(startPosition.z - position.z) / SharedData.widhtUnit, (int)(position.x - startPosition.x) / SharedData.widhtUnit].GetComponent <HeightData>().GetBoxCount();
            box.GetComponent <BoxController>().InitOnIt(onIt, onItNumber);

            boxesCollider.Add(box.GetComponent <BoxCollider>());
            AddToNotStaticElements(box, position, MapElement.Box);
        }
    }