Пример #1
0
    public void DrawSymbol(MhGesture gesture)
    {
        foreach (Vector2 v in gesture.points)
        {
            Vector3 v3screen = new Vector3(v.x, v.y);
            Vector3 v3Word   = Camera.main.ScreenToWorldPoint(v3screen);

            Vector3 pos = new Vector3();

            pos.x = v3Word.x;
            pos.y = v3Word.y;
            MhGesturePoint newPoint = InstancePoint(pos);
            if (lastVector == Vector2.zero)
            {
                lastVector    = v;
                firstPoint    = newPoint;
                lastGestPoint = newPoint;
            }
            else
            {
                lastGestPoint.SetNextPoint(newPoint);
                lastVector    = v;
                lastGestPoint = newPoint;
            }
        }
    }
Пример #2
0
    private MhGesturePoint InstancePoint(Vector3 worldPosition)
    {
        pointCount++;
        MhGesturePoint newPoint = Instantiate(spritePoint, worldPosition, new Quaternion(), parrentGesturePoint.transform).GetComponent <MhGesturePoint>();

        //Little magic for coloured change to help keep track of direction
        newPoint.GetComponent <SpriteRenderer>().color = new Color32((byte)(255 - (byte)Mathf.Abs(255 - (pointCount % 255))), (byte)(255 - Mathf.Abs(255 - (pointCount * 2 % 255))), 255, 255);
        return(newPoint);
    }
Пример #3
0
 public void ClearSymbol()
 {
     foreach (Transform child in parrentGesturePoint.transform)
     {
         Destroy(child.gameObject);
     }
     firstPoint = null;
     lastVector = new Vector2();
     pointCount = 0;
 }
Пример #4
0
    public MhGesture GetCurrentgesture()
    {
        MhGesture      gesture = new MhGesture();
        MhGesturePoint point   = firstPoint;

        while (point != null)
        {
            Vector3 currentScreenPos   = Camera.main.WorldToScreenPoint(point.transform.position);
            Vector2 currentScreenPos2D = new Vector2(currentScreenPos.x, currentScreenPos.y);
            point = point.after;
            gesture.Points.Add(currentScreenPos2D);
        }
        return(gesture);
    }
 public void DeleteLastPoint()
 {
     if (gestureInput.lastGestPoint == gestureInput.firstPoint)
     {
         gestureInput.ClearSymbol();
     }
     else
     {
         MhGesturePoint lastPoint       = gestureInput.lastGestPoint;
         MhGesturePoint secondLastPoint = lastPoint.before;
         Vector3        lastVector      = Camera.main.WorldToScreenPoint(secondLastPoint.transform.position);
         Destroy(lastPoint.gameObject);
         gestureInput.lastGestPoint = secondLastPoint;
         gestureInput.lastVector    = new Vector2(lastVector.x, lastVector.y);
         secondLastPoint.after      = null;
     }
 }
 public void SetNextPoint(MhGesturePoint nextPoint)
 {
     after            = nextPoint;
     nextPoint.before = this;
 }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftShift)))
        {
            drawing = true;
            Vector2 potentialLastVector = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            if (lastVector == Vector2.zero)
            {
                Vector3 pos           = new Vector3();
                Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                pos.x = mousePosWorld.x;
                pos.y = mousePosWorld.y;

                lastGestPoint = InstancePoint(pos);

                lastVector = potentialLastVector;
                firstPoint = lastGestPoint;
            }
            else if (Vector2.Distance(lastVector, potentialLastVector) >= maxDistance)
            {
                while (Vector2.Distance(lastVector, potentialLastVector) >= maxDistance)
                {
                    Vector2 direction   = potentialLastVector - lastVector;
                    Vector2 newPosition = lastVector + (direction / direction.magnitude) * maxDistance;// normalized direction * wanted direction;
                    Vector3 pos         = new Vector3();
                    pos.x = newPosition.x;
                    pos.y = newPosition.y;

                    Vector3 worldPosition = Camera.main.ScreenToWorldPoint(pos);
                    worldPosition.z = 0;

                    MhGesturePoint nextPoint = InstancePoint(worldPosition);

                    lastGestPoint.SetNextPoint(nextPoint);
                    lastGestPoint = nextPoint;
                    lastVector    = newPosition;
                    if (Input.GetKey(KeyCode.LeftControl))
                    {
                        break;
                    }
                }
            }
        }
        if (Input.GetMouseButton(1))
        {
            if (lastMousemovePosition == Vector2.zero)
            {
                Vector3 curentWord = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                lastMousemovePosition = new Vector2(curentWord.x, curentWord.y);
            }
            else
            {
                Vector3 curentWord  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Vector2 newPosition = new Vector2(curentWord.x, curentWord.y);
                Vector2 move        = newPosition - lastMousemovePosition;
                lastMousemovePosition = newPosition;
                MhGesturePoint pointChecked = firstPoint;
                while (pointChecked != null)
                {
                    pointChecked.transform.position = new Vector3(pointChecked.transform.position.x + move.x, pointChecked.transform.position.y + move.y, pointChecked.transform.position.z);
                    pointChecked = pointChecked.after;
                }
            }
        }
        else
        {
            lastMousemovePosition = Vector2.zero;
        }


        if (drawing && !Input.GetMouseButton(0))
        {
            drawing = false;

            //drawwing stop
        }
    }