Пример #1
0
 void checkForUserInput()
 {
     if (stylus.GetButton(0))
     {
         if (!point0)
         {
             point0    = stylusTip.transform;
             location0 = stylusTip.transform.position;
         }
         else if (!point1)
         {
             point1    = stylusTip.transform;
             location1 = stylusTip.transform.position;
         }
         else
         {
             endPoints.transform.localScale = new Vector3(.01f, .01f, .01f);
             createLine(location0, location1);
             if (pointSwitch)
             {
                 point0 = null;
             }
             else
             {
                 point1 = null;
             }
             pointSwitch = !pointSwitch;
         }
     }
     else if (stylus.GetButtonUp(0))
     {
         point0 = null;
         point1 = null;
     }
     else if (stylus.GetButtonDown(1))
     {
         if (colorNumber + 1 < colorArray.Length)
         {
             changeColor(++colorNumber);
         }
     }
     else if (stylus.GetButtonDown(2))
     {
         if (colorNumber - 1 >= 0)
         {
             changeColor(--colorNumber);
         }
     }
     else if (Input.GetKeyDown(KeyCode.C))
     {
         Destroy(container.gameObject);
         lineCount   = 0;
         objectCount = 0;
         container   = new GameObject("Drawing").transform;
     }
     else if (Input.GetKeyDown(KeyCode.Z))
     {
         Destroy(container.GetChild(container.childCount - 1).gameObject);
     }
 }
Пример #2
0
    void Update()
    {
        bool isButtonDown = _selectButtons.Aggregate(false, (isPressed, buttonId) => isPressed |= _stylusSelector.GetButtonDown(buttonId));

        if (isButtonDown)
        {
            if (_stylusSelector.HoverObject == null)
            {
                _startPosition = _stylusSelector.activeStylus.hotSpot;
                _startRotation = (_isAxisAligned) ? Quaternion.identity : _stylusSelector.activeStylus.transform.rotation;

                GetComponent <Collider>().enabled = true;
                GetComponent <Renderer>().enabled = true;
                transform.rotation = _startRotation;
            }
        }

        bool isButton = _selectButtons.Aggregate(false, (isPressed, buttonId) => isPressed |= _stylusSelector.GetButton(buttonId));

        if (isButton && GetComponent <Renderer>().enabled)
        {
            _endPosition = _stylusSelector.activeStylus.hotSpot;

            Vector3 diagonal = _endPosition - _startPosition;
            transform.localScale = Quaternion.Inverse(transform.rotation) * diagonal;
            transform.position   = 0.5f * (_endPosition + _startPosition);
        }

        bool isButtonUp = _selectButtons.Aggregate(false, (isPressed, buttonId) => isPressed |= _stylusSelector.GetButtonUp(buttonId));

        if (isButtonUp)
        {
            GetComponent <Collider>().enabled = false;
            GetComponent <Renderer>().enabled = false;
        }
    }