Esempio n. 1
0
    protected override void OnConfigUpdated()
    {
        base.OnConfigUpdated();

        cursorDotSize *= 0.6f;

        UpdateLineRenderers();
        SetLineRendererWidthScale(1);

        Color fillColour   = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorRingColor, SettingsConfig.Config.CursorRingOpacity);
        Color borderColour = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotBorderColor, SettingsConfig.Config.CursorDotBorderOpacity);

        Gradient gradient = new Gradient();

        gradient.SetKeys(
            new GradientColorKey[] { new GradientColorKey(fillColour, 0.0f), new GradientColorKey(fillColour, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(fillColour.a, 0.0f), new GradientAlphaKey(fillColour.a, 1.0f) }
            );
        lineRenderer.colorGradient = gradient;

        gradient.SetKeys(
            new GradientColorKey[] { new GradientColorKey(borderColour, 0.0f), new GradientColorKey(borderColour, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(borderColour.a, 0.0f), new GradientAlphaKey(borderColour.a, 1.0f) }
            );

        lineRendererOutline.colorGradient = gradient;
    }
Esempio n. 2
0
    protected override void OnConfigUpdated()
    {
        dotFillColor   = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotFillColor, SettingsConfig.Config.CursorDotFillOpacity);
        dotBorderColor = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotBorderColor, SettingsConfig.Config.CursorDotBorderOpacity);
        ringColor      = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorRingColor, SettingsConfig.Config.CursorRingOpacity);

        cursorDot.color            = dotBorderColor;
        cursorDotFill.color        = dotFillColor;
        cursorProgressBorder.color = dotBorderColor;
        cursorProgressFill.color   = ringColor;

        if (ringEnabled)
        {
            cursorRing.color = ringColor;
        }

        screenDistanceAtMaxScaleMeters = SettingsConfig.Config.CursorMaxRingScaleAtDistanceM;

        cursorDotSize = (GlobalSettings.ScreenHeight / PhysicalConfigurable.Config.ScreenHeightM) * SettingsConfig.Config.CursorDotSizeM / 100f;
        var dotSizeIsZero = Mathf.Approximately(cursorDotSize, 0f);

        cursorDotSize = dotSizeIsZero ? 1f : cursorDotSize;

        // Scale up the dot by a factor of 2 for this interaction due to the smaller dot
        cursorDotSize *= 2f;

        cursorDot.enabled                  = !dotSizeIsZero;
        cursorProgressBorder.enabled       = !dotSizeIsZero;
        cursorProgressFill.enabled         = !dotSizeIsZero;
        cursorDotTransform.localScale      = new Vector3(cursorDotSize, cursorDotSize, cursorDotSize);
        cursorProgressTransform.localScale = new Vector3(cursorDotSize, cursorDotSize, cursorDotSize);

        maxRingScale = (1f / cursorDotSize) * SettingsConfig.Config.CursorRingMaxScale;
    }
Esempio n. 3
0
    protected override void OnConfigUpdated()
    {
        dotFillColor   = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotFillColor, SettingsConfig.Config.CursorDotFillOpacity);
        dotBorderColor = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotBorderColor, SettingsConfig.Config.CursorDotBorderOpacity);
        ringColor      = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorRingColor, SettingsConfig.Config.CursorRingOpacity);

        cursorDot.color     = dotBorderColor;
        cursorDotFill.color = dotFillColor;

        cursorDotSize = (GlobalSettings.ScreenHeight / PhysicalConfigurable.Config.ScreenHeightM) * SettingsConfig.Config.CursorDotSizeM / 100f;
        var dotSizeIsZero = Mathf.Approximately(cursorDotSize, 0f);

        cursorDotSize = dotSizeIsZero ? 1f : cursorDotSize;
        cursorDot.transform.localScale = new Vector3(cursorDotSize, cursorDotSize, cursorDotSize);
        SetCursorLocalScale(cursorDotSize);

        if (ringEnabled)
        {
            maxRingScale = (1f / cursorDotSize) * SettingsConfig.Config.CursorRingMaxScale;

            // This is a crude way of forcing the sprites to draw on top of the UI, without masking it.
            ringOuterSprite.sortingOrder = ringSpriteSortingOrder;
            ringMask.GetComponent <SpriteMask>().isCustomRangeActive = true;
            ringMask.GetComponent <SpriteMask>().frontSortingOrder   = ringSpriteSortingOrder + 1;
            ringMask.GetComponent <SpriteMask>().backSortingOrder    = ringSpriteSortingOrder - 1;
        }
    }
