Exemple #1
0
        public void EndCurrentDrag()
        {
            if (!isDragging)
            {
                return;
            }

            //Debug.Log("ending drag");


            if (draggingDP == null)
            {
                Debug.LogError("Dragging DP null");
                return;
            }

            draggingDP.onOverlayDragged?.Invoke(false);

            //If it was using a snap point in the past, clear it:
            draggingDP.ClearAllSnapData();

            //If we ended the drag on a new snap point
            if (isUsingSnapPoint)
            {
                draggingDP.TransitionOverlayPosition(activeSnapPoint.transform.localPosition, activeSnapPoint.transform.localEulerAngles, transitionSnapPointSpeed,
                                                     Ease.InOutCubic, false);

                //Remove any previous thing
                if (activeSnapPoint.dpApp != null)
                {
                    TheBarManager.I.MinimizeApp(activeSnapPoint.dpApp.appKey);
                }
                else if (activeSnapPoint.dpBase != null)
                {
                    DPUIManager.Animate(activeSnapPoint.dpBase, DPAnimation.FadeOut);
                    activeSnapPoint.ClearAllSnapData();
                }

                if (draggingDP.hasDPAppParent && draggingDP.dpAppParent.dpMain == draggingDP)
                {
                    activeSnapPoint.SetSnappedApp(draggingDP.dpAppParent);
                }
                else
                {
                    activeSnapPoint.SetSnappedDP(draggingDP);
                }
            }


            TheBarManager.I.ToggleSnapPointsVisible(false);

            isDragging = false;

            dummyDragChild.parent = null;

            draggingDP      = null;
            activeSnapPoint = null;

            draggingDPIsAutoCurving = false;
        }
Exemple #2
0
        private void ClearActiveSnapPoint(DPOverlayBase dpBase)
        {
            if (!isUsingSnapPoint)
            {
                return;
            }

            activeSnapPoint.CancelPreviewAndRestore();

            dpBase.KillTransitions();

            dpBase.TransitionOverlayWidth(dpBase.overlay.targetWidth, transitionSnapPointSpeed, false);
            dpBase.TransitionOverlayOpacity(dpBase.overlay.targetOpacity, transitionSnapPointSpeed, Ease.InOutCubic, false);
            //dpBase.TransitionOverlayCurvature(dpBase.overlay.targetCurvature, transitionSnapPointSpeed, false);

            activeSnapPoint.iconDP.TransitionOverlayWidth(activeSnapPoint.iconDP.overlay.targetWidth, transitionSnapPointSpeed, false);
            activeSnapPoint = null;
        }
        public override bool DetectSnapPoints(out DPSnapPoint activePoint)
        {
            Ray ray = new Ray {
                origin = pointer.position, direction = pointer.forward
            };
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, snapPointRaycastDistance, layerMask))
            {
                activePoint = hit.transform.GetComponent <DPSnapPoint>();

                if (activePoint != null)
                {
                    return(true);
                }
            }

            activePoint = null;
            return(false);
        }
Exemple #4
0
 /// <summary>
 /// Called when the interactor should test to see if it's pointing at/on a snap point
 /// </summary>
 /// <returns>If it hit a snap point</returns>
 public abstract bool DetectSnapPoints(out DPSnapPoint activePoint);
