Ejemplo n.º 1
0
    private void GenerateFluidGrid()
    {
        Vector2 tempIntersection = Vector2.zero;

        foreach (PaintingCell cell in Cells)
        {
            Vector2 centerPoint    = cell.visiblePolyExtrude.CenterPoint;
            float   bestUpDelta    = float.PositiveInfinity;
            float   bestDownDelta  = float.PositiveInfinity;
            float   bestLeftDelta  = float.PositiveInfinity;
            float   bestRightDelta = float.PositiveInfinity;

            FluidSelectable fluidSelectable = cell.fluidSelectable;
            fluidSelectable.up    = null;
            fluidSelectable.down  = null;
            fluidSelectable.left  = null;
            fluidSelectable.right = null;

            foreach (PaintingCell otherCell in Cells)
            {
                if (otherCell == cell)
                {
                    continue;
                }

                if (Vector2Extensions.GetLinePolyIntersection(out tempIntersection, centerPoint, Vector2.up, otherCell.visiblePolyExtrude.points))
                {
                    float delta = (tempIntersection - centerPoint).sqrMagnitude;
                    if (delta < bestUpDelta)
                    {
                        bestUpDelta        = delta;
                        fluidSelectable.up = otherCell.fluidSelectable;
                    }
                }

                if (Vector2Extensions.GetLinePolyIntersection(out tempIntersection, centerPoint, Vector2.down, otherCell.visiblePolyExtrude.points))
                {
                    float delta = (tempIntersection - centerPoint).sqrMagnitude;
                    if (delta < bestDownDelta)
                    {
                        bestDownDelta        = delta;
                        fluidSelectable.down = otherCell.fluidSelectable;
                    }
                }

                if (Vector2Extensions.GetLinePolyIntersection(out tempIntersection, centerPoint, Vector2.left, otherCell.visiblePolyExtrude.points))
                {
                    float delta = (tempIntersection - centerPoint).sqrMagnitude;
                    if (delta < bestLeftDelta)
                    {
                        bestLeftDelta        = delta;
                        fluidSelectable.left = otherCell.fluidSelectable;
                    }
                }

                if (Vector2Extensions.GetLinePolyIntersection(out tempIntersection, centerPoint, Vector2.right, otherCell.visiblePolyExtrude.points))
                {
                    float delta = (tempIntersection - centerPoint).sqrMagnitude;
                    if (delta < bestRightDelta)
                    {
                        bestRightDelta        = delta;
                        fluidSelectable.right = otherCell.fluidSelectable;
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    private bool SetupPaletteToPaintingLinks()
    {
        Vector2 tempIntersection = Vector2.zero;

        foreach (PaletteColor paletteColor in _paletteColors)
        {
            Vector2 direction = Vector2.zero;
            switch (paletteColor.paintingDirection)
            {
            case PaletteColor.Direction.Down:
                direction = Vector2.down;
                break;

            case PaletteColor.Direction.Left:
                direction = Vector2.left;
                break;

            default:
                continue;
            }

            FluidSelectable paletteFluidSelectable = paletteColor.fluidSelectable;

            float           bestDelta = float.PositiveInfinity;
            FluidSelectable bestCellFluidSelectable = null;

            foreach (PaintingCell cell in _painting.Cells)
            {
                if (Vector2Extensions.GetLinePolyIntersection(out tempIntersection, paletteColor.paintingPoint, direction, cell.visiblePolyExtrude.points))
                {
                    float delta = (tempIntersection - paletteColor.paintingPoint).sqrMagnitude;
                    if (delta < bestDelta)
                    {
                        bestDelta = delta;
                        bestCellFluidSelectable = cell.fluidSelectable;
                    }
                }
            }

            if (bestCellFluidSelectable != null)
            {
                switch (paletteColor.paintingDirection)
                {
                case PaletteColor.Direction.Down:
                    paletteFluidSelectable.down = bestCellFluidSelectable;
                    if (bestCellFluidSelectable.up == null)
                    {
                        bestCellFluidSelectable.up = paletteFluidSelectable;
                    }
                    break;

                case PaletteColor.Direction.Left:
                    paletteFluidSelectable.left = bestCellFluidSelectable;
                    if (bestCellFluidSelectable.right == null)
                    {
                        bestCellFluidSelectable.right = paletteFluidSelectable;
                    }
                    break;

                default:
                    break;
                }
            }
        }

        return(true);
    }