Esempio n. 4
0
    private void ResolveClassicPinchOrGrab()
    {
        float pinchStrength = SingleHandManager.Instance.CurrentHand.PinchStrength;
        float grabStrength  = SingleHandManager.Instance.CurrentHand.GrabStrength;

        if (grabbing)
        {
            bool classicPinching = (pinchStrength >= unpinchThreshold);
            bool classicGrabbing = (grabStrength >= ungrabThreshold);
            grabbing = classicPinching | classicGrabbing;
        }
        else
        {
            bool classicPinching = (pinchStrength >= pinchThreshold);
            bool classicGrabbing = (grabStrength >= grabThreshold);
            grabbing = classicPinching | classicGrabbing;
        }

        if (grabbing)
        {
            GeneralisedGrabStrength = 1;
        }
        else
        {
            float normalisedPinchStrength = ScreenControlUtility.MapRangeToRange(Mathf.Clamp(pinchStrength, 0, pinchThreshold), 0, pinchThreshold, 0, 1);
            float normalisedGrabStrength  = ScreenControlUtility.MapRangeToRange(Mathf.Clamp(grabStrength, 0, grabThreshold), 0, grabThreshold, 0, 1);

            GeneralisedGrabStrength = Mathf.Max(normalisedPinchStrength, normalisedGrabStrength);
        }
    }
Esempio n. 5
0
    private void OnDrawGizmos()
    {
        if (Application.isEditor && Application.isPlaying && DrawDebugGizmos)
        {
            float arcAngle = left ? ArcAngleLeft : ArcAngleRight;
            float circleCentreOffsetBase    = cursorDotSize * CircleCentreOffsetBaseScale * _screenScale;
            float arcMidpointRadius         = cursorDotSize * ArcMidpointOffsetScale * _screenScale;
            float currentCircleOffsetRadius = ScreenControlUtility.MapRangeToRange(radiusScale.Evaluate(generalisedGrabDetector.GeneralisedGrabStrength), 1, 0, arcMidpointRadius / 2, circleCentreOffsetBase);
            float finalOffsetRadius         = arcMidpointRadius / 2;

            Vector2 anchoredPosition = Camera.main.ScreenToWorldPoint(_targetPos);

            Vector2 arcOffset = new Vector2()
            {
                x = arcMidpointRadius * Mathf.Cos(Mathf.Deg2Rad * arcAngle),
                y = arcMidpointRadius * Mathf.Sin(Mathf.Deg2Rad * arcAngle)
            };

            Vector2 currentCircleOffset = new Vector2()
            {
                x = currentCircleOffsetRadius * Mathf.Cos(Mathf.Deg2Rad * (arcAngle + 180)),
                y = currentCircleOffsetRadius * Mathf.Sin(Mathf.Deg2Rad * (arcAngle + 180))
            };

            Vector2 finalOffset = new Vector2()
            {
                x = finalOffsetRadius * Mathf.Cos(Mathf.Deg2Rad * (arcAngle + 180)),
                y = finalOffsetRadius * Mathf.Sin(Mathf.Deg2Rad * (arcAngle + 180))
            };

            Vector3 arcMidpoint = new Vector3()
            {
                x = anchoredPosition.x + arcOffset.x,
                y = anchoredPosition.y + arcOffset.y,
                z = transform.position.z,
            };

            Vector3 circleCentre = new Vector3()
            {
                x = arcMidpoint.x + currentCircleOffset.x,
                y = arcMidpoint.y + currentCircleOffset.y,
                z = arcMidpoint.z,
            };

            Vector3 finalCircleCentre = new Vector3()
            {
                x = arcMidpoint.x + finalOffset.x,
                y = arcMidpoint.y + finalOffset.y,
                z = arcMidpoint.z,
            };

            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(circleCentre, currentCircleOffsetRadius);
            Gizmos.color = Color.blue;
            Gizmos.DrawWireSphere(finalCircleCentre, finalOffsetRadius);
            Gizmos.color = Color.green;
            Gizmos.DrawWireSphere(Camera.main.ScreenToWorldPoint(_targetPos), 0.1f);
        }
    }
    private bool ShouldTriggerGrab(Leap.Hand hand)
    {
        float handAngle        = GetAngle(hand);
        float clampedHandAngle = Mathf.Clamp(handAngle, clickAngle, 180);

        GrabStrength = ScreenControlUtility.MapRangeToRange(clampedHandAngle, clickAngle, 180, 1, 0);

        return(handAngle < clickAngle);
    }
    protected override void ValidateValues()
    {
        var dotSize = Mathf.Clamp(cursorDotSizeSlider.value, ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorDotSize_Min), ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorDotSize_Max));

        cursorDotSizeSlider.SetValueWithoutNotify(dotSize);
        cursorDotSize.SetTextWithoutNotify(dotSize.ToString("#0.00#"));

        var ringScale = Mathf.Clamp(cursorMaxRingScaleSlider.value, SettingsConfig.CursorRingMaxScale_Min, SettingsConfig.CursorRingMaxScale_Max);

        cursorMaxRingScaleSlider.SetValueWithoutNotify(ringScale);
        cursorMaxRingScale.SetTextWithoutNotify(ringScale.ToString("#0.00#"));

        var maxDistance = Mathf.Clamp(cursorMaxRingScaleAtDistanceSlider.value, ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorMaxRingScaleAtDistance_Min), ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorMaxRingScaleAtDistance_Max));

        cursorMaxRingScaleAtDistanceSlider.SetValueWithoutNotify(maxDistance);
        cursorMaxRingScaleAtDistance.SetTextWithoutNotify(maxDistance.ToString("#0.00#"));

        var deadzoneRadius = Mathf.Clamp(cursorDeadzoneSlider.value, SettingsConfig.CursorDeadzone_Min, SettingsConfig.CursorDeadzone_Max);

        cursorDeadzoneSlider.SetValueWithoutNotify(deadzoneRadius);

        var verticalOffset = Mathf.Clamp(cursorVerticalOffsetSlider.value, ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorVerticalOffset_Min), ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorVerticalOffset_Max));

        cursorVerticalOffsetSlider.SetValueWithoutNotify(verticalOffset);
        cursorVerticalOffset.SetTextWithoutNotify(verticalOffset.ToString("#0.00#"));

        var hoverStartTime = Mathf.Clamp(HoverCursorStartTimeSlider.value, SettingsConfig.HoverCursorStartTime_Min, SettingsConfig.HoverCursorStartTime_Max);

        HoverCursorStartTime.SetTextWithoutNotify(hoverStartTime.ToString("#0.00#"));
        HoverCursorStartTimeSlider.SetValueWithoutNotify(hoverStartTime);

        var hoverCompleteTime = Mathf.Clamp(HoverCursorCompleteTimeSlider.value, SettingsConfig.HoverCursorCompleteTime_Min, SettingsConfig.HoverCursorCompleteTime_Max);

        HoverCursorCompleteTime.SetTextWithoutNotify(hoverCompleteTime.ToString("#0.00#"));
        HoverCursorCompleteTimeSlider.SetValueWithoutNotify(hoverCompleteTime);

        CTIShowTimer.SetTextWithoutNotify(TryParseNewStringToFloat(ref CallToInteractConfig.Config.ShowTimeAfterNoHandPresent, CTIShowTimer.text).ToString("#0.00#"));
        CTIHideTimer.SetTextWithoutNotify(TryParseNewStringToFloat(ref CallToInteractConfig.Config.HideTimeAfterHandPresent, CTIHideTimer.text).ToString("#0.00#"));

        switch (CallToInteractConfig.Config.hideType)
        {
        case HideRequirement.PRESENT:
            activityHideOption.SetActive(true);
            break;

        case HideRequirement.INTERACTION:
            activityHideOption.SetActive(false);
            break;
        }

        ValidateInteractionTypeElements();
        hoverEventsWarning.SetActive(sendHoverEventsTog.isOn);
    }
