Пример #1
0
    void Update()
    {
        float   tipHeight = transform.Find("Tip").transform.localScale.y;
        Vector3 tip       = transform.Find("Tip/TouchPoint").transform.position;

        whiteboard.SetPenSize(10);
        //Debug.Log(tip);

        if (lastTouch)
        {
            tipHeight *= 1.1f;
        }

        if (Physics.Raycast(tip, transform.up, out touch, tipHeight))
        {
            if (touch.collider.tag == "Wallboard")
            {
                this.wallboard = touch.collider.GetComponent <WallBoard>();

                wallboard.SetColor(Color.black);
                wallboard.SetTouchPosition(touch.textureCoord.x, touch.textureCoord.y);
                wallboard.ToggleTouch(true);


                if (lastTouch == false)
                {
                    lastTouch = true;
                    lastAngle = transform.rotation;
                }
            }
            else if (touch.collider.tag == "Whiteboard")
            {
                this.whiteboard = touch.collider.GetComponent <Whiteboard>();

                whiteboard.SetColor(Color.black);
                whiteboard.SetTouchPosition(touch.textureCoord.x, touch.textureCoord.y);
                whiteboard.ToggleTouch(true);


                if (lastTouch == false)
                {
                    lastTouch = true;
                    lastAngle = transform.rotation;
                }
            }
        }
        else
        {
            whiteboard.ToggleTouch(false);
            lastTouch = false;
        }


        if (lastTouch)
        {
            transform.rotation = lastAngle;
        }
    }
    // Update is called once per frame
    void Update()
    {
        float   tipHeight = transform.Find("Tip").transform.localScale.y;
        Vector3 tip       = transform.Find("Tip/TouchPoint").transform.position;

        Debug.Log(tip);

        if (lastTouch)
        {
            tipHeight *= 1.1f;
        }

        // Check for a Raycast from the tip of the pen
        if (Physics.Raycast(tip, transform.up, out touch, tipHeight))
        {
            if (!(touch.collider.tag == "Whiteboard"))
            {
                return;
            }
            this.whiteboard = touch.collider.GetComponent <Whiteboard>();

            // Give haptic feedback when touching the whiteboard
            controllerActions.TriggerHapticPulse(0.05f);

            // Set whiteboard parameters
            whiteboard.SetColor(Color.blue);
            whiteboard.SetTouchPosition(touch.textureCoord.x, touch.textureCoord.y);
            whiteboard.ToggleTouch(true);

            // If we started touching, get the current angle of the pen
            if (lastTouch == false)
            {
                lastTouch = true;
                lastAngle = transform.rotation;
            }
        }
        else
        {
            whiteboard.ToggleTouch(false);
            lastTouch = false;
        }

        // Lock the rotation of the pen if "touching"
        if (lastTouch)
        {
            transform.rotation = lastAngle;
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        LineRenderer lineRenderer = GetComponent <LineRenderer>();

        lineRenderer.positionCount = 2;

        if (Input.GetKeyDown(KeyCode.Space) && !m_bIsDraw)
        {
            m_bIsDraw            = true;
            lineRenderer.enabled = true;
        }
        else if (Input.GetKeyDown(KeyCode.Space) && m_bIsDraw)
        {
            m_bIsDraw            = false;
            lineRenderer.enabled = false;
        }

        if (m_bIsDraw)
        {
            if (Physics.Raycast(transform.position, transform.forward, out hit) &&
                hit.collider.gameObject.name == "Whiteboard")
            {
                this.whiteboard = hit.collider.GetComponent <Whiteboard>();

                whiteboard.SetColor(Color.black);
                whiteboard.SetTouchPosition(hit.textureCoord.x, hit.textureCoord.y);
                whiteboard.ToggleTouch(true);

                if (lastTouch == false)
                {
                    lastTouch = true;
                    lastAngle = transform.rotation;
                }


                lineRenderer.startColor = Color.blue;
                lineRenderer.endColor   = Color.blue;
                lineRenderer.SetPosition(0, transform.position);
                lineRenderer.SetPosition(1, hit.point);

                ////if (Input.GetKeyDown(KeyCode.A) && !m_bIsDrawing)
                //if (Input.GetKeyDown(KeyCode.A) && !m_bIsDrawing)
                //{
                //    m_bIsDrawing = true;

                //    GameObject.Find("Board").GetComponent<testBoard>().m_HitPos = hit.point;
                //}
                //else if (Input.GetKeyDown(KeyCode.A) && m_bIsDrawing)
                //{
                //    m_bIsDrawing = false;
                //}
            }
            else
            {
                whiteboard.ToggleTouch(false);
                lastTouch = false;

                lineRenderer.startColor = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                lineRenderer.endColor   = new Color(1.0f, 1.0f, 1.0f, 0.0f);
            }

            if (lastTouch)
            {
                transform.rotation = lastAngle;
            }
        }
    }