Esempio n. 1
0
    private void Update()
    {
        int  wandCount            = ViveWand.wandCount;
        bool targeted             = false;
        bool targetedAndActivated = false;

        for (int i = 0; i < wandCount; i++)
        {
            ViveWand wand = ViveWand.Wand(i);

            if (!wand)
            {
                continue;
            }
            if (wand.skin == ViveWand.ViveWandSkins.Beam)
            {
                continue;
            }

            if (wand.targetedGameObject == gameObject)
            {
                targeted = true;

                if (wand.IsInteractionPressed(XperAction.Grip) || wand.IsInteractionPressed(XperAction.Trigger))
                {
                    targetedAndActivated = true;
                }
            }
        }

        if (targeted)
        {
            if ((m_scaleFactor <= 1) || (m_scaleFactor >= m_maxScale))
            {
                m_scaleFactorDirection = -m_scaleFactorDirection;
            }
        }
        else
        {
            m_scaleFactorDirection = -1;
        }

        m_scaleFactor += m_scaleFactorDirection * Time.deltaTime * m_scaleSpeed;
        m_scaleFactor  = Mathf.Max(Mathf.Min(m_scaleFactor, m_maxScale), 1);

        transform.localScale = m_scaleFactor * m_baseScale;

        if (m_isUpperArrow)
        {
            StageManager.MoveStageUp(targetedAndActivated);
        }
        else
        {
            StageManager.MoveStageDown(targetedAndActivated);
        }
    }
    private bool InteractsWithWand(out ViveWand interactionWand, out XperAction mode, out XperRange range)
    {
        int        wandCount       = ViveWand.wandCount;
        XperAction activationMode  = 0;
        XperRange  activationRange = 0;
        ViveWand   gripingWand     = null;

        m_isAtRangeOfWand = false;

        List <ViveWand> wands = new List <ViveWand>();

        for (int i = 0; i < wandCount; i++)
        {
            wands.Add(ViveWand.Wand(i));
        }

        if (m_interactionWand && wands.Contains(m_interactionWand))
        {
            if (wands[0] != m_interactionWand)
            {
                int      indexOfInteractionWand = wands.IndexOf(m_interactionWand);
                ViveWand tmp = wands[0];
                wands[0] = m_interactionWand;
                wands[indexOfInteractionWand] = tmp;
            }
        }

        foreach (ViveWand wand in wands)
        {
            if (!wand || !wand.gameObject.activeSelf)
            {
                continue;
            }

            if (!wand.upToDate)
            {
                wand.ForceUpdate();
            }

            XperAction[] actions = Enum.GetValues(typeof(XperAction)) as XperAction[];
            XperRange[]  ranges  = Enum.GetValues(typeof(XperRange)) as XperRange[];

            foreach (XperRange tmpRange in ranges)
            {
                foreach (XperAction tmpAction in actions)
                {
                    bool isAtRangeOfTestedWand = CheckAtRange(wand, tmpRange);
                    m_isAtRangeOfWand |= isAtRangeOfTestedWand;
                    if ((isAtRangeOfTestedWand || hasFocus) && CheckWandAction(wand, tmpAction, tmpRange))
                    {
                        activationMode  = tmpAction;
                        activationRange = tmpRange;
                        gripingWand     = wand;

                        break;
                    }
                }

                if (gripingWand)
                {
                    break;
                }
            }

            if (gripingWand)
            {
                break;
            }
        }

        range           = activationRange;
        interactionWand = gripingWand;
        mode            = activationMode;

        return(gripingWand != null);
    }