Ejemplo n.º 1
0
    private void BuildDecor(DecorObject p_Decor, int p_PartID)
    {
        Transform l_Object = Instantiate(m_Prefabs[p_Decor.type]).transform;

        l_Object.parent        = m_Parts[p_PartID];
        l_Object.localPosition = p_Decor.position;
        l_Object.localRotation = p_Decor.rotation;
        l_Object.localScale    = new Vector3(p_Decor.scale.x, p_Decor.scale.y, p_Decor.scale.z);
    }
Ejemplo n.º 2
0
        public void RebuildLevel(List <Node> nodes, Biomes biome, List <Decor> decor)
        {
            finishedBuilding = false;

            // start by resetting the grid's nodes to their base states
            _Grid.instance.ResetIndexGrid();

            foreach (Node recoveredNode in nodes)
            {
                // EXTREMELY IMPORTANT -> CONVERTS THE CUBE'S TYPE FROM STRING TO ENUM
                recoveredNode.cubeType = Node.ConvertStringToCubeType(recoveredNode.savedCubeType);

                //Set the universe textures
                _MaterialCentral.instance.ChangeUniverse(biome);

                currentNode = recoveredNode;

                GameObject newCube = Instantiate(cubePrefab);

                _Grid.instance.placedCubes.Add(newCube);

                // get the kuboGrid and set the information on each of the nodes
                SetNodeInfo(newCube, recoveredNode.nodeIndex, recoveredNode.worldPosition, recoveredNode.worldRotation,
                            recoveredNode.facingDirection, recoveredNode.cubeLayers, recoveredNode.cubeType);

                // check the node's cube type and setup the relevant cube and its transform + individual information
                switch (recoveredNode.cubeType)
                {
                case CubeTypes.FullStaticCube:
                    newCube.AddComponent(typeof(StaticCube));
                    StaticCube fullStaticCube = newCube.GetComponent <StaticCube>();
                    SetCubeInfo(fullStaticCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.FullStaticCube, true);
                    break;

                case CubeTypes.EmptyStaticCube:
                    newCube.AddComponent(typeof(StaticCube));
                    StaticCube emptyCube = newCube.GetComponent <StaticCube>();
                    SetCubeInfo(emptyCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.EmptyStaticCube, true);
                    break;

                case CubeTypes.TopStaticCube:
                    newCube.AddComponent(typeof(StaticCube));
                    StaticCube topStaticCube = newCube.GetComponent <StaticCube>();
                    SetCubeInfo(topStaticCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.TopStaticCube, true);
                    break;

                case CubeTypes.CornerStaticCube:
                    newCube.AddComponent(typeof(StaticCube));
                    StaticCube cornerStaticCube = newCube.GetComponent <StaticCube>();
                    SetCubeInfo(cornerStaticCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.CornerStaticCube, true);
                    break;

                case CubeTypes.TripleStaticCube:
                    newCube.AddComponent(typeof(StaticCube));
                    StaticCube tripleStaticCube = newCube.GetComponent <StaticCube>();
                    SetCubeInfo(tripleStaticCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.TripleStaticCube, true);
                    break;

                case CubeTypes.QuadStaticCube:
                    newCube.AddComponent(typeof(StaticCube));
                    StaticCube quadStaticCube = newCube.GetComponent <StaticCube>();
                    SetCubeInfo(quadStaticCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.QuadStaticCube, true);
                    break;

                case CubeTypes.MoveableCube:
                    newCube.AddComponent(typeof(MoveableCube));
                    MoveableCube moveableCube = newCube.GetComponent <MoveableCube>();
                    SetCubeInfo(moveableCube as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.MoveableCube, false);
                    break;

                case CubeTypes.BaseVictoryCube:
                    newCube.AddComponent(typeof(BaseVictoryCube));
                    BaseVictoryCube baseVictoryCube = newCube.GetComponent <BaseVictoryCube>();
                    SetCubeInfo(baseVictoryCube as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.BaseVictoryCube, false);
                    break;

                case CubeTypes.ConcreteVictoryCube:
                    newCube.AddComponent(typeof(ConcreteVictoryCube));
                    ConcreteVictoryCube concreteVictoryCube = newCube.GetComponent <ConcreteVictoryCube>();
                    SetCubeInfo(concreteVictoryCube as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.ConcreteVictoryCube, false);
                    break;

                case CubeTypes.BombVictoryCube:
                    newCube.AddComponent(typeof(BombVictoryCube));
                    BombVictoryCube bombVictoryCube = newCube.GetComponent <BombVictoryCube>();
                    SetCubeInfo(bombVictoryCube as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.BombVictoryCube, false);
                    break;

                case CubeTypes.SwitchVictoryCube:
                    newCube.AddComponent(typeof(SwitchVictoryCube));
                    SwitchVictoryCube switchVictoryCube = newCube.GetComponent <SwitchVictoryCube>();
                    SetCubeInfo(switchVictoryCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.SwitchVictoryCube, true);
                    break;

                case CubeTypes.DeliveryCube:
                    newCube.AddComponent(typeof(DeliveryCube));
                    DeliveryCube deliveryCube = newCube.GetComponent <DeliveryCube>();
                    SetCubeInfo(deliveryCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.DeliveryCube, true);
                    break;

                case CubeTypes.BlueElevatorCube:
                    newCube.AddComponent(typeof(ElevatorCube));
                    ElevatorCube blueElevatorCube = newCube.GetComponent <ElevatorCube>();
                    blueElevatorCube.isGreen = false;
                    SetCubeInfo(blueElevatorCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.BlueElevatorCube, false);
                    break;

                case CubeTypes.GreenElevatorCube:
                    newCube.AddComponent(typeof(ElevatorCube));
                    ElevatorCube greenElevatorCube = newCube.GetComponent <ElevatorCube>();
                    greenElevatorCube.isGreen = true;
                    SetCubeInfo(greenElevatorCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.GreenElevatorCube, false);
                    break;

                case CubeTypes.ConcreteCube:
                    newCube.AddComponent(typeof(ConcreteCube));
                    ConcreteCube concreteCube = newCube.GetComponent <ConcreteCube>();
                    SetCubeInfo(concreteCube as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.ConcreteCube, false);
                    break;

                case CubeTypes.BombCube:
                    newCube.AddComponent(typeof(BombCube));
                    BombCube bombCube = newCube.GetComponent <BombCube>();
                    SetCubeInfo(bombCube as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.BombCube, false);
                    break;

                    #region // TIMER CUBE
                case CubeTypes.TimerCube1:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube1, true);
                    timerCube.timerValue = 1;
                    break;

                case CubeTypes.TimerCube2:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube2 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube2 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube2, true);
                    timerCube2.timerValue = 2;
                    break;

                case CubeTypes.TimerCube3:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube3 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube3 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube3, true);
                    timerCube3.timerValue = 3;
                    break;

                case CubeTypes.TimerCube4:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube4 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube4 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube4, true);
                    timerCube4.timerValue = 4;
                    break;

                case CubeTypes.TimerCube5:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube5 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube5 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube5, true);
                    timerCube5.timerValue = 5;
                    break;

                case CubeTypes.TimerCube6:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube6 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube6 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube6, true);
                    timerCube6.timerValue = 6;
                    break;

                case CubeTypes.TimerCube7:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube7 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube7 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube7, true);
                    timerCube7.timerValue = 7;
                    break;

                case CubeTypes.TimerCube8:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube8 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube8 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube8, true);
                    timerCube8.timerValue = 8;
                    break;

                case CubeTypes.TimerCube9:
                    newCube.AddComponent(typeof(TimerCube));
                    TimerCube timerCube9 = newCube.GetComponent <TimerCube>();
                    SetCubeInfo(timerCube9 as _CubeBase, CubeLayers.cubeFull, CubeTypes.TimerCube9, true);
                    timerCube9.timerValue = 9;
                    break;
                    #endregion CUBES

                case CubeTypes.SwitchButton:
                    newCube.AddComponent(typeof(SwitchButton));
                    SwitchButton switchButton = newCube.GetComponent <SwitchButton>();
                    SetCubeInfo(switchButton as _CubeBase, CubeLayers.cubeFull, CubeTypes.SwitchButton, true);
                    break;

                case CubeTypes.SwitchCube:
                    newCube.AddComponent(typeof(SwitchCube));
                    SwitchCube switchCube = newCube.GetComponent <SwitchCube>();
                    SetCubeInfo(switchCube as _CubeBase, CubeLayers.cubeFull, CubeTypes.SwitchCube, true);
                    break;

                case CubeTypes.RotatorRightTurner:
                    newCube.AddComponent(typeof(RotateRightCube));
                    RotateRightCube rotatorRightTurn = newCube.GetComponent <RotateRightCube>();
                    SetCubeInfo(rotatorRightTurn as _CubeBase, CubeLayers.cubeFull, CubeTypes.RotatorRightTurner, true);
                    break;

                case CubeTypes.RotatorLeftTurner:
                    newCube.AddComponent(typeof(RotateLeftCube));
                    RotateLeftCube rotatorLeftTurn = newCube.GetComponent <RotateLeftCube>();
                    SetCubeInfo(rotatorLeftTurn as _CubeBase, CubeLayers.cubeFull, CubeTypes.RotatorLeftTurner, true);
                    break;

                case CubeTypes.RotatorLocker:
                    newCube.AddComponent(typeof(RotatorLocker));
                    RotatorLocker rotatorLocker = newCube.GetComponent <RotatorLocker>();
                    SetCubeInfo(rotatorLocker as _CubeBase, CubeLayers.cubeFull, CubeTypes.RotatorLocker, true);
                    break;

                case CubeTypes.ChaosBall:
                    newCube.AddComponent(typeof(ChaosBall));
                    ChaosBall chaosBall = newCube.GetComponent <ChaosBall>();
                    SetCubeInfo(chaosBall as _CubeBase, CubeLayers.cubeMoveable, CubeTypes.ChaosBall, false);
                    break;

                default:
                    //set epmty cubes as cubeEmpty
                    _Grid.instance.kuboGrid[recoveredNode.nodeIndex - 1].cubeLayers = CubeLayers.cubeEmpty;
                    _Grid.instance.kuboGrid[recoveredNode.nodeIndex - 1].cubeType   = CubeTypes.None;
                    break;
                }
            }


            foreach (Decor recoveredDecor in decor)
            {
                //Instantiate new decor thing

                GameObject newDecor = Instantiate(decorPrefab);

                _Grid.instance.placedDecor.Add(newDecor);

                newDecor.AddComponent(typeof(DecorObject));

                DecorObject decorObject = newDecor.GetComponent <DecorObject>();
                decorObject.LoadDecor(recoveredDecor);
            }

            finishedBuilding = true;
        }