Exemple #5
0
        /// <summary>
        /// Handles checking and animating the currently dragged overlay to the snap points
        /// </summary>
        private void HandleSnapPoints()
        {
            //If the overlay we're dragging is anchored, ignore snap points:
            if (isDraggingAnchored)
            {
                return;
            }

            if (!draggingDP.canUseSnapPoints)
            {
                return;
            }

            if (!DPSettings.config.snapPointsEnabled)
            {
                return;
            }

            //Disable snapping when button held:
            if (secondaryInteractAction[primaryLaser.inputSource].state == true)
            {
                if (isUsingSnapPoint)
                {
                    ClearActiveSnapPoint(draggingDP);
                }
                return;
            }


            bool foundSnapPoint = primaryLaser.DetectSnapPoints(out DPSnapPoint foundPoint);

            //If we found a new snap point
            if (foundSnapPoint && foundPoint != activeSnapPoint)
            {
                activeSnapPoint = foundPoint;

                draggingDP.KillTransitions();

                //draggingDP.TransitionOverlayWidth(foundPoint.maxOverlayWidth, transitionSnapPointSpeed, false);
                draggingDP.TransitionOverlayCurvature(foundPoint.overlayCurvature, transitionSnapPointSpeed, false);

                activeSnapPoint.PreviewSnappedDP(draggingDP);

                foundPoint.iconDP.TransitionOverlayWidth(0.07f, transitionSnapPointSpeed, false);

                Vector3 inFrontPos = foundPoint.transform.localPosition + foundPoint.transform.up * -0.01f;

                draggingDP.TransitionOverlayPosition(inFrontPos, foundPoint.transform.localEulerAngles, transitionSnapPointSpeed,
                                                     Ease.InOutCubic, false);


                //Size change:
                if (draggingDP.isResponsive && activeSnapPoint.useWindowResizing && DPSettings.config.snapPointsResize)
                {
                    draggingDP.ResizeForRatio(activeSnapPoint.resizeRatioX, activeSnapPoint.resizeRatioY);
                }

                draggingDP.snapPointQueuedToResize = true;
            }

            //If we were using a snap point, but no longer are, reset state
            else if (isUsingSnapPoint && !foundSnapPoint)
            {
                ClearActiveSnapPoint(draggingDP);
            }
        }
        /// <summary>
        /// Main function to launch and display an app.
        /// </summary>
        /// <param name="appKey">The key of the app to launch</param>
        /// <param name="snapPoint">The snap point to launch the app on, if any</param>
        /// <param name="spawnPos">The spawn pos for the app, if not using snap points</param>
        /// <param name="spawnRot">The spawn rot for the app, if not using snap points</param>
        /// <param name="device">The device it should be anchored to</param>
        public DPApp LaunchApp(string appKey, DPSnapPoint snapPoint = null, Vector3 spawnPos = new Vector3(), Vector3 spawnRot = new Vector3(),
                               DPOverlayTrackedDevice device        = DPOverlayTrackedDevice.None, bool isAnchoredToTheBar = true)
        {
            DPApp dpApp;

            //Check if the app is already open:
            if (openApps.ContainsKey(appKey))
            {
                dpApp = openApps[appKey];

                //Check if the snap point is the same as the one it's on already:
                if (snapPoint != null && snapPoint.dpApp == dpApp)
                {
                    snapPoint.CancelPreviewAndRestore();
                    return(dpApp);
                }

                //Don't make a new button since it's already open
            }
            else
            {
                dpApp = loadedApps[appKey];

                if (dpApp == null)
                {
                    Debug.LogError("Tried to open not-loaded DPApp :/ " + appKey);
                }

                AddOpenApp(dpApp);
            }


            dpApp.dpMain.KillTransitions();


            //If the app was previously on a snap point, clear the data of that snap point:
            if (dpApp.snapPoint != null)
            {
                dpApp.snapPoint.ClearAllSnapData();
            }

            //If the new snap point has an app on it, minimize that app:
            if (snapPoint != null && snapPoint.isOccupied)
            {
                if (snapPoint.dpApp != null)
                {
                    MinimizeApp(snapPoint.dpApp.appKey);
                }
                else
                {
                    DPUIManager.Animate(snapPoint.dpBase, DPAnimation.FadeOut);
                    snapPoint.ClearAllSnapData();
                }
            }


            //Disable look hiding
            dpApp.dpMain.useLookHiding      = false;
            dpApp.dpMain.useDistanceHiding  = false;
            dpApp.dpMain.useSnapAnchoring   = false;
            dpApp.dpMain.useSmoothAnchoring = false;
            dpApp.dpMain.isInteractable     = true;

            //Clear the anchor:
            dpApp.dpMain.SetOverlayTrackedDevice(DPOverlayTrackedDevice.None);


            if (isAnchoredToTheBar)
            {
                AddAnchoredDP(dpApp.dpMain);
            }

            //If it's launching onto a snap point:
            if (snapPoint != null)
            {
                snapPoint.SetSnappedApp(dpApp);

                dpApp.dpMain.overlay.SetWidthInMeters(snapPoint.maxOverlayWidth, false);
                dpApp.dpMain.overlay.SetCurvature(snapPoint.overlayCurvature, false);
                dpApp.dpMain.SetOverlayTransform(snapPoint.transform.localPosition, snapPoint.transform.localEulerAngles, true, false);

                if (dpApp.dpMain.isResponsive && snapPoint.useWindowResizing && DPSettings.config.snapPointsResize)
                {
                    dpApp.dpMain.ResizeForRatio(snapPoint.resizeRatioX, snapPoint.resizeRatioY);
                }

                dpApp.dpMain.snapPointQueuedToResize = true;
            }
            //Else, we're launching it somewhere in the world:
            else
            {
                dpApp.dpMain.SetOverlayTransform(spawnPos, spawnRot, true, false);
                dpApp.dpMain.overlay.SetCurvature(0f, false);
            }

            ToggleDPApp(dpApp, true);
            dpApp.OnTheBarToggled(true);
            dpApp.OnOpen();


            return(dpApp);
        }