コード例 #1
0
    public void HandleScroll(GameObject currentGameObject, PointerEventData pointerData,
                             GvrBasePointer pointer, IGvrEventExecutor eventExecutor)
    {
        bool    touchDown     = false;
        bool    touching      = false;
        bool    touchUp       = false;
        Vector2 currentScroll = Vector2.zero;

        if (pointer != null && pointer.IsAvailable)
        {
            touchDown     = pointer.TouchDown;
            touching      = pointer.IsTouching;
            touchUp       = pointer.TouchUp;
            currentScroll = pointer.TouchPos;
        }

        GameObject currentScrollHandler = eventExecutor.GetEventHandler <IScrollHandler>(currentGameObject);

        if (touchDown)
        {
            RemoveScrollHandler(currentScrollHandler);
        }

        if (currentScrollHandler != null && (touchDown || touching))
        {
            OnTouchingScrollHandler(currentScrollHandler, pointerData, currentScroll, eventExecutor);
        }
        else if (touchUp && currentScrollHandler != null)
        {
            OnReleaseScrollHandler(currentScrollHandler);
        }

        StopScrollingIfNecessary(touching, currentScrollHandler);
        UpdateInertiaScrollHandlers(touching, currentScrollHandler, pointerData, eventExecutor);
    }
コード例 #2
0
    private void OnTouchingScrollHandler(GameObject currentScrollHandler, PointerEventData pointerData,
                                         Vector2 currentScroll, IGvrEventExecutor eventExecutor)
    {
        ScrollInfo scrollInfo = null;

        if (!scrollHandlers.ContainsKey(currentScrollHandler))
        {
            scrollInfo = AddScrollHandler(currentScrollHandler, currentScroll);
        }
        else
        {
            scrollInfo = scrollHandlers[currentScrollHandler];
        }
        currentScroll *= GetScrollDeltaMultiplier(scrollInfo);
        CalculationValue(GetScrollDeltaMultiplier(scrollInfo));
        // Detect if we should start scrolling along the x-axis based on the horizontal slop threshold.
        if (CanScrollStartX(scrollInfo, currentScroll))
        {
            scrollInfo.isScrollingX = true;
        }

        // Detect if we should start scrolling along the y-axis based on the vertical slop threshold.
        if (CanScrollStartY(scrollInfo, currentScroll))
        {
            scrollInfo.isScrollingY = true;
        }

        if (scrollInfo.IsScrolling)
        {
            Vector2 clampedScroll     = currentScroll;
            Vector2 clampedLastScroll = scrollInfo.lastScroll;
            if (!scrollInfo.isScrollingX)
            {
                clampedScroll.x     = 0.0f;
                clampedLastScroll.x = 0.0f;
            }

            if (!scrollInfo.isScrollingY)
            {
                clampedScroll.y     = 0.0f;
                clampedLastScroll.y = 0.0f;
            }

            Vector2 scrollDisplacement = clampedScroll - clampedLastScroll;
            UpdateVelocity(scrollInfo, scrollDisplacement);

            if (!ShouldUseInertia(scrollInfo))
            {
                // If inertia is disabled, then we send scroll events immediately.
                pointerData.scrollDelta = scrollDisplacement;
                eventExecutor.ExecuteHierarchy(currentScrollHandler, pointerData, ExecuteEvents.scrollHandler);
                pointerData.scrollDelta = Vector2.zero;
            }
        }

        scrollInfo.lastScroll = currentScroll;
    }
コード例 #3
0
        public void Setup()
        {
            SubstituteComponent.BeginComponentContext();

            // Create input module implementation.
            module = new GvrPointerInputModuleImpl();

            // Create Event System.
            GameObject eventSystemObj = new GameObject("EventSystem");

            eventSytem = eventSystemObj.AddComponent <EventSystem>();

            // Create mock pointer.
            pointer = SubstituteComponent.For <GvrBasePointer>(eventSystemObj);
            pointer.PointerTransform.Returns(eventSytem.transform);
            pointer.IsAvailable.Returns(true);
            module.Pointer = pointer;

            // Create mock scroll input.
            scrollInput        = new GvrPointerScrollInput();
            module.ScrollInput = scrollInput;

            // Create mock module controller.
            moduleController = Substitute.For <IGvrInputModuleController>();
            moduleController.eventSystem.Returns(eventSytem);
            resultCache = new List <RaycastResult>();
            moduleController.RaycastResultCache.Returns(resultCache);
            module.ModuleController = moduleController;

            // Create mock event executor.
            eventExecutor        = Substitute.For <IGvrEventExecutor>();
            module.EventExecutor = eventExecutor;

            // Create dummy objects to use for hit detection.
            raycastResult = new RaycastResult();
            hitObject     = new GameObject("HitObject");
            hitPos        = new Vector3(1.0f, 2.0f, 3.0f);

            dummyRaycastResult = new RaycastResult();
        }
コード例 #4
0
    private void UpdateInertiaScrollHandlers(bool touching,
                                             GameObject currentScrollHandler,
                                             PointerEventData pointerData,
                                             IGvrEventExecutor eventExecutor)
    {
        if (pointerData == null)
        {
            return;
        }

        // If the currentScrollHandler is null, then the currently scrolling scrollHandlers
        // must still be decelerated so the function does not return early.
        for (int i = 0; i < scrollingObjects.Count; i++)
        {
            GameObject scrollHandler = scrollingObjects[i];
            ScrollInfo scrollInfo    = scrollHandlers[scrollHandler];

            if (!ShouldUseInertia(scrollInfo))
            {
                continue;
            }

            if (scrollInfo.IsScrolling)
            {
                // Decelerate the scrollHandler if necessary.
                if (!touching || scrollHandler != currentScrollHandler)
                {
                    float finalDecelerationRate = GetDecelerationRate(scrollInfo);
                    scrollInfo.scrollVelocity *= Mathf.Pow(finalDecelerationRate, Time.deltaTime);
                }

                // Send the scroll events.
                pointerData.scrollDelta = scrollInfo.scrollVelocity * Time.deltaTime;
                eventExecutor.ExecuteHierarchy(
                    scrollHandler, pointerData, ExecuteEvents.scrollHandler);
            }
        }

        pointerData.scrollDelta = Vector2.zero;
    }
コード例 #5
0
    private void OnTouchingScrollHandler(GameObject currentScrollHandler, PointerEventData pointerData,
                                         Vector2 currentScroll, IGvrEventExecutor eventExecutor)
    {
        ScrollInfo scrollInfo = null;

        if (!scrollHandlers.ContainsKey(currentScrollHandler))
        {
            scrollInfo = AddScrollHandler(currentScrollHandler, currentScroll);
        }
        else
        {
            scrollInfo = scrollHandlers[currentScrollHandler];
        }

        // Determine if we should start scrolling this scrollHandler.
        // This is true if the current scroll is outside of the slop threshold.
        if (CanScrollStart(scrollInfo, currentScroll))
        {
            scrollInfo.isScrolling = true;
        }

        if (scrollInfo.isScrolling)
        {
            if (ShouldUseInertia(scrollInfo))
            {
                UpdateVelocity(scrollInfo, currentScroll);
            }
            else
            {
                // If inertia is disabled, then we send scroll events immediately.
                pointerData.scrollDelta = currentScroll - scrollInfo.lastScroll;
                eventExecutor.ExecuteHierarchy(currentScrollHandler, pointerData, ExecuteEvents.scrollHandler);
                pointerData.scrollDelta = Vector2.zero;
            }
        }

        scrollInfo.lastScroll = currentScroll;
    }