Exemple #1
0
        /// <summary>
        /// Activate the scene, no transition is used.
        /// </summary>
        public void Activate()
        {
            // Make sure the scene is active and enabled
            if (!this.isActiveAndEnabled || !this.gameObject.activeInHierarchy)
            {
                return;
            }

            // If it's prefab
            if (this.m_Type == Type.Prefab || this.m_Type == Type.Resource)
            {
                GameObject prefab = null;

                if (this.m_Type == Type.Prefab)
                {
                    // Check the prefab
                    if (this.m_Prefab == null)
                    {
                        Debug.LogWarning("You are activating a prefab scene and no prefab is specified.");
                        return;
                    }

                    prefab = this.m_Prefab;
                }

                if (this.m_Type == Type.Resource)
                {
                    // Try loading the resource
                    if (string.IsNullOrEmpty(this.m_Resource))
                    {
                        Debug.LogWarning("You are activating a resource scene and no resource path is specified.");
                        return;
                    }

                    prefab = Resources.Load <GameObject>(this.m_Resource);
                }

                // Instantiate the prefab
                if (prefab != null)
                {
                    // Instantiate the prefab
                    GameObject obj = Instantiate <GameObject>(prefab);

                    // Set the content variable
                    this.m_Content = obj.transform;

                    // Set parent
                    this.m_Content.SetParent(this.transform);

                    // Check if it's a rect transform
                    if (this.m_Content is RectTransform)
                    {
                        // Get the rect transform
                        RectTransform rectTransform = this.m_Content as RectTransform;

                        // Prepare the rect
                        rectTransform.localScale    = Vector3.one;
                        rectTransform.localPosition = Vector3.zero;

                        // Set anchor and pivot
                        rectTransform.anchorMin = new Vector2(0f, 0f);
                        rectTransform.anchorMax = new Vector2(1f, 1f);
                        rectTransform.pivot     = new Vector2(0.5f, 0.5f);

                        // Get the canvas size
                        Canvas canvas = UIUtility.FindInParents <Canvas>(this.gameObject);

                        if (canvas == null)
                        {
                            canvas = this.gameObject.GetComponentInChildren <Canvas>();
                        }

                        if (canvas != null)
                        {
                            RectTransform crt = canvas.transform as RectTransform;

                            rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, crt.sizeDelta.x);
                            rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, crt.sizeDelta.y);
                        }

                        // Set position
                        rectTransform.anchoredPosition3D = new Vector3(0f, 0f, 0f);
                    }
                }
            }

            // Enable the game object
            if (this.m_Content != null)
            {
                this.m_Content.gameObject.SetActive(true);
            }

            // Set the first selected for the navigation
            if (this.isActiveAndEnabled && this.m_FirstSelected != null)
            {
                EventSystem.current.SetSelectedGameObject(this.m_FirstSelected);
            }

            // Set the active variable
            this.m_IsActivated = true;

            // Invoke the event
            if (this.onActivate != null)
            {
                this.onActivate.Invoke(this);
            }
        }
 protected virtual void OnCanvasGroupChanged()
 {
     // Get the canvas responsible for the tooltip
     this.m_Canvas = UIUtility.FindInParents <Canvas>(this.gameObject);
 }
Exemple #3
0
 protected void Awake()
 {
     this.m_Toggle = this.gameObject.GetComponent <Toggle>();
     this.m_Menu   = UIUtility.FindInParents <Demo_FindMatch_Menu>(this.gameObject);
 }
Exemple #4
0
 /// <summary>
 /// Brings the window to the front.
 /// </summary>
 public void BringToFront()
 {
     UIUtility.BringToFront(this.gameObject, this.m_FocusAllowReparent);
 }
Exemple #5
0
        public void OnTransitionBegin(UIWindow window, UIWindow.VisualState state, bool instant)
        {
            if (!this.IsActive() || window == null)
            {
                return;
            }

            // Check if we are receiving hide event and we are not showing the overlay to begin with, return
            if (state == UIWindow.VisualState.Hidden && !this.IsVisible())
            {
                return;
            }

            // Prepare transition duration
            float duration = (instant) ? 0f : window.transitionDuration;

            // Showing a window
            if (state == UIWindow.VisualState.Shown)
            {
                // Increase the window count so we know when to hide the overlay
                this.m_WindowsCount += 1;

                // Check if the overlay is already visible
                if (this.IsVisible())
                {
                    // Bring the window forward
                    UIUtility.BringToFront(window.gameObject);

                    // Break
                    return;
                }

                // Bring the overlay forward
                UIUtility.BringToFront(this.gameObject);

                // Bring the window forward
                UIUtility.BringToFront(window.gameObject);

                // Transition
                this.m_Image.CrossFadeAlpha(1f, duration, true);

                // Toggle block raycast on
                this.m_CanvasGroup.blocksRaycasts = true;
            }
            // Hiding a window
            else
            {
                // Decrease the window count
                this.m_WindowsCount -= 1;

                // Never go below 0
                if (this.m_WindowsCount < 0)
                {
                    this.m_WindowsCount = 0;
                }

                // Check if we still have windows using the overlay
                if (this.m_WindowsCount > 0)
                {
                    return;
                }

                // Transition
                this.m_Image.CrossFadeAlpha(0f, duration, true);

                // Toggle block raycast on
                this.m_CanvasGroup.blocksRaycasts = false;
            }
        }