Esempio n. 8
0
    private void ResolveClassicGrab()
    {
        float grabStrength = SingleHandManager.Instance.CurrentHand.GrabStrength;

        if (grabbing)
        {
            grabbing = (grabStrength >= ungrabThreshold);
            GeneralisedGrabStrength = ScreenControlUtility.MapRangeToRange(Mathf.Clamp(grabStrength, 0, ungrabThreshold), 0, ungrabThreshold, 0, 1);
        }
        else
        {
            grabbing = (grabStrength >= grabThreshold);
            GeneralisedGrabStrength = ScreenControlUtility.MapRangeToRange(Mathf.Clamp(grabStrength, 0, grabThreshold), 0, grabThreshold, 0, 1);
        }
    }
    void InitialiseUI()
    {
        PhysicalScreenTiltAngleSlider.minValue = PhysicalConfigurable.ScreenTilt_Min;
        ScreenHeightSlider.minValue            = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.ScreenHeight_Min);
        TrackingOriginXSlider.minValue         = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.TrackingOriginX_Min);
        TrackingOriginYSlider.minValue         = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.TrackingOriginY_Min);
        TrackingOriginZSlider.minValue         = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.TrackingOriginZ_Min);
        TrackingRotationXSlider.minValue       = PhysicalConfigurable.TrackingRoation_Min;

        PhysicalScreenTiltAngleSlider.maxValue = PhysicalConfigurable.ScreenTilt_Max;
        ScreenHeightSlider.maxValue            = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.ScreenHeight_Max);
        TrackingOriginXSlider.maxValue         = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.TrackingOriginX_Max);
        TrackingOriginYSlider.maxValue         = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.TrackingOriginY_Max);
        TrackingOriginZSlider.maxValue         = ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.TrackingOriginZ_Max);
        TrackingRotationXSlider.maxValue       = PhysicalConfigurable.TrackingRoation_Max;
    }
