Esempio n. 1
0
    public List <Quadrant> FindQuadrantsOfSize(QuadrantSize size)
    {
        List <Quadrant> quadrantsOfSize = new List <Quadrant>();

        if (this.size.x == (int)size)
        {
            quadrantsOfSize.Add(this);
        }
        else
        {
            if (bottomLeft != null)
            {
                quadrantsOfSize.AddRange(bottomLeft.FindQuadrantsOfSize(size));
            }
            if (bottomRight != null)
            {
                quadrantsOfSize.AddRange(bottomRight.FindQuadrantsOfSize(size));
            }
            if (topLeft != null)
            {
                quadrantsOfSize.AddRange(topLeft.FindQuadrantsOfSize(size));
            }
            if (topRight != null)
            {
                quadrantsOfSize.AddRange(topRight.FindQuadrantsOfSize(size));
            }
        }

        return(quadrantsOfSize);
    }
Esempio n. 2
0
    private void UpdateVisibleQuadrants()
    {
        // Find quadrants that have to be visible
        List <Quadrant> newActiveQuadrants = new List <Quadrant>();

        foreach (Quadrant quadrant in root.FindQuadrantsOfSize(visibleQuadrantScale))
        {
            if (quadrant.VisibleByMainCam())
            {
                newActiveQuadrants.Add(quadrant);
            }
        }

        // Deactivate visible quadrants that have to be invisible
        for (int i = visibleQuadrants.Count - 1; i >= 0; i--)
        {
            Quadrant quadrant = visibleQuadrants[i];
            if (!newActiveQuadrants.Contains(quadrant))
            {
                quadrant.SetVisible(false);
                TerrainTexture terrainTexture = visibleQuadrantPairs[quadrant];
                terrainTexture.Deactivate();
                visibleQuadrantPairs.Remove(quadrant);
                terrainTexturePool.Add(terrainTexture);
            }
        }

        // Activate new visible quadrants
        visibleQuadrants = newActiveQuadrants;
        foreach (Quadrant quadrant in visibleQuadrants)
        {
            if (!visibleQuadrantPairs.ContainsKey(quadrant))
            {
                quadrant.SetVisible(true);

                // Only instantiate a new terrainTexture if the pool is empty
                if (terrainTexturePool.Count == 0)
                {
                    terrainTexturePool.Add(Instantiate(terrainPlanePrefab, transform));
                }

                TerrainTexture terrainTexture = terrainTexturePool[0];
                terrainTexturePool.Remove(terrainTexture);
                terrainTexture.gameObject.SetActive(true);
                terrainTexture.Setup(quadrant, loadType != TerrainLoadType.NONE);
                visibleQuadrantPairs.Add(quadrant, terrainTexture);
            }
        }
    }