示例#1
0
    public void UpdateGround(List <Vector3> shapePoints = null)
    {
        // Skip cubes intersected by cutting line
        for (var i = 0; i < shapePoints.Count; i++)
        {
            var cubeX = (int)Mathf.Floor(shapePoints[i].x * _pointsPerUnit);
            var cubeZ = (int)Mathf.Floor(shapePoints[i].z * _pointsPerUnit);
            if (!_skippedQuads[cubeX, 0, cubeZ])
            {
                _skippedQuads[cubeX, 0, cubeZ] = true;
                // Debug.DrawLine(
                //     (new Vector3(cubeX, 0, cubeZ) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                //     (new Vector3(cubeX, 1, cubeZ) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                //     Color.green,999);
            }
        }

        // Find floating islands and drop them
        for (int z = 1; z < _zPoints - 1; z++)
        {
            for (int x = 1; x < _xPoints - 1; x++)
            {
                if (MyMaths.ContainsPoint(shapePoints, (new Vector3(x, 0, z) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit))
                {
                    _skippedQuads[x, 0, z] = true;
                    // Debug.DrawLine(
                    //     (new Vector3(x, 0, z) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                    //     (new Vector3(x, 2, z) + Vector3.forward * .5f + Vector3.right * .5f) / _pointsPerUnit,
                    //     Color.yellow, 999);
                }
            }
        }

        RegenerateMesh(shapePoints);

        var hole  = CreateHoleObject(shapePoints);
        var walls = CreateHoleWallObject(shapePoints);

        GiveHoleACollider(hole);

        Signals.Get <HoleGeneratedSignal>().Dispatch(hole, walls);
        // Debug.Log($"HoleGeneratedSignal F={Time.frameCount}", gameObject);

        _holeId++;
    }