Esempio n. 10
0
    public IEnumerator ShrinkCursorDot()
    {
        YieldInstruction yieldInstruction = new YieldInstruction();
        float            elapsedTime      = 0.0f;

        while (elapsedTime < pulseSeconds)
        {
            yield return(yieldInstruction);

            elapsedTime += Time.deltaTime;
            float scale = ScreenControlUtility.MapRangeToRange(pulseShrinkCurve.Evaluate(elapsedTime / pulseSeconds), 0, 1, cursorDownScale * cursorDotSize, cursorDotSize);
            SetCursorLocalScale(scale);
        }

        SetCursorLocalScale(cursorDownScale * cursorDotSize);
        cursorScalingRoutine = null;
    }
    protected override void LoadConfigValuesIntoFields()
    {
        PhysicalScreenTiltAngle.SetTextWithoutNotify(PhysicalConfigurable.Config.ScreenRotationD.ToString("##0.0"));
        ScreenHeight.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.Config.ScreenHeightM).ToString("#0.00#"));
        TrackingOriginX.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.x).ToString("#0.00#"));
        TrackingOriginY.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.y).ToString("#0.00#"));
        TrackingOriginZ.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(-PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.z).ToString("#0.00#"));
        TrackingRotationX.SetTextWithoutNotify(PhysicalConfigurable.Config.LeapRotationD.x.ToString("##0.0"));

        var bottomMount = Mathf.Approximately(PhysicalConfigurable.Config.LeapRotationD.z, 0f);

        PhysicalScreenTiltAngleSlider.SetValueWithoutNotify(PhysicalConfigurable.Config.ScreenRotationD);
        ScreenHeightSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.Config.ScreenHeightM));
        TrackingOriginXSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.x));
        TrackingOriginYSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.y));
        TrackingOriginZSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(-PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.z));
        TrackingRotationXSlider.SetValueWithoutNotify(PhysicalConfigurable.Config.LeapRotationD.x);
    }
Esempio n. 12
0
    private IEnumerator ShrinkLine()
    {
        lineShrunk = true;
        YieldInstruction yieldInstruction = new YieldInstruction();
        float            elapsedTime      = 0.0f;

        while (elapsedTime < LineGrowthSeconds)
        {
            yield return(yieldInstruction);

            elapsedTime += Time.deltaTime;
            float scale = ScreenControlUtility.MapRangeToRange(lineShrinkCurve.Evaluate(elapsedTime / LineGrowthSeconds), 0, 1, 1, LineGrowthMultiplier);
            SetLineRendererWidthScale(scale);
        }

        SetLineRendererWidthScale(1);
        lineScalingRoutine = null;
    }
    void InitialiseUI()
    {
        cursorDotSizeSlider.minValue                = ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorDotSize_Min);
        cursorDotSizeSlider.maxValue                = ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorDotSize_Max);
        cursorMaxRingScaleSlider.minValue           = SettingsConfig.CursorRingMaxScale_Min;
        cursorMaxRingScaleSlider.maxValue           = SettingsConfig.CursorRingMaxScale_Max;
        cursorMaxRingScaleAtDistanceSlider.minValue = ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorMaxRingScaleAtDistance_Min);
        cursorMaxRingScaleAtDistanceSlider.maxValue = ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorMaxRingScaleAtDistance_Max);

        cursorDeadzoneSlider.minValue = SettingsConfig.CursorDeadzone_Min;
        cursorDeadzoneSlider.maxValue = SettingsConfig.CursorDeadzone_Max;

        cursorVerticalOffsetSlider.minValue = ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorVerticalOffset_Min);
        cursorVerticalOffsetSlider.maxValue = ScreenControlUtility.ToDisplayUnits(SettingsConfig.CursorVerticalOffset_Max);

        HoverCursorStartTimeSlider.minValue    = SettingsConfig.HoverCursorStartTime_Min;
        HoverCursorStartTimeSlider.maxValue    = SettingsConfig.HoverCursorStartTime_Max;
        HoverCursorCompleteTimeSlider.minValue = SettingsConfig.HoverCursorCompleteTime_Min;
        HoverCursorCompleteTimeSlider.maxValue = SettingsConfig.HoverCursorCompleteTime_Max;

        customCursorDotFillColour    = SettingsConfig.Config.CursorDotFillColor;
        customCursorDotBorderColour  = SettingsConfig.Config.CursorDotBorderColor;
        customCursorRingColour       = SettingsConfig.Config.CursorRingColor;
        customCursorDotFillOpacity   = SettingsConfig.Config.CursorDotFillOpacity;
        customCursorDotBorderOpacity = SettingsConfig.Config.CursorDotBorderOpacity;
        customCursorRingOpacity      = SettingsConfig.Config.CursorRingOpacity;

        if (SettingsConfig.Config.CursorColorPreset == CursorColourPreset.custom)
        {
            // we are in custom, so only worry about custom colours
            foreach (var label in customCursorColourLabels)
            {
                label.SetActive(true);
            }
        }
        else
        {
            foreach (var label in customCursorColourLabels)
            {
                label.SetActive(false);
            }
        }
    }
