コード例 #1
0
ファイル: DPUIManager.cs プロジェクト: ouarlone/DesktopPortal
        private static IEnumerator HandleAnimationData(DPAnimationState state)
        {
            //Add the new data to the list
            currentAnimations.Add(state);

            //Trigger events:
            // if (state.isChangingVisibility) {
            //if (state.isShowing) state.dpBase.OnShowing();
            //else state.cuiGroup.OnHiding();
            //}

            //Wait for the animation to complete
            yield return(new WaitForSeconds(state.animLength));

            //Wait an extra frame to finish
            yield return(null);

            yield return(null);


            //Check if it's still valid, if so remove it
            if (currentAnimations.Contains(state))
            {
                //Move the overlay to it's final position
                state.dpBase.transform.localPosition = state.finalPos;
                state.dpBase.SyncTransform();

                //Disable the GO if needed
                //if (!state.isShowing) state.cuiGroup.gameObject.SetActive(false);
                //if (!state.isShowing)

                currentAnimations.Remove(state);
            }
        }
コード例 #2
0
ファイル: DPUIManager.cs プロジェクト: ouarlone/DesktopPortal
        private static void KillActiveAnimations(DPOverlayBase dpBase)
        {
            if (currentAnimations.Count <= 0)
            {
                return;
            }

            //Kill any existing animations
            DPAnimationState existingState = currentAnimations.Find(x => x.dpBase == dpBase);

            if (existingState != null)
            {
                currentAnimations.Remove(existingState);

                existingState.dpBase.KillTransitions();

                //Set the overlay to whatever final pos it had
                existingState.dpBase.transform.localPosition = existingState.finalPos;
                existingState.dpBase.SyncTransform();

                existingState.dpBase.overlay.SetWidthInMeters(existingState.finalWidth);

                if (existingState.data.changeVisibility)
                {
                    existingState.dpBase.overlay.SetVisible(existingState.data.show);
                }
            }
        }
コード例 #3
0
ファイル: DPUIManager.cs プロジェクト: ouarlone/DesktopPortal
        private static void AnimateInternal(DPOverlayBase dp, object anim, float overrideAnimTime = -1f)
        {
            KillActiveAnimations(dp);

            DPAnimationData data = GetDPAnimationFromEnum(anim.ToString().Replace("DPAnimations.", ""));

            if (data == null)
            {
                Debug.LogError("DPAnimationData ( " + anim.ToString() + ") could not be found, aborting!");
                return;
            }


            if (data.changeVisibility && data.show)
            {
                dp.overlay.SetVisible(true, false);
                dp.overlay.SetOpacity(0, false);

                foreach (DPOverlayBase child in dp.children)
                {
                    if (!child.followParentOpacity)
                    {
                        continue;
                    }
                    child.overlay.SetVisible(true, false);
                    child.overlay.SetOpacity(0, false);
                }
            }

            //Calculate the animation time
            float finalAnimTime;

            if (overrideAnimTime > 0)
            {
                finalAnimTime = overrideAnimTime;
            }
            else
            {
                finalAnimTime = animTime;
            }


            DPAnimationState state = new DPAnimationState()
            {
                dpBase     = dp,
                data       = data,
                animLength = finalAnimTime,
                finalPos   = dp.transform.localPosition,
                finalWidth = dp.overlay.width
            };


            //MOVEMENT ANIMATION
            if (data.move)
            {
                Vector3 curPos = dp.transform.localPosition;

                //Animate pos is either the starting position or the ending position of the animation depending on if it is showing or hiding
                Vector3 animatePos = curPos + (Vector3.right * data.moveDir.x * dp.overlay.width) + (Vector3.up * data.moveDir.y * dp.overlay.width) +
                                     (Vector3.forward * data.moveDir.z * dp.overlay.width);

                Vector3 anchoredPos = curPos + (dp.transform.right * data.moveDir.x) + (dp.transform.up * data.moveDir.y) + (dp.transform.forward * data.moveDir.z);

                if (data.changeVisibility)
                {
                    //If it's fading in:
                    if (data.show)
                    {
                        dp.SetOverlayTransform(animatePos, dp.transform.localEulerAngles, true, false, true);

                        dp.TransitionOverlayPosition(curPos, dp.transform.localEulerAngles, finalAnimTime, animShowEasing, false);
                    }
                    //If it's fading out:
                    else
                    {
                        dp.TransitionOverlayPosition(animatePos, dp.transform.localEulerAngles, finalAnimTime, animHideEasing, false);
                    }
                }

                //If it's not changing visibility:
                else
                {
                    dp.TransitionOverlayPosition(animatePos, dp.transform.localEulerAngles, finalAnimTime, animHideEasing, false);
                }
            }


            //VISIBILITY ANIMATION
            if (data.changeVisibility)
            {
                if (data.show)
                {
                    if (dp.overlay.targetOpacity <= 0f)
                    {
                        Debug.LogError("Overlay target opacity was 0f!");
                    }

                    dp.TransitionOverlayOpacity(dp.overlay.targetOpacity, finalAnimTime, animShowEasing, false);
                }
                else
                {
                    dp.TransitionOverlayOpacity(0f, finalAnimTime, animHideEasing, false);
                }
            }

            //SCALING ANIMATION
            if (data.scale)
            {
                if (data.changeVisibility)
                {
                    if (data.show)
                    {
                        //float curWidth = dp.overlay.width;
                        dp.overlay.SetWidthInMeters(dp.overlay.width * data.widthScaleMulti, false);
                        dp.TransitionOverlayWidth(dp.overlay.width, finalAnimTime, false);
                    }
                    else
                    {
                        dp.TransitionOverlayWidth(dp.overlay.width * data.widthScaleMulti, finalAnimTime, false);
                    }
                }

                else
                {
                    dp.TransitionOverlayWidth(dp.overlay.width * data.widthScaleMulti, finalAnimTime, false);
                }
            }


            I.StartCoroutine(HandleAnimationData(state));
        }