示例#1
0
    public void Create()
    {
        rotate = true;

        this.type = (SliceType)Random.Range(0, 2);
        this.sprite.transform.rotation = Quaternion.identity;

        GameObject firstLine  = Instantiate(linePrefab, transform.position, Quaternion.identity, transform);
        GameObject secondLine = Instantiate(linePrefab, transform.position, Quaternion.identity, transform);

        first  = firstLine.GetComponent <SlicerLine>();
        second = secondLine.GetComponent <SlicerLine>();

        if (this.type == SliceType.CORNER)
        {
            this.sprite.sprite = corner;
            first.Create(LineDirection.UP, this);
            second.Create(LineDirection.RIGHT, this);
        }
        else
        {
            this.sprite.sprite = straight;
            first.Create(LineDirection.LEFT, this);
            second.Create(LineDirection.RIGHT, this);
        }

        int rotateTime = Random.Range(0, 4);

        for (int i = 0; i < rotateTime; i++)
        {
            Rotate();
        }
    }
示例#2
0
    // Check point exactly
    public Vector3 PointInLine(SlicerLine slicerLine, Line normalLine)
    {
        Vector3 result = Vector3.zero;

        if (slicerLine.direction == LineDirection.UP || slicerLine.direction == LineDirection.DOWN)
        {
            if (normalLine.direction == LineDirection.UP || normalLine.direction == LineDirection.DOWN)
            {
                // If closer to start
                if (Vector3.Distance(slicerLine.end, normalLine.end) >= Vector3.Distance(slicerLine.end, normalLine.start))
                {
                    normalLine = normalLine.GetShape().FindLineByEnd(normalLine.start);
                }
                // If closer to end
                else
                {
                    normalLine = normalLine.GetShape().FindLineByStart(normalLine.end);
                    //GameObject dup = Instantiate(normalLine.gameObject);
                }
            }
            result.x = slicerLine.start.x;
            result.y = normalLine.start.y;

            info.line = normalLine;
            line      = normalLine;
        }
        else
        {
            if (normalLine.direction == LineDirection.LEFT || normalLine.direction == LineDirection.RIGHT)
            {
                // If closer to start
                if (Vector3.Distance(slicerLine.end, normalLine.end) >= Vector3.Distance(slicerLine.end, normalLine.start))
                {
                    normalLine = normalLine.GetShape().FindLineByEnd(normalLine.start);
                }
                // If closer to end
                else
                {
                    normalLine = normalLine.GetShape().FindLineByStart(normalLine.end);
                }
            }
            result.x = normalLine.start.x;
            result.y = slicerLine.start.y;

            info.line = normalLine;
            line      = normalLine;
        }

        return(result);
    }