Esempio n. 14
0
    private void ResolveCombinedPinchAndGrab()
    {
        float pinchStrength    = SingleHandManager.Instance.CurrentHand.PinchStrength;
        float fistStrength     = SingleHandManager.Instance.CurrentHand.GetFistStrength();
        float combinedStrength = pinchStrength + fistStrength;

        if (grabbing)
        {
            grabbing = combinedStrength >= combinedUngrabThreshold;
            GeneralisedGrabStrength = ScreenControlUtility.MapRangeToRange(Mathf.Clamp(combinedStrength, 0, combinedUngrabThreshold), 0, combinedUngrabThreshold, 0, 1);
        }
        else
        {
            grabbing = (pinchStrength == pinchThreshold) && (combinedStrength >= combinedGrabThreshold);
            float clampedCombinedStrength = Mathf.Clamp(combinedStrength, 0, combinedGrabThreshold);

            GeneralisedGrabStrength = ScreenControlUtility.MapRangeToRange(Mathf.Clamp(clampedCombinedStrength + pinchStrength, 0, combinedGrabThreshold + pinchThreshold), 0, clampedCombinedStrength + pinchThreshold, 0, 1);
        }
    }
    protected override void OnConfigUpdated()
    {
        dotFillColor   = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotFillColor, SettingsConfig.Config.CursorDotFillOpacity);
        dotBorderColor = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotBorderColor, SettingsConfig.Config.CursorDotBorderOpacity);

        openHandImage.color   = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorRingColor, SettingsConfig.Config.CursorRingOpacity);
        closedHandImage.color = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorRingColor, SettingsConfig.Config.CursorRingOpacity);

        cursorDot.color     = dotBorderColor;
        cursorDotFill.color = dotFillColor;

        cursorDotSize = (GlobalSettings.ScreenHeight / PhysicalConfigurable.Config.ScreenHeightM) * SettingsConfig.Config.CursorDotSizeM / 100f;
        var dotSizeIsZero = Mathf.Approximately(cursorDotSize, 0f);

        cursorDotSize     = dotSizeIsZero ? 1f : cursorDotSize;
        cursorDot.enabled = !dotSizeIsZero;

        if (!hidingCursor)
        {
            cursorDot.transform.localScale = new Vector3(cursorDotSize, cursorDotSize, cursorDotSize);
        }
    }
Esempio n. 16
0
    protected float TryParseNewStringToFloat(ref float _original, string _newText, bool _convertToStorageUnits = false, bool _convertToDisplayUnits = false)
    {
        // Match any character that is not period (.), hypen (-), or numbers 0 to 9, and strip them out.
        _newText = Regex.Replace(_newText, "[^.0-9-]", "");

        float val;

        if (!float.TryParse(_newText, NumberStyles.Number, CultureInfo.CurrentCulture, out val))
        {
            val = _original; // string was not compatible!
        }
        if (_convertToDisplayUnits)
        {
            val = ScreenControlUtility.ToDisplayUnits(val);
        }
        else if (_convertToStorageUnits)
        {
            val = ScreenControlUtility.FromDisplayUnits(val);
        }

        return(val);
    }
