Exemple #1
0
        // ------------------------------------------------------------------------
        public override void createObjects()
        {
            GameObject go;

            PrefabLevelEditor.PartList partId;

            float distance = _cubeSize;

            int xStart = _width / 2 * -1;
            int xEnd   = xStart + _width;
            int zStart = _depth / 2 * -1;
            int zEnd   = zStart + _depth;

            int x, z;

            for (x = xStart; x < xEnd; ++x)
            {
                for (z = zStart; z < zEnd; ++z)
                {
                    Vector3 pos = new Vector3(x * distance, 0, z * distance);

                    partId = parts [Random.Range(0, parts.Length)].id;
                    go     = PrefabLevelEditor.Instance.createPartAt(partId, 0, 0, 0);

                    if (go != null)
                    {
                        go.name = "temp_part_" + _container.transform.childCount.ToString();
                        go.transform.SetParent(_container.transform);
                        go.transform.localPosition = pos;
                        go.transform.rotation      = Quaternion.Euler(new Vector3(0, Random.Range(0, 4) * 90, 0));

                        LevelController.Instance.setMeshCollider(go, false);
                        LevelController.Instance.setRigidBody(go, false);

                        LevelController.LevelElement element = new LevelController.LevelElement();
                        element.go   = go;
                        element.part = partId;

                        _dungeonElements.Add(element);
                    }
                }
            }
        }
        // ------------------------------------------------------------------------
        private void createElement(Vector3 pos)
        {
            GameObject go = PrefabLevelEditor.Instance.createPartAt(_curPart.id, 0, 0, 0);

            if (go != null)
            {
                go.name = "temp_part_" + _container.transform.childCount.ToString();
                go.transform.SetParent(_container.transform);
                go.transform.localPosition = pos;

                LevelController.Instance.setMeshCollider(go, false);
                LevelController.Instance.setRigidBody(go, false);

                LevelController.LevelElement element = new LevelController.LevelElement();
                element.go   = go;
                element.part = _curPart.id;

                _roomElements.Add(element);
            }
        }
        // ------------------------------------------------------------------------
        public override void createObjects()
        {
            GameObject go;

            PrefabLevelEditor.PartList partId;

            float distance = _cubeSize;
            bool  isWall   = false;

            int xStart = _width / 2 * -1;
            int xEnd   = xStart + _width;
            int zStart = _depth / 2 * -1;
            int zEnd   = zStart + _depth;

            int x, z;

            for (x = xStart; x < xEnd; ++x)
            {
                for (z = zStart; z < zEnd; ++z)
                {
                    Vector3 pos = new Vector3(x * distance, 0, z * distance);

                    isWall = false;
                    if (x > xStart && z > zStart && x < (xEnd - 1) && z < (zEnd - 1))
                    {
                        partId = partTurn.id;
                    }
                    else
                    {
                        if ((x == xStart && z == zStart) || (x == (xEnd - 1) && z == (zEnd - 1)) || (x == xStart && z == (zEnd - 1)) || (x == (xEnd - 1) && z == zStart))
                        {
                            partId = partCorner.id;
                        }
                        else
                        {
                            partId = partWall.id;
                        }
                        isWall = true;
                    }

                    go = PrefabLevelEditor.Instance.createPartAt(partId, 0, 0, 0);

                    if (go != null)
                    {
                        go.name = "temp_part_" + _container.transform.childCount.ToString();
                        go.transform.SetParent(_container.transform);
                        go.transform.localPosition = pos;

                        if (isWall)
                        {
                            if (x == xStart && z == (zEnd - 1))
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                            }
                            else if (x == (xEnd - 1) && z == zStart)
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                            }
                            else if (x == xStart)
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                            }
                            else if (x == (xEnd - 1))
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
                            }
                            else if (z == zStart)
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                            }
                            else if (z == (zEnd - 1))
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                            }
                        }
                        else
                        {
                            go.transform.rotation = Quaternion.Euler(new Vector3(0, Random.Range(0, 4) * 90, 0));
                        }

                        LevelController.Instance.setMeshCollider(go, false);
                        LevelController.Instance.setRigidBody(go, false);

                        LevelController.LevelElement element = new LevelController.LevelElement();
                        element.go   = go;
                        element.part = partId;

                        _dungeonElements.Add(element);
                    }
                }
            }
        }
