protected void Awake() { // Make sure we have the window component if (this.m_Window == null) { this.m_Window = this.gameObject.GetComponent <UIWindow>(); } // Prepare some window parameters this.m_Window.ID = UIWindowID.ModalBox; this.m_Window.escapeKeyAction = UIWindow.EscapeKeyAction.None; // Hook an event to the window this.m_Window.onTransitionComplete.AddListener(OnWindowTransitionEnd); // Prepare the always on top component UIAlwaysOnTop aot = this.gameObject.GetComponent <UIAlwaysOnTop>(); aot.order = UIAlwaysOnTop.ModalBoxOrder; // Hook the button click event if (this.m_ConfirmButton != null) { this.m_ConfirmButton.onClick.AddListener(Confirm); } if (this.m_CancelButton != null) { this.m_CancelButton.onClick.AddListener(Close); } }
protected virtual void CreateBlocker(Canvas rootCanvas) { // Create blocker GameObject. GameObject blocker = new GameObject("Blocker"); // Setup blocker RectTransform to cover entire root canvas area. RectTransform blockerRect = blocker.AddComponent <RectTransform>(); blockerRect.SetParent(rootCanvas.transform, false); blockerRect.localScale = Vector3.one; blockerRect.localPosition = Vector3.zero; blockerRect.anchorMin = Vector3.zero; blockerRect.anchorMax = Vector3.one; blockerRect.sizeDelta = Vector2.zero; // Add image since it's needed to block, but make it clear. Image blockerImage = blocker.AddComponent <Image>(); blockerImage.color = Color.clear; // Add button since it's needed to block, and to close the dropdown when blocking area is clicked. Button blockerButton = blocker.AddComponent <Button>(); blockerButton.onClick.AddListener(Close); // Make sure it's the top-most element UIAlwaysOnTop aot = blocker.AddComponent <UIAlwaysOnTop>(); aot.order = UIAlwaysOnTop.SelectFieldBlockerOrder; this.m_Blocker = blocker; }
public int CompareTo(object obj) { if (obj != null) { UIAlwaysOnTop comp = obj as UIAlwaysOnTop; if (comp != null) { return(this.order.CompareTo(comp.order)); } } return(1); }
protected virtual void Awake() { // Save instance reference mInstance = this; // Get the rect transform this.m_Rect = this.gameObject.GetComponent <RectTransform>(); // Get the canvas group this.m_CanvasGroup = this.gameObject.GetComponent <CanvasGroup>(); // Make sure the tooltip does not block raycasts this.m_CanvasGroup.blocksRaycasts = false; this.m_CanvasGroup.interactable = false; // Get the content size fitter this.m_SizeFitter = this.gameObject.GetComponent <ContentSizeFitter>(); // Prepare the content size fitter this.m_SizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // Prepare the vertical layout group VerticalLayoutGroup vlg = this.gameObject.GetComponent <VerticalLayoutGroup>(); vlg.childControlHeight = true; vlg.childControlWidth = true; // Make sure we have the always on top component UIAlwaysOnTop aot = this.gameObject.GetComponent <UIAlwaysOnTop>(); if (aot == null) { aot = this.gameObject.AddComponent <UIAlwaysOnTop>(); aot.order = UIAlwaysOnTop.TooltipOrder; } // Hide this.SetAlpha(0f); this.m_VisualState = VisualState.Hidden; this.InternalOnHide(); }
/// <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); } }