Esempio n. 17
0
    private void Update()
    {
        // side-on view
        float sideLeapPosX = ScreenControlUtility.MapRangeToRange(-PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.z, 0, PhysicalConfigurable.Config.ScreenHeightM, 0, sideonScreen.sizeDelta.y);
        float sideLeapPosY = ScreenControlUtility.MapRangeToRange(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.y, 0, PhysicalConfigurable.Config.ScreenHeightM, 0, sideonScreen.sizeDelta.y);

        sideonScreen.localRotation = Quaternion.Euler(0, 0, PhysicalConfigurable.Config.ScreenRotationD);

        sideonLeap.localPosition = sideonScreen.localPosition + new Vector3(sideLeapPosX, sideLeapPosY, 0);
        sideonLeap.localRotation = Quaternion.Euler(PhysicalConfigurable.Config.LeapRotationD.z, 0, PhysicalConfigurable.Config.LeapRotationD.x);

        sideonLeap.localPosition = new Vector3(Mathf.Clamp(sideonLeap.localPosition.x, sideonLocalClampMin.x, sideonLocalClampMax.x),
                                               Mathf.Clamp(sideonLeap.localPosition.y, sideonLocalClampMin.y, sideonLocalClampMax.y), 0);

        // front-on view
        var aspectRatio = (float)GlobalSettings.ScreenWidth / (float)GlobalSettings.ScreenHeight;

        if (aspectRatio > 1)
        {
            // landscape
            frontonScreen.sizeDelta = new Vector2(dynamicScreenSizePX, dynamicScreenSizePX * ((float)GlobalSettings.ScreenHeight / (float)GlobalSettings.ScreenWidth));
        }
        else
        {
            //portrait
            frontonScreen.sizeDelta = new Vector2(dynamicScreenSizePX * aspectRatio, dynamicScreenSizePX);
        }

        float frontLeapPosX = ScreenControlUtility.MapRangeToRange(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.x, 0, PhysicalConfigurable.Config.ScreenHeightM, 0, frontonScreen.sizeDelta.y);
        float frontLeapPosY = ScreenControlUtility.MapRangeToRange(PhysicalConfigurable.Config.LeapPositionRelativeToScreenBottomM.y, 0, PhysicalConfigurable.Config.ScreenHeightM, 0, frontonScreen.sizeDelta.y);

        frontonLeap.localPosition = frontonScreen.localPosition + new Vector3(frontLeapPosX, (-frontonScreen.sizeDelta.y / 2) + frontLeapPosY, 0);
        frontonLeap.localRotation = Quaternion.Euler(0, 0, PhysicalConfigurable.Config.LeapRotationD.z);

        frontonLeap.localPosition = new Vector3(Mathf.Clamp(frontonLeap.localPosition.x, frontonLocalClampMin.x, frontonLocalClampMax.x),
                                                Mathf.Clamp(frontonLeap.localPosition.y, frontonLocalClampMin.y, frontonLocalClampMax.y), 0);
    }
    void DisplayCursorPreview()
    {
        var dotFillColor   = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotFillColor, SettingsConfig.Config.CursorDotFillOpacity);
        var dotBorderColor = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorDotBorderColor, SettingsConfig.Config.CursorDotBorderOpacity);
        var ringColor      = ScreenControlUtility.ParseColor(SettingsConfig.Config.CursorRingColor, SettingsConfig.Config.CursorRingOpacity);

        pushCursorPreview.SetActive(false);
        grabCursorPreview.SetActive(false);
        hoverCursorPreview.SetActive(false);

        switch (SettingsConfig.Config.InteractionSelection)
        {
        case InteractionSelection.Push:
        case InteractionSelection.Poke:
            pushCursorPreview.SetActive(true);
            pushCursorPreviewBorder.color = dotBorderColor;
            pushCursorPreviewDot.color    = dotFillColor;
            pushCursorPreviewRing.color   = ringColor;
            break;

        case InteractionSelection.Grab:
            grabCursorPreview.SetActive(true);
            grabCursorPreviewBorder.color = dotBorderColor;
            grabCursorPreviewDot.color    = dotFillColor;
            grabCursorPreviewLine.color   = ringColor;
            break;

        case InteractionSelection.Hover:
            hoverCursorPreview.SetActive(true);
            hoverCursorPreviewBorder.color     = dotBorderColor;
            hoverCursorPreviewDot.color        = dotFillColor;
            hoverCursorPreviewRingBorder.color = dotBorderColor;
            hoverCursorPreviewRing.color       = ringColor;
            break;
        }
    }
