Ejemplo n.º 1
0
 public void PulloutBeganDragging(PulloutState fromPulloutState)
 {
     if (fromPulloutState == PulloutState.Maximized)
     {
         chatViewController.ChatDismissing();
     }
 }
        nfloat PulloutDestinationYFromState(PulloutState state)
        {
            switch (state)
            {
            case PulloutState.Maximized: return(pulloutMaxDestY);

            case PulloutState.Minimized: return(pulloutMinDestY);

            default: return(pulloutNeutralDestY);
            }
        }
Ejemplo n.º 3
0
        public void PulloutDidFinishAnimating(PulloutState newPulloutState)
        {
            if (prevPulloutState == PulloutState.Maximized && newPulloutState != PulloutState.Maximized)
            {
                chatViewController.ChatDismissed();
            }
            else if (newPulloutState == PulloutState.Maximized)
            {
                chatViewController.ChatSummoned();
            }

            prevPulloutState = newPulloutState;
        }
        void AnimatePullout(PulloutState newPulloutState, float initialVelocity = 0.7f, bool launchKeyboard = false)
        {
            var initialVelocityVector = new CGVector(0f, initialVelocity);

            var springParameters = GetSpringTimingParameters(initialVelocityVector);
            var destinationY     = PulloutDestinationYFromState(newPulloutState);

            pulloutAnimator = new UIViewPropertyAnimator(0, springParameters)
            {
                Interruptible = true,
            };

            pulloutAnimator.AddAnimations(() =>
            {
                mainPulloutView.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = mainPulloutView.Frame.X,
                        Y = destinationY,
                    },
                    Size = mainPulloutView.Frame.Size,
                };

                mainPulloutView.SetPercentMaximized(newPulloutState == PulloutState.Maximized ? 1 : 0);
                mainPulloutView.SetPercentMinimized(newPulloutState == PulloutState.Neutral || newPulloutState == PulloutState.Maximized ? 0 : 1);

                pulloutBackgroundView.Alpha = newPulloutState == PulloutState.Maximized ? 1 : 0;
            });

            if (launchKeyboard)
            {
                mainPulloutView.LaunchKeyboard();
            }

            pulloutAnimator.AddCompletion(pos =>
            {
                pulloutState = newPulloutState;
                mainPulloutView.PulloutDidFinishAnimating(newPulloutState);
            });

            pulloutAnimator.StartAnimation();
        }
Ejemplo n.º 5
0
        public Pullout(Rect screenRect, float minWidth, bool scrollable = false, Color?backgroundColor = null)
        {
            var maxWidth = screenRect.width;

            minWidth = Mathf.Max(minWidth, 0);
            minWidth = Mathf.Min(maxWidth, minWidth);

            var controlID = GUIUtility.GetControlID(FocusType.Keyboard, screenRect);

            state = StateObject.Get <PulloutState>(controlID);
            state.Tick();

            if (backgroundColor != null)
            {
                state.Setup(backgroundColor.Value);
            }

            var mousePosition = Event.current.mousePosition;

            if (screenRect.Contains(mousePosition) && mousePosition.x - screenRect.x < state.edgePosition)
            {
                if (!state.mouseIn && (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID))
                {
                    state.mouseIn = true;
                    wantsRepaint  = true;
                }

                if (state.mouseIn)
                {
                    state.wantedEdgePosition = maxWidth;
                }

                if (GUIUtility.keyboardControl == controlID)
                {
                    GUIUtility.hotControl = controlID;
                }

                HandleUtility.AddDefaultControl(controlID);
            }
            else
            {
                if (state.mouseIn)
                {
                    state.mouseIn = false;
                    wantsRepaint  = true;
                }
                state.wantedEdgePosition = minWidth;
            }

            disposables.Push(new HandleGUI());
            disposables.Push(new GUILayoutArea(screenRect));

            //groupArea = new GroupArea(new Rect(screenRect.x, screenRect.y, screenRect.width, screenRect.height));


            var offset = maxWidth - state.edgePosition;

            disposables.Push(new GUICustomViewport(new Rect(0, 0, screenRect.width, screenRect.height),
                                                   new Rect(offset, 0, screenRect.width - offset, screenRect.height)));

            disposables.Push(new GUIMatrix(Matrix4x4.TRS(new Vector3(-offset, 0, 0), Quaternion.identity,
                                                         new Vector3(1, 1, 1))));

            using (new HandleColor(Color.red)) {
                Handles.DrawLine(new Vector3(maxWidth + 1, 0, 0),
                                 new Vector3(maxWidth + 1, screenRect.height, 0));
                Handles.DrawLine(new Vector3(0, 0, 0),
                                 new Vector3(maxWidth + 1, 0, 0));
                Handles.DrawLine(new Vector3(0, screenRect.height, 0),
                                 new Vector3(maxWidth + 1, screenRect.height, 0));
            }

            GUI.DrawTexture(new Rect(0, 0, maxWidth, screenRect.height),
                            state.background, ScaleMode.ScaleAndCrop);

            using (new HandleColor(Color.green)) {
                Handles.DrawLine(new Vector3(0, 0, 0),
                                 new Vector3(0, screenRect.height, 0));
            }

            if (scrollable)
            {
                disposables.Push(new ScrollView());
            }

            oldGUIEnabled = GUI.enabled;
            GUI.enabled   = state.mouseIn && state.Opened(maxWidth);

            if (Math.Abs(state.edgePosition - maxWidth) > 0.25f)
            {
                wantsRepaint = true;
            }
        }
