示例#1
0
    public static AreaNoise BuildNoiseArea(int size, AreaNoiseDetails areaNoiseDetails, Vector2 center)
    {
        float[,] area = Noise.GenerateAreaValues(size, areaNoiseDetails.noiseDetails, center);

        // Curve copy for every thread to avoid accessing it in same time
        AnimationCurve threadCurve = new AnimationCurve(areaNoiseDetails.curve.keys);

        float minHeight = float.MaxValue;
        float maxHeight = float.MinValue;

        for (int yIndex = 0; yIndex < size; yIndex++)
        {
            for (int xIndex = 0; xIndex < size; xIndex++)
            {
                area[xIndex, yIndex] *= threadCurve.Evaluate(area[xIndex, yIndex]) * areaNoiseDetails.heightMultiplier;

                if (area[xIndex, yIndex] < minHeight)
                {
                    minHeight = area[xIndex, yIndex];
                }
                if (area[xIndex, yIndex] > maxHeight)
                {
                    maxHeight = area[xIndex, yIndex];
                }
            }
        }

        return(new AreaNoise(area, minHeight, maxHeight));
    }
    public Area(Vector2 coords, Transform parent, Material material, LODDetails[] lodDetails, int colliderLODIndex, AreaNoiseDetails areaNoiseDetails, AreaDetails areaDetails, Transform player)
    {
        this.areaNoiseDetails = areaNoiseDetails;
        this.areaDetails      = areaDetails;

        center = coords * areaDetails.resolution / areaDetails.scale;

        Vector3 position = coords * areaDetails.resolution;

        instance = new GameObject("Area" + parent.childCount);
        instance.transform.position = new Vector3(position.x, 0, position.y);
        instance.transform.parent   = parent;

        bounds = new Bounds(position, Vector2.one * areaDetails.resolution);

        SetVisible(false);

        meshRenderer          = instance.AddComponent <MeshRenderer>();
        meshFilter            = instance.AddComponent <MeshFilter>();
        meshRenderer.material = material;

        this.lodDetails = lodDetails;
        lodMeshes       = new LODMesh[lodDetails.Length];

        for (int index = 0; index < lodDetails.Length; index++)
        {
            lodMeshes[index]         = new LODMesh(lodDetails[index].lod);
            lodMeshes[index].update += UpdateArea;

            if (index == colliderLODIndex)
            {
                lodMeshes[index].update += UpdateCollider;
            }
        }

        this.colliderLODIndex = colliderLODIndex;
        collider = instance.AddComponent <MeshCollider>();

        this.coords = coords;
        this.player = player;
        viewRange   = lodDetails[lodDetails.Length - 1].distance;
    }