Exemple #4
0
        // ------------------------------------------------------------------------
        public override void createObjects()
        {
            GameObject go;

            PrefabLevelEditor.PartList partId;

            float distance = _cubeSize;
            bool  isWall   = false;

            int xStart = _width / 2 * -1;
            int xEnd   = xStart + _width;
            int zStart = _depth / 2 * -1;
            int zEnd   = zStart + _depth;

            int   stairsStep     = 0;
            float stairsRotation = 0;
            bool  isStairs       = false;

            int x, z, y;

            // create stair step positions first
            List <stairStep> stairSteps = new List <stairStep> ();
            stairStep        step;

            for (y = 0; y < _height; ++y)
            {
                // first stairs
                if (stairsStep == 0)
                {                       // z+
                    step = new stairStep(new Vector3Int(xStart, y, zEnd - 2), stairsRotation, partStairsLower.id);
                    stairSteps.Add(step);
                    step = new stairStep(new Vector3Int(xStart, y, zEnd - 1), stairsRotation, partStairsUpper.id);
                    stairSteps.Add(step);
                }
                else if (stairsStep == 1)
                {                       // x+
                    step = new stairStep(new Vector3Int(xEnd - 2, y, zEnd - 1), stairsRotation, partStairsLower.id);
                    stairSteps.Add(step);
                    step = new stairStep(new Vector3Int(xEnd - 1, y, zEnd - 1), stairsRotation, partStairsUpper.id);
                    stairSteps.Add(step);
                }
                else if (stairsStep == 2)
                {                       // z-
                    step = new stairStep(new Vector3Int(xEnd - 1, y, zStart + 1), stairsRotation, partStairsLower.id);
                    stairSteps.Add(step);
                    step = new stairStep(new Vector3Int(xEnd - 1, y, zStart), stairsRotation, partStairsUpper.id);
                    stairSteps.Add(step);
                }
                else if (stairsStep == 3)
                {                       // x-
                    step = new stairStep(new Vector3Int(xStart + 1, y, zStart), stairsRotation, partStairsLower.id);
                    stairSteps.Add(step);
                    step = new stairStep(new Vector3Int(xStart, y, zStart), stairsRotation, partStairsUpper.id);
                    stairSteps.Add(step);
                }

                stairsStep     = (stairsStep < 3 ? stairsStep + 1 : 0);
                stairsRotation = (stairsRotation < 270 ? stairsRotation + 90 : 0);
            }

            for (x = xStart; x < xEnd; ++x)
            {
                for (z = zStart; z < zEnd; ++z)
                {
                    for (y = 0; y <= _height; ++y)
                    {
                        Vector3 pos = new Vector3(x * distance, y * distance, z * distance);

                        isWall   = false;
                        isStairs = false;

                        partId = partFloor.id;

                        if (y == _height)
                        {
                            if (!_ceiling)
                            {
                                continue;
                            }
                            else
                            {
                                partId = partFloor.id;
                            }
                        }
                        else if (x == xStart && y == 0 && z == zStart)
                        {
                            partId = partWall.id;
                        }
                        else
                        {
                            int s, numStairSteps = stairSteps.Count;
                            for (s = 0; s < numStairSteps; ++s)
                            {
                                if (stairSteps[s].pos.x == x && stairSteps[s].pos.y == y && stairSteps[s].pos.z == z)
                                {
                                    step           = stairSteps [s];
                                    partId         = step.partId;
                                    stairsRotation = step.rot;
                                    isStairs       = true;
                                    break;
                                }
                            }

                            if (!isStairs)
                            {
                                if (x > xStart && z > zStart && x < (xEnd - 1) && z < (zEnd - 1))
                                {
                                    if (y > 0)
                                    {
                                        continue;                                         // no floors on upper floors
                                    }
                                    partId = partFloor.id;
                                }
                                else
                                {
                                    if ((x == xStart && z == zStart) || (x == (xEnd - 1) && z == (zEnd - 1)) || (x == xStart && z == (zEnd - 1)) || (x == (xEnd - 1) && z == zStart))
                                    {
                                        if (y > 0)
                                        {
                                            partId = partCornerNF.id;
                                        }
                                        else
                                        {
                                            partId = partCorner.id;
                                        }
                                    }
                                    else
                                    {
                                        if (y > 0)
                                        {
                                            partId = partWallNF.id;
                                        }
                                        else
                                        {
                                            partId = partWall.id;
                                        }
                                    }
                                    isWall = true;
                                }
                            }
                        }

                        go = PrefabLevelEditor.Instance.createPartAt(partId, 0, 0, 0);

                        if (go != null)
                        {
                            go.name = "temp_part_" + _container.transform.childCount.ToString();
                            go.transform.SetParent(_container.transform);
                            go.transform.localPosition = pos;

                            if (isStairs)
                            {
                                go.transform.rotation = Quaternion.Euler(new Vector3(0, stairsRotation, 0));
                            }
                            else if (isWall)
                            {
                                if (x == xStart && z == (zEnd - 1))
                                {
                                    go.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                                }
                                else if (x == (xEnd - 1) && z == zStart)
                                {
                                    go.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                                }
                                else if (x == xStart)
                                {
                                    go.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                                }
                                else if (x == (xEnd - 1))
                                {
                                    go.transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
                                }
                                else if (z == zStart)
                                {
                                    go.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                                }
                                else if (z == (zEnd - 1))
                                {
                                    go.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                                }
                            }

                            LevelController.Instance.setMeshCollider(go, false);
                            LevelController.Instance.setRigidBody(go, false);

                            LevelController.LevelElement element = new LevelController.LevelElement();
                            element.go   = go;
                            element.part = partId;

                            _dungeonElements.Add(element);
                        }
                    }
                }
            }
        }