Ejemplo n.º 6
0
        public Pullout(Rect screenRect, float minWidth, bool scrollable = false, Color? backgroundColor = null)
        {
            var maxWidth = screenRect.width;

            minWidth = Mathf.Max(minWidth, 0);
            minWidth = Mathf.Min(maxWidth, minWidth);

            var controlID = GUIUtility.GetControlID(FocusType.Keyboard, screenRect);
            state = StateObject.Get<PulloutState>(controlID);
            state.Tick();

            if (backgroundColor != null) {
                state.Setup(backgroundColor.Value);
            }

            var mousePosition = Event.current.mousePosition;
            if (screenRect.Contains(mousePosition) && mousePosition.x - screenRect.x < state.edgePosition) {
                if (!state.mouseIn && (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID)) {
                    state.mouseIn = true;
                    wantsRepaint = true;
                }

                if (state.mouseIn) {
                    state.wantedEdgePosition = maxWidth;
                }

                if (GUIUtility.keyboardControl == controlID) {
                    GUIUtility.hotControl = controlID;
                }

                HandleUtility.AddDefaultControl(controlID);
            }
            else {
                if (state.mouseIn) {
                    state.mouseIn = false;
                    wantsRepaint = true;
                }
                state.wantedEdgePosition = minWidth;
            }

            disposables.Push(new HandleGUI());
            disposables.Push(new GUILayoutArea(screenRect));

            //groupArea = new GroupArea(new Rect(screenRect.x, screenRect.y, screenRect.width, screenRect.height));

            var offset = maxWidth - state.edgePosition;

            disposables.Push(new GUICustomViewport(new Rect(0, 0, screenRect.width, screenRect.height),
                new Rect(offset, 0, screenRect.width - offset, screenRect.height)));

            disposables.Push(new GUIMatrix(Matrix4x4.TRS(new Vector3(-offset, 0, 0), Quaternion.identity,
                new Vector3(1, 1, 1))));

            using (new HandleColor(Color.red)) {
                Handles.DrawLine(new Vector3(maxWidth + 1, 0, 0),
                    new Vector3(maxWidth + 1, screenRect.height, 0));
                Handles.DrawLine(new Vector3(0, 0, 0),
                    new Vector3(maxWidth + 1, 0, 0));
                Handles.DrawLine(new Vector3(0, screenRect.height, 0),
                    new Vector3(maxWidth + 1, screenRect.height, 0));
            }

            GUI.DrawTexture(new Rect(0, 0, maxWidth, screenRect.height),
                state.background, ScaleMode.ScaleAndCrop);

            using (new HandleColor(Color.green)) {
                Handles.DrawLine(new Vector3(0, 0, 0),
                    new Vector3(0, screenRect.height, 0));
            }

            if (scrollable) {
                disposables.Push(new ScrollView());
            }

            oldGUIEnabled = GUI.enabled;
            GUI.enabled = state.mouseIn && state.Opened(maxWidth);

            if (Math.Abs(state.edgePosition - maxWidth) > 0.25f) {
                wantsRepaint = true;
            }
        }