예제 #1
0
        /// <summary>
        /// Creates the temporary icon.
        /// </summary>
        /// <returns>The temporary icon.</returns>
        protected virtual void CreateTemporaryIcon(PointerEventData eventData)
        {
            Canvas canvas = UIUtility.FindInParents <Canvas>(this.gameObject);

            if (canvas == null || this.iconGraphic == null)
            {
                return;
            }

            // Create temporary panel
            GameObject iconObj = (GameObject)Instantiate((this.m_CloneTarget == null) ? this.iconGraphic.gameObject : this.m_CloneTarget);

            iconObj.transform.localScale = new Vector3(1f, 1f, 1f);
            iconObj.transform.SetParent(canvas.transform, false);
            iconObj.transform.SetAsLastSibling();
            (iconObj.transform as RectTransform).pivot = new Vector2(0.5f, 0.5f);

            // The icon will be under the cursor.
            // We want it to be ignored by the event system.
            iconObj.AddComponent <UIIgnoreRaycast>();

            // Save the dragging plane
            this.m_CurrentDraggingPlane = canvas.transform as RectTransform;

            // Set as the current dragging object
            this.m_CurrentDraggedObject = iconObj;

            // Update the icon position
            this.UpdateDraggedPosition(eventData);
        }
예제 #2
0
        /// <summary>
        /// Brings the window to the front.
        /// </summary>
        public void BringToFront()
        {
            // If we are allowed to re-parent the transform
            if (this.m_FocusAllowReparent)
            {
                UIScene scene = UIUtility.FindInParents <UIScene>(this.gameObject);

                // If the object has a parent ui scene
                if (scene != null && scene.content != null)
                {
                    this.gameObject.transform.SetParent(scene.content, true);
                }
                else
                {
                    Canvas canvas = UIUtility.FindInParents <Canvas>(this.gameObject);

                    // If the object has a parent canvas
                    if (canvas != null)
                    {
                        this.gameObject.transform.SetParent(canvas.transform, true);
                    }
                }
            }

            // Set as last sibling
            this.gameObject.transform.SetAsLastSibling();
        }
예제 #3
0
        /// <summary>
        /// Brings the game object to the front.
        /// </summary>
        /// <param name="go">Game Object.</param>
        public static void BringToFront(GameObject go)
        {
            Canvas canvas = UIUtility.FindInParents <Canvas>(go);

            // If the object has a parent canvas
            if (canvas != null)
            {
                go.transform.SetParent(canvas.transform, true);
            }

            // Set as last sibling
            go.transform.SetAsLastSibling();

            // Handle the always on top components
            if (canvas != null)
            {
                UIAlwaysOnTop[] alwaysOnTopComponenets = canvas.gameObject.GetComponentsInChildren <UIAlwaysOnTop>();

                if (alwaysOnTopComponenets.Length > 0)
                {
                    // Sort them by order
                    Array.Sort(alwaysOnTopComponenets);

                    foreach (UIAlwaysOnTop component in alwaysOnTopComponenets)
                    {
                        component.transform.SetAsLastSibling();
                    }
                }
            }
        }
예제 #4
0
 protected override void OnTransformParentChanged()
 {
     base.OnTransformParentChanged();
     this.m_Canvas = UIUtility.FindInParents <Canvas>((this.m_Target != null) ? this.m_Target.gameObject : this.gameObject);
     if (this.m_Canvas != null)
     {
         this.m_CanvasRectTransform = this.m_Canvas.transform as RectTransform;
     }
 }
예제 #5
0
 protected override void Awake()
 {
     base.Awake();
     m_parent      = (RectTransform)target.parent;
     this.m_Canvas = UIUtility.FindInParents <Canvas>((this.m_Target != null) ? this.m_Target.gameObject : this.gameObject);
     if (this.m_Canvas != null)
     {
         this.m_CanvasRectTransform = this.m_Canvas.transform as RectTransform;
     }
 }
예제 #6
0
        /// <summary>
        /// Brings the window to the front.
        /// </summary>
        public void BringToFront()
        {
            Canvas canvas = UIUtility.FindInParents <Canvas>(this.gameObject);

            // If the object has a parent canvas
            if (canvas != null)
            {
                this.gameObject.transform.SetParent(canvas.transform, true);
            }

            // Set as last sibling
            this.gameObject.transform.SetAsLastSibling();
        }
