Inheritance: HorizontalOrVerticalLayoutGroup
 static public int SetLayoutHorizontal(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.UI.VerticalLayoutGroup self = (UnityEngine.UI.VerticalLayoutGroup)checkSelf(l);
         self.SetLayoutHorizontal();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Beispiel #2
0
    void Start()
    {
        FingerGestures.OnDragMove   += OnDragMove;
        FingerGestures.OnFingerDown += OnFingerDown;
        tiles = new StageType[height, width];
        gos   = new GameObject[height, width];
        var save_btn_go = gameObject.transform.Find("Controls/save_btn").gameObject;

        save_btn_button = save_btn_go.GetComponent <UnityEngine.UI.Button>();
        save_btn_button.onClick.AddListener(OnSaveBtnClick);
        TileBtns_go = gameObject.transform.Find("Controls/ScollView/TileBtns").gameObject;
        TileBtns_verticallayoutgroup = TileBtns_go.GetComponent <UnityEngine.UI.VerticalLayoutGroup>();
        Container   = new UIContainer <TileBtn>(TileBtns_verticallayoutgroup.gameObject);
        Template_go = gameObject.transform.Find("Controls/ScollView/TileBtns/Template").gameObject;
        tileGo      = gameObject.transform.Find("ScrollView/Content/tile").gameObject;
        tileGo.GetComponent <Image>();
        tileContent           = gameObject.transform.Find("ScrollView/Content").gameObject.GetComponent <RectTransform>();
        tileContent.sizeDelta = new Vector2(width * tileSize, height * tileSize);
        var brushs = Enum.GetValues(typeof(StageType));

        Container.Resize(brushs.Length);
        for (int i = 0; i < Container.ChildCount; i++)
        {
            var t = Container.GetChild(i);
            t.UpdateInfo((StageType)i);
            t.OnClickCallback = OnClick;
        }
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        achList = new List <AchievementBase>();
        UnityEngine.UI.VerticalLayoutGroup vlg = GetComponent <VerticalLayoutGroup>();
        RectTransform rectTransform            = GetComponent <RectTransform>();

        rectTransform.sizeDelta = new Vector2(1, rectTransform.rect.height * achievementPrefabList.Count);
        rectTransform.position  = new Vector3(rectTransform.position.x, -1000, 0); //force to see the first
        foreach (AchievementBase a in achievementPrefabList)
        {
            GameObject panel = Instantiate(achPanel);
            panel.transform.SetParent(this.gameObject.transform);

            GameObject titleObj       = panel.transform.Find("Title").gameObject;
            GameObject descriptionObj = panel.transform.Find("Description").gameObject;
            GameObject sliderObj      = panel.transform.Find("Slider").gameObject;

            Text titleText = titleObj.GetComponent <Text>();
            titleText.text = a.ach_name;
            Text desText = descriptionObj.GetComponent <Text>();
            desText.text = a.description;
            Slider slider = sliderObj.GetComponent <Slider>();
            slider.value = a.progress_percent;

            GameObject valueobj  = sliderObj.transform.Find("ProgressValue").gameObject;
            Text       valuetext = valueobj.GetComponent <Text>();
            valuetext.text = a.curr_progress.ToString() + "/" + a.max_progress.ToString();

            achList.Add(a);
        }
    }
Beispiel #4
0
        public void OnEnable()
        {
            _instance = this;
            _layout = playerListContentTransform.GetComponent<VerticalLayoutGroup>();

			QuickplayLobby quickPlayLobby = FindObjectOfType<QuickplayLobby>();
			if (quickPlayLobby != null)
				quickPlayLobby.panel.SetActive(false);
        }
    // Start is called before the first frame update
    void Start()
    {
        GameObject content = transform.Find("Viewport").GetChild(0).gameObject;

        UnityEngine.UI.VerticalLayoutGroup group = content.GetComponent <UnityEngine.UI.VerticalLayoutGroup>();
        int padding = group.padding.top + group.padding.bottom;

        maxScrollHeight = Constants.scrollButtonHeight * Constants.countWorlds + padding;
    }
Beispiel #6
0
 static public int CalculateLayoutInputHorizontal(IntPtr l)
 {
     try {
         UnityEngine.UI.VerticalLayoutGroup self = (UnityEngine.UI.VerticalLayoutGroup)checkSelf(l);
         self.CalculateLayoutInputHorizontal();
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #7
0
 static public int SetLayoutVertical(IntPtr l)
 {
     try {
         UnityEngine.UI.VerticalLayoutGroup self = (UnityEngine.UI.VerticalLayoutGroup)checkSelf(l);
         self.SetLayoutVertical();
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #8
0
 static public int SetLayoutHorizontal(IntPtr l)
 {
     try {
         UnityEngine.UI.VerticalLayoutGroup self = (UnityEngine.UI.VerticalLayoutGroup)checkSelf(l);
         self.SetLayoutHorizontal();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public static int CalculateLayoutInputVertical(IntPtr l)
 {
     try {
         UnityEngine.UI.VerticalLayoutGroup self=(UnityEngine.UI.VerticalLayoutGroup)checkSelf(l);
         self.CalculateLayoutInputVertical();
         pushValue(l,true);
         return 1;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
Beispiel #10
0
 static public int SetLayoutHorizontal(IntPtr l)
 {
     try {
         UnityEngine.UI.VerticalLayoutGroup self = (UnityEngine.UI.VerticalLayoutGroup)checkSelf(l);
         self.SetLayoutHorizontal();
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Beispiel #11
0
 public void OnEnable()
 {
     if (_instance == null)
     {
         _instance = this;
         _layout = playerListContentTransform.GetComponent<VerticalLayoutGroup>();
     }
     else if (_instance != this)
     {
         Destroy(gameObject);
     }
 }
Beispiel #12
0
 static int QPYX_SetLayoutVertical_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 1);
         UnityEngine.UI.VerticalLayoutGroup QPYX_obj_YXQP = (UnityEngine.UI.VerticalLayoutGroup)ToLua.CheckObject <UnityEngine.UI.VerticalLayoutGroup>(L_YXQP, 1);
         QPYX_obj_YXQP.SetLayoutVertical();
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
 public void Inisialize(UnityEngine.UI.CustomScrollRect scroll, int data_count, Action <RectTransform, int> on_swap = null)
 {
     updateItem = on_swap;
     scrollRect = scroll;
     verLayout  = scrollRect.content.GetComponent <UnityEngine.UI.VerticalLayoutGroup>();
     childObj   = scrollRect.GetChild();
     dataCount  = data_count;
     Reset();
     scrollRect.onValueChanged.AddListener(SwapScroll);
     scrollRect.UpdateVerticalBerSizeEX(UpdateVerticalBerSize);
     scrollRect.UpdateVerticalBerValueEX(UpdateVerticalBerValue);
     scrollRect.SetVerticalNormalizePositionEX(VerticalNorNormalizedPosition);
 }
 static int CalculateLayoutInputVertical(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.UI.VerticalLayoutGroup obj = (UnityEngine.UI.VerticalLayoutGroup)ToLua.CheckObject(L, 1, typeof(UnityEngine.UI.VerticalLayoutGroup));
         obj.CalculateLayoutInputVertical();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int SetLayoutVertical(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.UI.VerticalLayoutGroup obj = (UnityEngine.UI.VerticalLayoutGroup)ToLua.CheckObject <UnityEngine.UI.VerticalLayoutGroup>(L, 1);
         obj.SetLayoutVertical();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #16
0
    protected override void OnAwakeView()
    {
        Transform _Text_TextSample0 = transform.FindChild("TextSample");
        textSample = _Text_TextSample0.GetComponent<Text>();
        Transform ScrollView1 = transform.FindChild("ScrollView");
        Transform Viewport10 = ScrollView1.FindChild("Viewport");
        Transform _Panel_Content100 = Viewport10.FindChild("Content");
        contentPanel = _Panel_Content100.GetComponent<RectTransform>();

        layoutGroup = contentPanel.GetComponent<VerticalLayoutGroup>();
        if(layoutGroup == null)
        {
            layoutGroup = contentPanel.gameObject.AddComponent<VerticalLayoutGroup>();
        }

        UpdateWidth();
    }
Beispiel #17
0
    public RichEditBlock(Transform parent, float width, float lineSpacing)
    {
        gameObject = new GameObject("RichEditBlock");
        transform = gameObject.AddComponent<RectTransform>();
        transform.SetParent(parent, false);
        transform.SetAsLastSibling();

        layoutElement = gameObject.AddComponent<LayoutElement>();
        layoutElement.preferredWidth = width;
        layoutElement.preferredHeight = 0;

        layoutGroup = gameObject.AddComponent<VerticalLayoutGroup>();
        layoutGroup.childForceExpandWidth = false;
        layoutGroup.childForceExpandHeight = false;
        layoutGroup.childAlignment = TextAnchor.LowerLeft;
        layoutGroup.spacing = lineSpacing;

        currentLine = AddNewLine();
    }
        /// <summary>
        /// Creates a option.
        /// </summary>
        /// <param name="index">Index.</param>
        protected void CreateOption(int index, ToggleGroup toggleGroup)
        {
            if (this.m_ListObject == null)
            {
                return;
            }

            // Create the option game object with it's components
            GameObject optionObject = new GameObject("Option " + index.ToString(), typeof(RectTransform));

            // Change parents
            optionObject.transform.SetParent(this.m_ListObject.transform, false);

            // Get the option component
            UISelectField_Option optionComp = optionObject.AddComponent <UISelectField_Option>();

            // Prepare the option background
            if (this.optionBackgroundSprite != null)
            {
                Image image = optionObject.AddComponent <Image>();
                image.sprite = this.optionBackgroundSprite;
                image.type   = this.optionBackgroundSpriteType;
                image.color  = this.optionBackgroundSpriteColor;

                // Add the graphic as the option transition target
                optionComp.targetGraphic = image;
            }

            // Prepare the option for animation
            if (this.optionBackgroundTransitionType == Transition.Animation)
            {
                // Attach animator component
                Animator animator = optionObject.AddComponent <Animator>();

                // Set the animator controller
                animator.runtimeAnimatorController = this.optionBackgroundAnimatorController;
            }

            // Apply the option padding
            VerticalLayoutGroup vlg = optionObject.AddComponent <VerticalLayoutGroup>();

            vlg.padding = this.optionPadding;

            // Create the option text
            GameObject textObject = new GameObject("Label", typeof(RectTransform));

            // Change parents
            textObject.transform.SetParent(optionObject.transform, false);

            // Apply pivot
            (textObject.transform as RectTransform).pivot = new Vector2(0f, 1f);

            // Prepare the text
            Text text = textObject.AddComponent <Text>();

            text.font      = this.optionFont;
            text.fontSize  = this.optionFontSize;
            text.fontStyle = this.optionFontStyle;
            text.color     = this.optionColor;

            if (this.options != null)
            {
                text.text = this.options[index];
            }

            // Apply normal state transition color
            if (this.optionTextTransitionType == OptionTextTransitionType.CrossFade)
            {
                text.canvasRenderer.SetColor(this.optionTextTransitionColors.normalColor);
            }

            // Add and prepare the text effect
            if (this.optionTextEffectType != OptionTextEffectType.None)
            {
                if (this.optionTextEffectType == OptionTextEffectType.Shadow)
                {
                    Shadow effect = textObject.AddComponent <Shadow>();
                    effect.effectColor     = this.optionTextEffectColor;
                    effect.effectDistance  = this.optionTextEffectDistance;
                    effect.useGraphicAlpha = this.optionTextEffectUseGraphicAlpha;
                }
                else if (this.optionTextEffectType == OptionTextEffectType.Outline)
                {
                    Outline effect = textObject.AddComponent <Outline>();
                    effect.effectColor     = this.optionTextEffectColor;
                    effect.effectDistance  = this.optionTextEffectDistance;
                    effect.useGraphicAlpha = this.optionTextEffectUseGraphicAlpha;
                }
            }

            // Initialize the option component
            optionComp.Initialize(this, text);

            // Set active if it's the selected one
            if (index == this.selectedOptionIndex)
            {
                optionComp.isOn = true;
            }

            // Register to the toggle group
            if (toggleGroup != null)
            {
                optionComp.group = toggleGroup;
            }

            // Hook some events
            optionComp.onSelectOption.AddListener(OnOptionSelect);
            optionComp.onPointerUp.AddListener(OnOptionPointerUp);

            // Add it to the list
            if (this.m_OptionObjects != null)
            {
                this.m_OptionObjects.Add(optionComp);
            }
        }
 public void OnEnable()
 {
     _instance = this;
     _layout = playerListContentTransform.GetComponent<VerticalLayoutGroup>();
 }
 private void Start()
 {
     _menu = GetComponent<VerticalLayoutGroup>();
     _button = GetComponentInChildren<Button>();
 }
        private GameObject TextTipObj()
        {
            GameObject obj = new GameObject("TextTip", typeof(RectTransform), typeof(Image), /*typeof(Canvas),*/ typeof(CanvasGroup), typeof(VerticalLayoutGroup), typeof(ContentSizeFitter));

            RectTransform rt = obj.GetComponent <RectTransform>();

            Image img = obj.GetComponent <Image>();

            img.raycastTarget = false;
            img.type          = Image.Type.Sliced;
            img.sprite        = Resources.Load <Sprite>("Sprite/frame_background");

            VerticalLayoutGroup vg = obj.GetComponent <VerticalLayoutGroup>();

            vg.padding.left           = 16;
            vg.padding.right          = 16;
            vg.padding.top            = 10;
            vg.padding.bottom         = 16;
            vg.childAlignment         = TextAnchor.MiddleCenter;
            vg.childControlWidth      = true;
            vg.childControlHeight     = false;
            vg.childForceExpandWidth  = true;
            vg.childForceExpandHeight = false;

            ContentSizeFitter sizeFt = obj.GetComponent <ContentSizeFitter>();

            sizeFt.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            sizeFt.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
            sizeFt.enabled       = false;

            obj.GetComponent <CanvasGroup>().alpha = 0f;

            //text content
            GameObject topTxtObj    = new GameObject("topTxt", typeof(RectTransform), typeof(Text), typeof(LayoutElement), typeof(ContentSizeFitter));
            GameObject bottomTxtObj = new GameObject("bottomTxt", typeof(RectTransform), typeof(Text), typeof(LayoutElement), typeof(ContentSizeFitter));

            topTxtObj.transform.SetParent(rt, false);
            bottomTxtObj.transform.SetParent(rt, false);

            Text tText = topTxtObj.GetComponent <Text>();

            tText.fontSize           = 18;
            tText.font               = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            tText.alignment          = TextAnchor.UpperLeft;
            tText.horizontalOverflow = HorizontalWrapMode.Overflow;
            tText.raycastTarget      = false;

            Text bText = bottomTxtObj.GetComponent <Text>();

            bText.fontSize      = 15;
            bText.font          = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            bText.alignment     = TextAnchor.MiddleLeft;
            bText.raycastTarget = false;

            ContentSizeFitter topCZ = topTxtObj.GetComponent <ContentSizeFitter>();

            topCZ.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            topCZ.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
            topCZ.enabled       = false;

            ContentSizeFitter bottomCZ = bottomTxtObj.GetComponent <ContentSizeFitter>();

            bottomCZ.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
            bottomCZ.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
            bottomCZ.enabled       = false;

            obj.transform.SetParent(mRoot, false);

            mTipDict.Add(TipType.Txt, obj);
            return(obj);
        }
        /// <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);
            }
        }
        /// <summary>
        /// Creates a option.
        /// </summary>
        /// <param name="index">Index.</param>
        protected void CreateOption(int index, ToggleGroup toggleGroup)
        {
            if (this.m_ListObject == null)
            {
                return;
            }

            // Create the option game object with it's components
            GameObject optionObject = new GameObject("Option " + index.ToString(), typeof(RectTransform));

            optionObject.layer = this.gameObject.layer;

            // Change parents
            optionObject.transform.SetParent(this.m_ListObject.transform, false);
            optionObject.transform.localScale = new Vector3(1f, 1f, 1f);

            // Get the option component
            UISelectField_Option optionComp = optionObject.AddComponent <UISelectField_Option>();

            // Prepare the option background
            if (this.optionBackgroundSprite != null)
            {
                Image image = optionObject.AddComponent <Image>();
                image.sprite = this.optionBackgroundSprite;
                image.type   = this.optionBackgroundSpriteType;
                image.color  = this.optionBackgroundSpriteColor;

                // Add the graphic as the option transition target
                optionComp.targetGraphic = image;
            }

            // Prepare the option for animation
            if (this.optionBackgroundTransitionType == Transition.Animation)
            {
                // Attach animator component
                Animator animator = optionObject.AddComponent <Animator>();

                // Set the animator controller
                animator.runtimeAnimatorController = this.optionBackgroundAnimatorController;
            }

            // Apply the option padding
            VerticalLayoutGroup vlg = optionObject.AddComponent <VerticalLayoutGroup>();

            vlg.padding = this.optionPadding;

            // Create the option text
            GameObject textObject = new GameObject("Label", typeof(RectTransform));

            // Change parents
            textObject.transform.SetParent(optionObject.transform, false);

            // Apply pivot
            (textObject.transform as RectTransform).pivot = new Vector2(0f, 1f);

            // Prepare the text
            Text text = textObject.AddComponent <Text>();

            text.font      = this.optionFont;
            text.fontSize  = this.optionFontSize;
            text.fontStyle = this.optionFontStyle;
            text.color     = this.optionColor;

            if (this.options != null)
            {
                text.text = this.options[index];
            }

            // Apply normal state transition color
            if (this.optionTextTransitionType == OptionTextTransitionType.CrossFade)
            {
                text.canvasRenderer.SetColor(this.optionTextTransitionColors.normalColor);
            }

            // Add and prepare the text effect
            if (this.optionTextEffectType != OptionTextEffectType.None)
            {
                if (this.optionTextEffectType == OptionTextEffectType.Shadow)
                {
                    Shadow effect = textObject.AddComponent <Shadow>();
                    effect.effectColor     = this.optionTextEffectColor;
                    effect.effectDistance  = this.optionTextEffectDistance;
                    effect.useGraphicAlpha = this.optionTextEffectUseGraphicAlpha;
                }
                else if (this.optionTextEffectType == OptionTextEffectType.Outline)
                {
                    Outline effect = textObject.AddComponent <Outline>();
                    effect.effectColor     = this.optionTextEffectColor;
                    effect.effectDistance  = this.optionTextEffectDistance;
                    effect.useGraphicAlpha = this.optionTextEffectUseGraphicAlpha;
                }
            }

            // Prepare the option hover overlay
            if (this.optionHoverOverlay != null)
            {
                GameObject hoverOverlayObj = new GameObject("Hover Overlay", typeof(RectTransform));
                hoverOverlayObj.layer = this.gameObject.layer;

                // Add layout element
                LayoutElement hoverLayoutElement = hoverOverlayObj.AddComponent <LayoutElement>();
                hoverLayoutElement.ignoreLayout = true;

                // Change parents
                hoverOverlayObj.transform.SetParent(optionObject.transform, false);
                hoverOverlayObj.transform.localScale = new Vector3(1f, 1f, 1f);

                // Add image
                Image hoImage = hoverOverlayObj.AddComponent <Image>();
                hoImage.sprite = this.optionHoverOverlay;
                hoImage.type   = Image.Type.Sliced;

                // Apply pivot
                (hoverOverlayObj.transform as RectTransform).pivot = new Vector2(0f, 1f);

                // Apply anchors
                (hoverOverlayObj.transform as RectTransform).anchorMin = new Vector2(0f, 0f);
                (hoverOverlayObj.transform as RectTransform).anchorMax = new Vector2(1f, 1f);

                // Apply offsets
                (hoverOverlayObj.transform as RectTransform).offsetMin = new Vector2(0f, 0f);
                (hoverOverlayObj.transform as RectTransform).offsetMax = new Vector2(0f, 0f);

                // Add the highlight transition component
                UISelectField_OptionOverlay hoht = optionObject.AddComponent <UISelectField_OptionOverlay>();
                hoht.targetGraphic = hoImage;
                hoht.transition    = UISelectField_OptionOverlay.Transition.ColorTint;
                hoht.colorBlock    = this.optionHoverOverlayColorBlock;
                hoht.InternalEvaluateAndTransitionToNormalState(true);
            }

            // Prepare the option press overlay
            if (this.optionPressOverlay != null)
            {
                GameObject pressOverlayObj = new GameObject("Press Overlay", typeof(RectTransform));
                pressOverlayObj.layer = this.gameObject.layer;

                // Add layout element
                LayoutElement pressLayoutElement = pressOverlayObj.AddComponent <LayoutElement>();
                pressLayoutElement.ignoreLayout = true;

                // Change parents
                pressOverlayObj.transform.SetParent(optionObject.transform, false);
                pressOverlayObj.transform.localScale = new Vector3(1f, 1f, 1f);

                // Add image
                Image poImage = pressOverlayObj.AddComponent <Image>();
                poImage.sprite = this.optionPressOverlay;
                poImage.type   = Image.Type.Sliced;

                // Apply pivot
                (pressOverlayObj.transform as RectTransform).pivot = new Vector2(0f, 1f);

                // Apply anchors
                (pressOverlayObj.transform as RectTransform).anchorMin = new Vector2(0f, 0f);
                (pressOverlayObj.transform as RectTransform).anchorMax = new Vector2(1f, 1f);

                // Apply offsets
                (pressOverlayObj.transform as RectTransform).offsetMin = new Vector2(0f, 0f);
                (pressOverlayObj.transform as RectTransform).offsetMax = new Vector2(0f, 0f);

                // Add the highlight transition component
                UISelectField_OptionOverlay poht = optionObject.AddComponent <UISelectField_OptionOverlay>();
                poht.targetGraphic = poImage;
                poht.transition    = UISelectField_OptionOverlay.Transition.ColorTint;
                poht.colorBlock    = this.optionPressOverlayColorBlock;
                poht.InternalEvaluateAndTransitionToNormalState(true);
            }

            // Initialize the option component
            optionComp.Initialize(this, text);

            // Set active if it's the selected one
            if (index == this.selectedOptionIndex)
            {
                optionComp.isOn = true;
            }

            // Register to the toggle group
            if (toggleGroup != null)
            {
                optionComp.group = toggleGroup;
            }

            // Hook some events
            optionComp.onSelectOption.AddListener(OnOptionSelect);
            optionComp.onPointerUp.AddListener(OnOptionPointerUp);

            // Add it to the list
            if (this.m_OptionObjects != null)
            {
                this.m_OptionObjects.Add(optionComp);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Creates new line column object.
        /// </summary>
        /// <param name="parent">Parent.</param>
        /// <param name="content">Content.</param>
        /// <param name="isLeft">If set to <c>true</c> is left.</param>
        /// <param name="style">The style.</param>
        private void CreateLineColumn(Transform parent, string content, bool isLeft, UITooltipLines.LineStyle style)
        {
            // Create the game object
            GameObject obj = new GameObject("Column", typeof(RectTransform), typeof(CanvasRenderer));

            obj.layer = this.gameObject.layer;
            obj.transform.SetParent(parent);

            // Set the pivot to top left
            (obj.transform as RectTransform).pivot = new Vector2(0f, 1f);

            // Set a fixed size for attribute columns
            if (style == UITooltipLines.LineStyle.Attribute)
            {
                VerticalLayoutGroup   vlg  = this.gameObject.GetComponent <VerticalLayoutGroup>();
                HorizontalLayoutGroup phlg = parent.gameObject.GetComponent <HorizontalLayoutGroup>();
                LayoutElement         le   = obj.AddComponent <LayoutElement>();
                le.preferredWidth = (this.m_Rect.sizeDelta.x - vlg.padding.horizontal - phlg.padding.horizontal) / 2f;
            }

            // Prepare the text component
            Text text = obj.AddComponent <Text>();

            text.text            = content;
            text.supportRichText = true;
            text.alignment       = (isLeft) ? TextAnchor.LowerLeft : TextAnchor.LowerRight;

            // Prepare some style properties
            TextEffectType effect         = TextEffectType.None;
            Color          effectColor    = Color.white;
            Vector2        effectDistance = new Vector2(1f, -1f);
            bool           effectUseAlpha = true;

            switch (style)
            {
            case UITooltipLines.LineStyle.Title:
                text.font        = this.m_TitleFont;
                text.fontStyle   = this.m_TitleFontStyle;
                text.fontSize    = this.m_TitleFontSize;
                text.lineSpacing = this.m_TitleFontLineSpacing;
                text.color       = this.m_TitleFontColor;
                effect           = this.m_TitleTextEffect;
                effectColor      = this.m_TitleTextEffectColor;
                effectDistance   = this.m_TitleTextEffectDistance;
                effectUseAlpha   = this.m_TitleTextEffectUseGraphicAlpha;
                break;

            case UITooltipLines.LineStyle.Attribute:
                text.font        = this.m_AttributeFont;
                text.fontStyle   = this.m_AttributeFontStyle;
                text.fontSize    = this.m_AttributeFontSize;
                text.lineSpacing = this.m_AttributeFontLineSpacing;
                text.color       = this.m_AttributeFontColor;
                effect           = this.m_AttributeTextEffect;
                effectColor      = this.m_AttributeTextEffectColor;
                effectDistance   = this.m_AttributeTextEffectDistance;
                effectUseAlpha   = this.m_AttributeTextEffectUseGraphicAlpha;
                break;

            case UITooltipLines.LineStyle.Description:
                text.font        = this.m_DescriptionFont;
                text.fontStyle   = this.m_DescriptionFontStyle;
                text.fontSize    = this.m_DescriptionFontSize;
                text.lineSpacing = this.m_DescriptionFontLineSpacing;
                text.color       = this.m_DescriptionFontColor;
                effect           = this.m_DescriptionTextEffect;
                effectColor      = this.m_DescriptionTextEffectColor;
                effectDistance   = this.m_DescriptionTextEffectDistance;
                effectUseAlpha   = this.m_DescriptionTextEffectUseGraphicAlpha;
                break;
            }

            // Add text effect component
            if (effect == TextEffectType.Shadow)
            {
                Shadow s = obj.AddComponent <Shadow>();
                s.effectColor     = effectColor;
                s.effectDistance  = effectDistance;
                s.useGraphicAlpha = effectUseAlpha;
            }
            else if (effect == TextEffectType.Outline)
            {
                Outline o = obj.AddComponent <Outline>();
                o.effectColor     = effectColor;
                o.effectDistance  = effectDistance;
                o.useGraphicAlpha = effectUseAlpha;
            }
        }
        /// <summary>
        /// Creates the list and it's options.
        /// </summary>
        protected void CreateList()
        {
            // 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));

            // 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>();

            // 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.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.zero;
            rect.pivot     = new Vector2(0f, 1f);

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

            // Prepare the width of the list
            rect.sizeDelta = new Vector2((this.targetGraphic.rectTransform.sizeDelta.x - (this.listMargins.left + this.listMargins.right)), 0f);

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