示例#1
0
        /// <summary>
        /// Get next event from the pending list to display it. (FIFO: first in first out)
        /// </summary>
        private void PullNextEvent()
        {
            // If there is no currently displayed event and at least one pending event...
            if ((currentDisplayedEvent == null) && (pendingEventItems.Count > 0))
            {
                // Retrieve the pending event from the list and set it as the current displayed event
                currentDisplayedEvent = pendingEventItems[0];
                pendingEventItems.RemoveAt(0);

                // Set the event item's position far away from its parent to ensure it's not visible at its first enabling frame
                currentDisplayedEvent.transform.localPosition = new Vector3(currentDisplayedEvent.transform.localPosition.x, -(currentDisplayedEvent.transform.parent.GetComponent <RectTransform>().rect.height / 2f), currentDisplayedEvent.transform.localPosition.z);

                // Start the showing transition at the first initialization state
                showingTransitionState = ShowingTransitionState.InitEnable;
            }
        }
示例#2
0
        /// <summary>
        /// Update the current displayed event item position to get smooth transitions.
        /// </summary>
        private void UpdateEventItemDisplay()
        {
            switch (showingTransitionState)
            {
            // Enable the event item to allow the ContentSizeFitter's next update to resize the event item's height
            case ShowingTransitionState.InitEnable:
                currentDisplayedEvent.SetActive(true);
                showingTransitionState = ShowingTransitionState.InitPosition;
                break;

            // Once we know the final height of the event item, place it juste above its parent (assumed to be the fullscreen-stretched EventHandler)
            case ShowingTransitionState.InitPosition:
                RectTransform ip_parentRectTransform = currentDisplayedEvent.transform.parent.GetComponent <RectTransform>();
                float         ip_parentRectOriginY   = ip_parentRectTransform.rect.height * (1f - ip_parentRectTransform.pivot.y);
                currentDisplayedEvent.transform.localPosition = new Vector3(currentDisplayedEvent.transform.localPosition.x, ip_parentRectOriginY + currentDisplayedEvent.GetComponent <RectTransform>().rect.height, currentDisplayedEvent.transform.localPosition.z);
                targetPositionY        = ip_parentRectOriginY;
                showingTransitionState = ShowingTransitionState.Showing;
                break;

            // Update the current displayed event item to smoothly show it
            case ShowingTransitionState.Showing:
                // If event item's position is near its target position, snap it, set the target position to above its parent, set the hiding transition triggering time, and go to the next step
                if (Mathf.Abs(currentDisplayedEvent.transform.localPosition.y - targetPositionY) <= transitionSnap)
                {
                    RectTransform s_parentRectTransform = currentDisplayedEvent.transform.parent.GetComponent <RectTransform>();
                    float         s_parentRectOriginY   = s_parentRectTransform.rect.height * (1f - s_parentRectTransform.pivot.y);
                    currentDisplayedEvent.transform.localPosition = new Vector3(currentDisplayedEvent.transform.localPosition.x, targetPositionY, currentDisplayedEvent.transform.localPosition.z);
                    targetPositionY        = s_parentRectOriginY + currentDisplayedEvent.GetComponent <RectTransform>().rect.height;
                    hidingTransitionTime   = Time.time + transitionDelay;
                    showingTransitionState = ShowingTransitionState.Waiting;
                }
                // Else, update event item's position to its target position
                else
                {
                    currentDisplayedEvent.transform.localPosition = new Vector3(currentDisplayedEvent.transform.localPosition.x, Mathf.Lerp(currentDisplayedEvent.transform.localPosition.y, targetPositionY, Time.deltaTime * transitionSpeed), currentDisplayedEvent.transform.localPosition.z);
                }
                break;

            // Once the event item is fully shown, wait for a given delay before starting to hide it
            case ShowingTransitionState.Waiting:
                if (Time.time >= hidingTransitionTime)
                {
                    showingTransitionState = ShowingTransitionState.Hiding;
                }
                break;

            // Update the current displayed event item to smoothly hide it
            case ShowingTransitionState.Hiding:
                // If event item's position is near its target position, destroy it, and end event item's display to allow the next pull
                if (Mathf.Abs(currentDisplayedEvent.transform.localPosition.y - targetPositionY) <= transitionSnap)
                {
                    Destroy(currentDisplayedEvent);
                    currentDisplayedEvent = null;
                    PullNextEvent();
                }
                // Else, update event item's position to its target position
                else
                {
                    currentDisplayedEvent.transform.localPosition = new Vector3(currentDisplayedEvent.transform.localPosition.x, Mathf.Lerp(currentDisplayedEvent.transform.localPosition.y, targetPositionY, Time.deltaTime * transitionSpeed), currentDisplayedEvent.transform.localPosition.z);
                }
                break;
            }
        }