예제 #7
0
        /// <summary>
        /// Brings the game object to the front.
        /// </summary>
        /// <param name="go">Game Object.</param>
        public static void BringToFront(GameObject go)
        {
            Canvas canvas = UIUtility.FindInParents <Canvas>(go);

            // If the object has a parent canvas
            if (canvas != null)
            {
                go.transform.SetParent(canvas.transform, true);
            }

            // Set as last sibling
            go.transform.SetAsLastSibling();
        }
예제 #8
0
        /// <summary>
        /// Instantiate the tooltip game object if necessary.
        /// </summary>
        /// <param name="rel">Relative game object used to find the canvas.</param>
        public static void InstantiateIfNecessary(GameObject rel)
        {
            if (mInstance != null || UITooltipManager.Instance.prefab == null)
            {
                return;
            }

            Canvas canvas = UIUtility.FindInParents <Canvas>(rel);

            if (canvas != null)
            {
                Instantiate(UITooltipManager.Instance.prefab, canvas.transform, false);
            }
        }
예제 #9
0
        /// <summary>
        /// Brings the game object to the front.
        /// </summary>
        /// <param name="go">The Game Object.</param>
        /// <param name="allowReparent">Should we allow the method to change the Game Object's parent.</param>
        public static void BringToFront(GameObject go, bool allowReparent)
        {
            Transform root = null;

            // Check if this game object is part of a UI Scene
            UIScene scene = UIUtility.FindInParents <UIScene>(go);

            // If the object has a parent ui scene
            if (scene != null && scene.content != null)
            {
                root = scene.content;
            }
            else
            {
                // Use canvas as root
                Canvas canvas = UIUtility.FindInParents <Canvas>(go);
                if (canvas != null)
                {
                    root = canvas.transform;
                }
            }

            // If the object has a parent canvas
            if (allowReparent && root != null)
            {
                go.transform.SetParent(root, true);
            }

            // Set as last sibling
            go.transform.SetAsLastSibling();

            // Handle the always on top components
            if (root != null)
            {
                UIAlwaysOnTop[] alwaysOnTopComponenets = root.gameObject.GetComponentsInChildren <UIAlwaysOnTop>();

                if (alwaysOnTopComponenets.Length > 0)
                {
                    // Sort them by order
                    Array.Sort(alwaysOnTopComponenets);

                    foreach (UIAlwaysOnTop component in alwaysOnTopComponenets)
                    {
                        component.transform.SetAsLastSibling();
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Creates a modal box
        /// </summary>
        /// <param name="rel">Relative game object used to find the canvas.</param>
        public UIModalBox Create(GameObject rel)
        {
            if (this.m_ModalBoxPrefab == null || rel == null)
            {
                return(null);
            }

            Canvas canvas = UIUtility.FindInParents <Canvas>(rel);

            if (canvas != null)
            {
                GameObject obj = Instantiate(this.m_ModalBoxPrefab, canvas.transform, false);

                return(obj.GetComponent <UIModalBox>());
            }

            return(null);
        }
예제 #11
0
        protected override void Awake()
        {
            base.Awake();

            // Make sure we have toggle group
            if (this.group == null)
            {
                // Try to find the group in the parents
                ToggleGroup grp = UIUtility.FindInParents <ToggleGroup>(this.gameObject);

                if (grp != null)
                {
                    this.group = grp;
                }
                else
                {
                    // Add new group on the parent
                    this.group = this.transform.parent.gameObject.AddComponent <ToggleGroup>();
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Gets the black overlay based on relative game object. (In case we have multiple canvases.)
        /// </summary>
        /// <param name="relativeGameObject">The relative game object.</param>
        /// <returns>The black overlay component.</returns>
        public static UIBlackOverlay GetOverlay(GameObject relativeGameObject)
        {
            // Find the black overlay in the current canvas
            Canvas canvas = UIUtility.FindInParents <Canvas>(relativeGameObject);

            if (canvas != null)
            {
                // Try finding an overlay in the canvas
                UIBlackOverlay overlay = canvas.gameObject.GetComponentInChildren <UIBlackOverlay>();

                if (overlay != null)
                {
                    return(overlay);
                }

                // In case no overlay is found instantiate one
                if (UIBlackOverlayManager.Instance != null && UIBlackOverlayManager.Instance.prefab != null)
                {
                    return(UIBlackOverlayManager.Instance.Create(canvas.transform));
                }
            }

            return(null);
        }
예제 #13
0
        /// <summary>
        /// Creates the list and it's options.
        /// </summary>
        protected void CreateList()
        {
            // Get the root canvas
            Canvas rootCanvas = UIUtility.FindInParents <Canvas>(this.gameObject);

            // Reset the last list size
            this.m_LastListSize = Vector2.zero;

            // Clear the option texts list
            this.m_OptionObjects.Clear();

            // Create the list game object with the necessary components
            this.m_ListObject       = new GameObject("UISelectField - List", typeof(RectTransform));
            this.m_ListObject.layer = this.gameObject.layer;

            // Change the parent of the list
            this.m_ListObject.transform.SetParent(this.transform, false);

            // Get the select field list component
            UISelectField_List listComp = this.m_ListObject.AddComponent <UISelectField_List>();

            // Make sure it's the top-most element
            UIAlwaysOnTop aot = this.m_ListObject.AddComponent <UIAlwaysOnTop>();

            aot.order = UIAlwaysOnTop.SelectFieldOrder;

            // Get the list canvas group component
            this.m_ListCanvasGroup = this.m_ListObject.AddComponent <CanvasGroup>();

            // Change the anchor and pivot of the list
            RectTransform rect = (this.m_ListObject.transform as RectTransform);

            rect.localScale    = new Vector3(1f, 1f, 1f);
            rect.localPosition = Vector3.zero;
            rect.anchorMin     = Vector2.zero;
            rect.anchorMax     = Vector2.zero;
            rect.pivot         = new Vector2(0f, 1f);

            // Prepare the position of the list
            rect.anchoredPosition = new Vector3(this.listMargins.left, (this.listMargins.top * -1f), 0f);

            // Prepare the width of the list
            float width = (this.transform as RectTransform).sizeDelta.x;

            if (this.listMargins.left > 0)
            {
                width -= this.listMargins.left;
            }
            else
            {
                width += Math.Abs(this.listMargins.left);
            }
            if (this.listMargins.right > 0)
            {
                width -= this.listMargins.right;
            }
            else
            {
                width += Math.Abs(this.listMargins.right);
            }
            rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);

            // Hook the Dimensions Change event
            listComp.onDimensionsChange.AddListener(ListDimensionsChanged);

            // Apply the background sprite
            Image image = this.m_ListObject.AddComponent <Image>();

            if (this.listBackgroundSprite != null)
            {
                image.sprite = this.listBackgroundSprite;
            }
            image.type  = this.listBackgroundSpriteType;
            image.color = this.listBackgroundColor;

            // Prepare the vertical layout group
            VerticalLayoutGroup layoutGroup = this.m_ListObject.AddComponent <VerticalLayoutGroup>();

            layoutGroup.padding = this.listPadding;
            layoutGroup.spacing = this.listSpacing;

            // Prepare the content size fitter
            ContentSizeFitter fitter = this.m_ListObject.AddComponent <ContentSizeFitter>();

            fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            // Get the list toggle group
            ToggleGroup toggleGroup = this.m_ListObject.AddComponent <ToggleGroup>();

            // Create the options
            for (int i = 0; i < this.options.Count; i++)
            {
                if (i == 0 && this.startSeparator)
                {
                    this.m_StartSeparatorObject = this.CreateSeparator(i - 1);
                }

                // Create the option
                this.CreateOption(i, toggleGroup);

                // Create a separator if this is not the last option
                if (i < (this.options.Count - 1))
                {
                    this.CreateSeparator(i);
                }
            }

            // Prepare the list for the animation
            if (this.listAnimationType == ListAnimationType.None || this.listAnimationType == ListAnimationType.Fade)
            {
                // Starting alpha should be zero
                this.m_ListCanvasGroup.alpha = 0f;
            }
            else if (this.listAnimationType == ListAnimationType.Animation)
            {
                // Attach animator component
                Animator animator = this.m_ListObject.AddComponent <Animator>();

                // Set the animator controller
                animator.runtimeAnimatorController = this.listAnimatorController;

                // Set the animation triggers so we can use them to detect when animations finish
                listComp.SetTriggers(this.listAnimationOpenTrigger, this.listAnimationCloseTrigger);

                // Hook a callback on the finish event
                listComp.onAnimationFinish.AddListener(OnListAnimationFinish);
            }

            // Check if the navigation is disabled
            if (this.navigation.mode == Navigation.Mode.None)
            {
                this.CreateBlocker(rootCanvas);
            }
        }
예제 #14
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);
            }
        }
예제 #15
0
 protected virtual void OnCanvasGroupChanged()
 {
     // Get the canvas responsible for the tooltip
     this.m_Canvas = UIUtility.FindInParents <Canvas>(this.gameObject);
 }
예제 #16
0
 protected void Awake()
 {
     this.m_Toggle = this.gameObject.GetComponent <Toggle>();
     this.m_Menu   = UIUtility.FindInParents <Demo_FindMatch_Menu>(this.gameObject);
 }