/// <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();
                    }
                }
            }
        }
示例#2
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);
        }
示例#3
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;
     }
 }
        protected override void OnEnable()
        {
            base.OnEnable();

            // If constrain within canvas is enabled but no canvas is specified
            if (this.m_ConstrainWithinCanvas && this.m_CanvasRectTransform == null && this.m_Target != null)
            {
                this.m_CanvasRectTransform = UIUtility.FindInParents <Canvas>(this.m_Target.gameObject).transform as RectTransform;
            }
        }
        /// <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();
        }
示例#6
0
        protected override void Awake()
        {
            mInstance = this;

            // Get the rect transform
            this.m_Rect = (this.transform as RectTransform);

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

            // Get the canvas group
            this.m_CanvasGroup = this.gameObject.GetComponent <CanvasGroup>();
        }
        /// <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);
            }
        }
        /// <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);
        }
        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>();
                }
            }
        }
示例#10
0
        /// <summary>
        /// Brings the window to the front.
        /// </summary>
        public void BringToFront()
        {
            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();
        }
示例#11
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 as RectTransform;

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

                    // Set anchor and pivot
                    this.m_Content.anchorMin = new Vector2(0f, 0f);
                    this.m_Content.anchorMax = new Vector2(1f, 1f);
                    this.m_Content.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;

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

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

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

            // 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);
 }
        /// <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.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++)
            {
                // 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);
            }
        }