Esempio n. 19
0
    List <Vector3> GenerateArcPositions(float _arcLengthPercentage, float _arcAngle)
    {
        if (generalisedGrabDetector == null)
        {
            // try to re-find it!
            generalisedGrabDetector = FindObjectOfType <GeneralisedGrabDetector>();

            if (generalisedGrabDetector == null)
            {
                return(new List <Vector3>());
            }
        }

        float circleCentreOffsetBase    = cursorDotSize * CircleCentreOffsetBaseScale * _screenScale;
        float arcMidpointRadius         = cursorDotSize * ArcMidpointOffsetScale * _screenScale;
        float currentCircleOffsetRadius = ScreenControlUtility.MapRangeToRange(radiusScale.Evaluate(generalisedGrabDetector.GeneralisedGrabStrength), 1, 0, arcMidpointRadius / 2, circleCentreOffsetBase);

        Vector2 anchoredPosition = Camera.main.ScreenToWorldPoint(cursorTransform.anchoredPosition);

        Vector2 arcOffset = new Vector2()
        {
            x = arcMidpointRadius * Mathf.Cos(Mathf.Deg2Rad * _arcAngle),
            y = arcMidpointRadius * Mathf.Sin(Mathf.Deg2Rad * _arcAngle)
        };

        Vector2 currentCircleOffset = new Vector2()
        {
            x = currentCircleOffsetRadius * Mathf.Cos(Mathf.Deg2Rad * (_arcAngle + 180)),
            y = currentCircleOffsetRadius * Mathf.Sin(Mathf.Deg2Rad * (_arcAngle + 180))
        };

        Vector3 arcMidpoint = new Vector3()
        {
            x = anchoredPosition.x + arcOffset.x,
            y = anchoredPosition.y + arcOffset.y,
            z = transform.position.z,
        };

        Vector3 circleCentre = new Vector3()
        {
            x = arcMidpoint.x + currentCircleOffset.x,
            y = arcMidpoint.y + currentCircleOffset.y,
            z = arcMidpoint.z,
        };

        float finalOffsetRadius = arcMidpointRadius / 2;
        float arcLength         = (float)(2 * Math.PI * finalOffsetRadius) * _arcLengthPercentage;

        Vector2 delta         = (circleCentre - arcMidpoint);
        float   thetaMidpoint = (Mathf.Deg2Rad * 180) + Mathf.Atan2(delta.y, delta.x);

        float thetaMin = thetaMidpoint - ((arcLength / 2) / currentCircleOffsetRadius);
        float thetaMax = thetaMidpoint + ((arcLength / 2) / currentCircleOffsetRadius);

        List <Vector3> positions = new List <Vector3>();

        for (int i = 0; i < LineRendererPositions; i++)
        {
            float currentTheta = thetaMin + (i * (thetaMax - thetaMin) / LineRendererPositions);
            positions.Add(new Vector3()
            {
                x = circleCentre.x + Mathf.Cos(currentTheta) * currentCircleOffsetRadius,
                y = circleCentre.y + Mathf.Sin(currentTheta) * currentCircleOffsetRadius,
                z = circleCentre.z
            });
        }
        return(positions);
    }
    protected override void LoadConfigValuesIntoFields()
    {
        resolutionWidth.text  = Screen.currentResolution.width.ToString();
        resolutionHeight.text = Screen.currentResolution.height.ToString();

        cursorDotSize.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(SettingsConfig.Config.CursorDotSizeM).ToString("#0.00#"));
        cursorDotSizeSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(SettingsConfig.Config.CursorDotSizeM));
        cursorMaxRingScale.SetTextWithoutNotify(SettingsConfig.Config.CursorRingMaxScale.ToString("#0.00#"));
        cursorMaxRingScaleSlider.SetValueWithoutNotify(SettingsConfig.Config.CursorRingMaxScale);
        cursorMaxRingScaleAtDistance.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(SettingsConfig.Config.CursorMaxRingScaleAtDistanceM).ToString("#0.00#"));
        cursorMaxRingScaleAtDistanceSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(SettingsConfig.Config.CursorMaxRingScaleAtDistanceM));
        scrollingOrDraggingTog.SetIsOnWithoutNotify(SettingsConfig.Config.UseScrollingOrDragging);
        setupOnStartup.SetIsOnWithoutNotify(SettingsConfig.Config.ShowSetupScreenOnStartup);
        sendHoverEventsTog.SetIsOnWithoutNotify(SettingsConfig.Config.SendHoverEvents);

        cursorRingColor.SetTextWithoutNotify(SettingsConfig.Config.CursorRingColor);
        cursorRingOpacity.SetValueWithoutNotify(SettingsConfig.Config.CursorRingOpacity);
        cursorDotFillColor.SetTextWithoutNotify(SettingsConfig.Config.CursorDotFillColor);
        cursorDotFillOpacity.SetValueWithoutNotify(SettingsConfig.Config.CursorDotFillOpacity);
        cursorDotBorderColor.SetTextWithoutNotify(SettingsConfig.Config.CursorDotBorderColor);
        cursorDotBorderOpacity.SetValueWithoutNotify(SettingsConfig.Config.CursorDotBorderOpacity);

        cursorDeadzoneSlider.SetValueWithoutNotify(SettingsConfig.Config.DeadzoneRadius);
        cursorVerticalOffset.SetTextWithoutNotify(ScreenControlUtility.ToDisplayUnits(SettingsConfig.Config.CursorVerticalOffset).ToString("#0.00#"));
        cursorVerticalOffsetSlider.SetValueWithoutNotify(ScreenControlUtility.ToDisplayUnits(SettingsConfig.Config.CursorVerticalOffset));

        HoverCursorStartTime.SetTextWithoutNotify(SettingsConfig.Config.HoverCursorStartTimeS.ToString("#0.00#"));
        HoverCursorStartTimeSlider.SetValueWithoutNotify(SettingsConfig.Config.HoverCursorStartTimeS);
        HoverCursorCompleteTime.SetTextWithoutNotify(SettingsConfig.Config.HoverCursorCompleteTimeS.ToString("#0.00#"));
        HoverCursorCompleteTimeSlider.SetValueWithoutNotify(SettingsConfig.Config.HoverCursorCompleteTimeS);

        interactionTypeTogglePush.SetIsOnWithoutNotify(false);
        interactionTypeTogglePoke.SetIsOnWithoutNotify(false);
        interactionTypeTogglePinch.SetIsOnWithoutNotify(false);
        interactionTypeToggleHover.SetIsOnWithoutNotify(false);
        switch (SettingsConfig.Config.InteractionSelection)
        {
        case InteractionSelection.Push:
            interactionTypeTogglePush.SetIsOnWithoutNotify(true);
            break;

        case InteractionSelection.Poke:
            interactionTypeTogglePoke.SetIsOnWithoutNotify(true);
            break;

        case InteractionSelection.Grab:
            interactionTypeTogglePinch.SetIsOnWithoutNotify(true);
            break;

        case InteractionSelection.Hover:
            interactionTypeToggleHover.SetIsOnWithoutNotify(true);
            break;
        }

        cursorColorPresetToggleLight.SetIsOnWithoutNotify(false);
        cursorColorPresetToggleDark.SetIsOnWithoutNotify(false);
        cursorColorPresetToggleLightContrast.SetIsOnWithoutNotify(false);
        cursorColorPresetToggleDarkContrast.SetIsOnWithoutNotify(false);
        cursorColorPresetToggleCustom.SetIsOnWithoutNotify(false);
        switch (SettingsConfig.Config.CursorColorPreset)
        {
        case CursorColourPreset.light:
            cursorColorPresetToggleLight.SetIsOnWithoutNotify(true);
            break;

        case CursorColourPreset.dark:
            cursorColorPresetToggleDark.SetIsOnWithoutNotify(true);
            break;

        case CursorColourPreset.white_Contrast:
            cursorColorPresetToggleLightContrast.SetIsOnWithoutNotify(true);
            break;

        case CursorColourPreset.black_Contrast:
            cursorColorPresetToggleDarkContrast.SetIsOnWithoutNotify(true);
            break;

        case CursorColourPreset.custom:
            cursorColorPresetToggleCustom.SetIsOnWithoutNotify(true);
            break;
        }

        if (SettingsConfig.Config.CursorColorPreset == CursorColourPreset.custom)
        {
            foreach (var label in customCursorColourLabels)
            {
                label.SetActive(true);
            }
        }
        else
        {
            foreach (var label in customCursorColourLabels)
            {
                label.SetActive(false);
            }
        }

        ValidateInteractionTypeElements();

        CTIEnableTog.SetIsOnWithoutNotify(CallToInteractConfig.Config.Enabled);
        CTIShowTimer.SetTextWithoutNotify(CallToInteractConfig.Config.ShowTimeAfterNoHandPresent.ToString("#0.00#"));
        CTIHideTimer.SetTextWithoutNotify(CallToInteractConfig.Config.HideTimeAfterHandPresent.ToString("#0.00#"));

        switch (CallToInteractConfig.Config.hideType)
        {
        case HideRequirement.PRESENT:
            CTIEndOnPresentTog.SetIsOnWithoutNotify(true);
            CTIEndOnInteractionTog.SetIsOnWithoutNotify(false);
            activityHideOption.SetActive(true);
            break;

        case HideRequirement.INTERACTION:
            CTIEndOnPresentTog.SetIsOnWithoutNotify(false);
            CTIEndOnInteractionTog.SetIsOnWithoutNotify(true);
            activityHideOption.SetActive(false);
            break;
        }

        hoverEventsWarning.SetActive(sendHoverEventsTog.isOn);

        LoadCTIFilesIntoDropdown();
        DisplayCursorPreview();
        DisplayIntractionPreview();
    }