Пример #1
0
    public void InitTouchControl()
    {
        var recognizer = new TKPanRecognizer();

        //recognizer.boundaryFrame = new TKRect(50f, 0,public GameObject ColorPicker;
        //public Material ColorPickerMaterial; 100f, 100f);

        // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            recognizer.minimumNumberOfTouches = 2;
        }

        recognizer.gestureRecognizedEvent += (r) =>
        {
            //Camera.main.transform.position -= new Vector3(recognizer.deltaTranslation.x, recognizer.deltaTranslation.y) / 100;
            //Debug.Log("pan recognizer fired: " + r);
            //Debug.Log(recognizer.touchLocation());
            //Debug.Log(recognizer.state);
            if (!EventSystem.current.IsPointerOverGameObject() || true)
            {
                if (IsDrawing == false)
                {
                    clone     = (GameObject)Instantiate(LineObject);
                    clone.tag = "ARLines";
                    clone.GetComponent <LineRenderer>().material = CurrentMaterial;
                    clone.transform.parent = DrawSpace.transform;

                    line = clone.GetComponent <LineRenderer>();
                    //line.material.color = Color.white;
                    line.startWidth = LineWidth;
                    line.endWidth   = LineWidth;
                    LineDividNumber = 0;
                    IsDrawing       = true;
                }
                else
                {
                    LineDividNumber++;
                    line.positionCount = LineDividNumber;
                    Vector2 touchLocation = recognizer.touchLocation();
                    line.SetPosition(LineDividNumber - 1, TargetCamera.ScreenToWorldPoint(new Vector3(touchLocation.x, touchLocation.y, DrawOffset)));
                }
            }
        };

        // continuous gestures have a complete event so that we know when they are done recognizing
        recognizer.gestureCompleteEvent += r =>
        {
            Debug.Log("pan gesture complete");
            IsDrawing = false;
        };
        TouchKit.addGestureRecognizer(recognizer);
    }