示例#1
0
    private void Update()
    {
        UpdateVisibleQuadrantScale();
        UpdateVisibleQuadrants();
        UpdateQuadrantChanges();

        if (Input.GetKeyDown(KeyCode.S))
        {
            SaveTerrain();
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            ShareTerrain();
        }

        if (Input.GetKeyDown(KeyCode.U))
        {
            List <Quadrant> quadrants = root.GetLeafQuadrants();
            quadrants.ForEach(x => x.ApplyAllTerrainChanges());
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            ConvertTerrainTo512();
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            allowQuadrantRequests = !allowQuadrantRequests;
            Debug.LogError("AllowQuadrantRequests = " + allowQuadrantRequests);
        }
    }
示例#2
0
    public List <Quadrant> GetLeafQuadrants()
    {
        List <Quadrant> leaves = new List <Quadrant>();

        // If quadrant has children, add leafquadrants of children
        if (bottomLeft != null)
        {
            leaves.AddRange(bottomLeft.GetLeafQuadrants());
        }
        if (bottomRight != null)
        {
            leaves.AddRange(bottomRight.GetLeafQuadrants());
        }
        if (topLeft != null)
        {
            leaves.AddRange(topLeft.GetLeafQuadrants());
        }
        if (topRight != null)
        {
            leaves.AddRange(topRight.GetLeafQuadrants());
        }

        // If quadrant has no children, this quadrant is a leaf
        if (leaves.Count == 0)
        {
            leaves.Add(this);
        }

        return(leaves);
    }
示例#3
0
    // This was a one use method for converting to 512x512
    private void ConvertTerrainTo512()
    {
        Debug.Log("convert start");

        // add every color to the color map
        Color[] colorMap = new Color[(int)maxSize * (int)maxSize];
        foreach (Quadrant quadrant in root.GetLeafQuadrants())
        {
            for (int i = 0; i < quadrant.colorMap.Length; i++)
            {
                colorMap[((quadrant.position.y + Mathf.FloorToInt(i / (int)minSize)) * (int)maxSize) + quadrant.position.x + (i % (int)minSize)] = quadrant.colorMap[i];
            }
        }

        Debug.Log("colormap done");

        // create new quadrants with new scale
        minSize = QuadrantSize.p256;
        root    = new Quadrant(maxSize, minSize, position);

        Debug.Log("quadrant creation done");

        // give quadrants appropriate colormaps
        foreach (Quadrant quadrant in root.GetLeafQuadrants())
        {
            quadrant.colorMap = new Color[(int)minSize * (int)minSize];
            for (int i = 0; i < quadrant.colorMap.Length; i++)
            {
                quadrant.colorMap[i] = colorMap[((quadrant.position.y + Mathf.FloorToInt(i / (int)minSize)) * (int)maxSize) + quadrant.position.x + (i % (int)minSize)];
            }
        }

        // give parent quadrants appropriate colormaps
        root.BuildColorMaps();

        Debug.Log("colormap assignment done");

        // generate textures for all quadrants
        DrawTerrain();

        // save all textures
    }