Ejemplo n.º 1
0
    public void Init(TypeLineFind typeLine, int index, bool isSketching)
    {
        isRun               = true;
        this.typeLine       = typeLine;
        this.dir            = index == 0 ?-1:1;
        isCompleteSketching = isSketching;
        RaycastHit2D hit;

        if (typeLine == TypeLineFind.horizontal)
        {
            scaleCur  = new Vector2(0, 1);
            hit       = Physics2D.Linecast(transform.position, (Vector2)transform.position + Vector2.right * dir * 20000, layerMask);
            posTarget = hit.point;
            int posX = MathfExtension.FloorToInt(posTarget.x);
            Debug.Log("posTarGetX:" + posTarget.x + " point:" + hit.point + " posX:" + posX + " POSTARGET:" + posTarget);

            posTarget.x = posX + ((int)dir * GameConfig.SIZE_HALF_LINE);
        }
        else
        {
            scaleCur  = new Vector2(1, 0);
            hit       = Physics2D.Linecast(transform.position, (Vector2)transform.position + Vector2.up * dir * 20000, layerMask);
            posTarget = hit.point;
            int posY = MathfExtension.FloorToInt(posTarget.y);
            Debug.Log("posTarGetY:" + posTarget.x + " point:" + hit.point + " posY:" + posY + " POSTARGET:" + posTarget);
            posTarget.y = posY + ((int)dir * GameConfig.SIZE_HALF_LINE);
        }
        //Debug.Log("hit:"+transform.position+"=>"+posTarget);
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (GameplayController.Instance.canCreateLine == false)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            originPos = Input.mousePosition;
            originPos = cam.ScreenToWorldPoint(originPos);
        }
        if (Input.GetMouseButtonUp(0))
        {
            endPos = Input.mousePosition;
            endPos = cam.ScreenToWorldPoint(endPos);
            Vector2 posMouse = originPos;


            TypeLineFind typeSwipe = TypeLineFind.vertical;
            if (Mathf.Abs(endPos.x - originPos.x) >= Mathf.Abs(endPos.y - originPos.y))
            {
                typeSwipe = TypeLineFind.horizontal;
            }

            for (int i = 0; i < GameplayController.Instance.pointsList.Count; i++)
            {
                Vector2[] points = GameplayController.Instance.GetPointsBoard(i);

                if (points.Length > 0 && Utilities.IsPointInPolygon(posMouse, points))
                {
                    RaycastHit2D hit = Physics2D.BoxCast(posMouse, Vector2.one * (GameplayController.Instance.sizeLine.x * 2), 0, Vector2.zero, 0);
                    if (hit.collider == null)
                    {
                        posMouse.x = MathfExtension.FloorToInt(posMouse.x);
                        posMouse.y = MathfExtension.FloorToInt(posMouse.y);
                        posMouse   = GameplayController.Instance.RoundPosCreateLine(i, (Vector2)posMouse);
                        posMouse.x = MathfExtension.FloorToInt(posMouse.x);
                        posMouse.y = MathfExtension.FloorToInt(posMouse.y);
                        Debug.Log("posMouse:" + posMouse);
                        GameplayController.Instance.indexMask = i;
                        GameplayController.Instance.CreateLine(typeSwipe, posMouse);
                    }
                }
            }
        }
    }