示例#1
0
        public void RefreshWater(bool refreshNeighbors)
        {
            if (water == null)
            {
                return;
            }

            Edge bottomLeft = Lower.GetEdge(Upstream.CounterClockwise);
            Edge topLeft    = Upper.GetEdge(Upstream.Opposite.Clockwise);

            Edge bottomRight = Lower.GetEdge(Upstream.Clockwise);
            Edge topRight    = Upper.GetEdge(Upstream.Opposite.CounterClockwise);

            switch (Type)
            {
            case EdgeType.LAND:
            case EdgeType.WATER:
                water[Upstream] = new WaterVertex[]
                {
                    new WaterVertex(Lower, (bottomLeft == null || bottomLeft.Type != EdgeType.SHORE? ground[Upstream][0].GlobalPos : bottomLeft.water[Upstream.CounterClockwise][1].GlobalPos) - Lower.position),
                    new WaterVertex(Lower, (bottomRight == null || bottomRight.Type != EdgeType.SHORE? ground[Upstream][4].GlobalPos : bottomRight.water[Upstream.Clockwise][0].GlobalPos) - Lower.position)
                };

                water[Upstream.Opposite] = new WaterVertex[]
                {
                    new WaterVertex(Upper, (topRight == null || topRight.Type != EdgeType.SHORE? ground[Upstream.Opposite][0].GlobalPos : topRight.water[Upstream.Opposite.CounterClockwise][1].GlobalPos) - Upper.position),
                    new WaterVertex(Upper, (topLeft == null || topLeft.Type != EdgeType.SHORE? ground[Upstream.Opposite][4].GlobalPos : topLeft.water[Upstream.Opposite.Clockwise][0].GlobalPos) - Upper.position)
                };
                break;

            case EdgeType.SHORE:
                water[Upstream.Opposite] = new WaterVertex[]
                {
                    new WaterVertex(Lower, ground[Upstream][4].GlobalPos + Lerp(Lower.WaterLevel) - Lower.position, new Vector2(1f, 1f)),
                    new WaterVertex(Lower, ground[Upstream][0].GlobalPos + Lerp(Lower.WaterLevel) - Lower.position, new Vector2(0f, 1f))
                };

                water[Upstream] = new WaterVertex[]
                {
                    new WaterVertex(Lower, (bottomLeft == null || bottomLeft.Type != EdgeType.SHORE? chunk.world.LeftShoreVertex(this) : chunk.world.ShoreVertex(this, bottomLeft)) - Lower.position, new Vector2(0f, 0f)),
                    new WaterVertex(Lower, (bottomRight == null || bottomRight.Type != EdgeType.SHORE? chunk.world.RightShoreVertex(this) : chunk.world.ShoreVertex(bottomRight, this)) - Lower.position, new Vector2(1f, 0f))
                };

                shore = new WaterVertex[]
                {
                    new WaterVertex(Lower, ground[Upstream][1].GlobalPos + Lerp(Lower.WaterLevel) - Lower.position),
                    new WaterVertex(Lower, ground[Upstream][3].GlobalPos + Lerp(Lower.WaterLevel) - Lower.position)
                };
                shore[0].uv = new Vector2(1f, 1f);
                shore[1].uv = new Vector2(0f, 1f);

                if (refreshNeighbors)
                {
                    if (bottomLeft != null)
                    {
                        bottomLeft.RefreshWater(false);
                    }
                    if (bottomRight != null)
                    {
                        bottomRight.RefreshWater(false);
                    }
                }
                break;
            }
        }