예제 #1
0
    public void Load()
    {
        Tabs tabs = GameObject.Find("Phases").GetComponent <Tabs>();

        tabs.activateAll();

        EnviromentSaveAndLoadManager.getInstance().loadMap();
        DetailsSaveAndLoadManager.getInstance().loadDetails();
        TerraformSaveAndLoadManager.getInstance().loadMap();

        ChunkRenderer.renderAll();

        tabs.returnState();
    }
예제 #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Z))
        {
            if (objectsPutThisClick.Count > 0)
            {
                for (int i = 0; i < objectsPutThisClick[0].Count; i++)
                {
                    Vector3 v = objectsPutThisClick[0][i];
                    chunkMap.blockGrid[(int)v.x, (int)v.y, (int)v.z] = new Block(0, 0, 0);
                }
                objectsPutThisClick.RemoveAt(0);
                ChunkRenderer.renderAll();
            }
            return;
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            if (rotation == 3)
            {
                rotation = 0;
            }
            else
            {
                rotation++;
            }
        }

        if (eventSys.IsPointerOverGameObject())
        {
            return;
        }

        ShowGuider();

        if (Input.GetMouseButtonDown(0))
        {
            if (objectsPutThisClick.Count >= 10)
            {
                objectsPutThisClick.RemoveAt(9);
            }

            objectsPutThisClick.Insert(0, new List <Vector3>());
        }

        if (Input.GetMouseButtonUp(0))
        {
            ChunkRenderer.renderAll();
        }

        if (Input.GetMouseButton(0))
        {
            Ray        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit floorHit;
            float      camRayLength = 100f;
            if (Physics.Raycast(cameraRay, out floorHit, camRayLength, LayerMask.GetMask("Floor")))
            {
                Vector3 a    = floorHit.point;
                Vector3 orig = getLocationOfOriginalBlock(a);

                //Bugfix for dragging from UI to game.
                if (objectsPutThisClick == null || objectsPutThisClick.Count == 0)
                {
                    return;
                }

                //If clicked smoothedge
                if (blockIsInsideSmoothBounds(orig))
                {
                    if (chunkMap.blockGrid[(int)orig.x, (int)orig.y, (int)orig.z].shape == ObjectController.SMOOTHBORDER)
                    {
                        a    += Vector3.down;
                        orig += Vector3.down;
                    }
                }

                if (!objectsPutThisClick[0].Contains(new Vector3(orig.x, orig.y, orig.z)))
                {
                    a = getLocationOfNewBlock(a);

                    ObjectController oc = ObjectController.getInstance();

                    for (int i = 0; i < x; i++)
                    {
                        for (int j = 0; j < y; j++)
                        {
                            for (int k = 0; k < z; k++)
                            {
                                Vector3 b = new Vector3();

                                b.x = (int)(a.x) + i;
                                b.y = a.y + k;
                                b.z = (int)(a.z) + j;

                                if (oc.shape != ObjectController.SMOOTH)
                                {
                                    if (blockIsInsideBounds(b))
                                    {
                                        chunkMap.blockGrid[(int)b.x, (int)b.y, (int)b.z] = new Block(oc.shape, oc.texture + 1, rotation);
                                        objectsPutThisClick[0].Add(new Vector3((int)b.x, (int)b.y, (int)b.z));
                                    }
                                }
                                else
                                {
                                    if (blockIsInsideSmoothBounds(b))
                                    {
                                        chunkMap.blockGrid[(int)b.x, (int)b.y, (int)b.z] = new Block(oc.shape, oc.texture + 1, rotation);
                                        objectsPutThisClick[0].Add(new Vector3((int)b.x, (int)b.y, (int)b.z));
                                    }
                                }
                            }
                        }
                    }
                    if (objectsPutThisClick.Count != 0 && objectsPutThisClick[0].Count != 0)
                    {
                        ChunkRenderer.renderTemporarily(objectsPutThisClick[0]);
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Ray        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit floorHit;
            float      camRayLength = 200f;

            if (Physics.Raycast(cameraRay, out floorHit, camRayLength, LayerMask.GetMask("Floor")))
            {
                Vector3 a = floorHit.point;

                a = getLocationOfOriginalBlock(a);

                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        for (int k = 0; k < z; k++)
                        {
                            Vector3 b = new Vector3();

                            b.x = (int)(a.x) + i;
                            b.y = a.y - k;
                            b.z = (int)(a.z) + j;

                            if (blockIsInsideBounds(b))
                            {
                                chunkMap.blockGrid[(int)b.x, (int)b.y, (int)b.z] = new Block(0, 0, 0);
                            }
                        }
                    }
                }
                ChunkRenderer.renderAll();
            }
        }
    }
    public void loadMap()
    {
        ChunkMap chunkMap = GameObject.Find("EnviromentController").GetComponent <ChunkMap>();

        for (int i = 0; i < ChunkMap.SizeX; i++)
        {
            for (int j = 0; j < ChunkMap.SizeY; j++)
            {
                for (int k = 0; k < ChunkMap.SizeZ; k++)
                {
                    chunkMap.blockGrid[i, j, k] = new Block(0, 0, 0);
                }
            }
        }

        string text = SaveAndLoadManager.getInstance().loadText(key);

        string[] lines = text.Split('\n');
        int      count = 0;

        List <Block> blocks       = new List <Block>();
        Regex        blockSegment = new Regex(@"\d+\/\d+\/\d+\/\d+");
        Regex        emptySegment = new Regex(@"-\/-\/-\/\d+");

        foreach (string line in lines)
        {
            //Has Block
            if (blockSegment.IsMatch(line))
            {
                int    shape   = int.Parse(line.Substring(0, line.IndexOf('/')));
                string rest    = line.Substring(line.IndexOf('/') + 1);
                int    texture = int.Parse(rest.Substring(0, rest.IndexOf('/')));
                rest = rest.Substring(rest.IndexOf('/') + 1);
                int rotation = int.Parse(rest.Substring(0, rest.IndexOf('/')));
                rest = rest.Substring(rest.IndexOf('/') + 1);
                int amount = int.Parse(rest);

                for (int i = 0; i < amount; i++)
                {
                    Block block = new Block(shape, texture, rotation);

                    int z = count % ChunkMap.SizeZ;
                    int x = count / ChunkMap.SizeZ % ChunkMap.SizeX;
                    int y = count / (ChunkMap.SizeZ * ChunkMap.SizeX);

                    chunkMap.blockGrid[x, y, z] = block;

                    count++;
                }
                //Is Empty
            }
            else if (emptySegment.IsMatch(line))
            {
                string rest   = line.Substring(line.LastIndexOf('/') + 1);
                int    amount = int.Parse(rest);

                count += amount;
            }
        }

        ChunkRenderer.renderAll();
    }