Exemplo n.º 1
0
 /// <summary>
 /// 获取隐藏panel的宽或高
 /// </summary>
 private float HandleSelfFittingAlongAxis(int axis, GameObject obj)
 {
     //获取当前隐藏panel选择的适配模式
     ContentSizeFitter.FitMode fitting = (axis == 0 ? obj.GetComponent <ContentSizeFitter>().horizontalFit : obj.GetComponent <ContentSizeFitter>().verticalFit);
     if (fitting == ContentSizeFitter.FitMode.MinSize)
     {
         return(LayoutUtility.GetMinSize(obj.GetComponent <RectTransform>(), axis));
     }
     else if (fitting == ContentSizeFitter.FitMode.PreferredSize)
     {
         return(LayoutUtility.GetPreferredSize(obj.GetComponent <RectTransform>(), axis));
     }
     else
     {
         //如果是unconstrained的话直接获取当前的大小
         return(axis == 0 ? obj.GetComponent <RectTransform>().sizeDelta.x : obj.GetComponent <RectTransform>().sizeDelta.y);
     }
 }
Exemplo n.º 2
0
 private void HandleSelfFittingAlongAxis(int axis)
 {
     ContentSizeFitter.FitMode fitMode = (axis != 0) ? this.verticalFit : this.horizontalFit;
     if (fitMode == ContentSizeFitter.FitMode.Unconstrained)
     {
         this.m_Tracker.Add(this, this.rectTransform, DrivenTransformProperties.None);
     }
     else
     {
         this.m_Tracker.Add(this, this.rectTransform, (axis != 0) ? DrivenTransformProperties.SizeDeltaY : DrivenTransformProperties.SizeDeltaX);
         if (fitMode == ContentSizeFitter.FitMode.MinSize)
         {
             this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(this.m_Rect, axis));
         }
         else
         {
             this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(this.m_Rect, axis));
         }
     }
 }
 /// <summary>
 /// Sets the horizontal fit mode of the tooltip.
 /// </summary>
 /// <param name="mode">Mode.</param>
 protected void Internal_SetHorizontalFitMode(ContentSizeFitter.FitMode mode)
 {
     this.m_SizeFitter.horizontalFit = mode;
 }
Exemplo n.º 4
0
        public void AddContentSizeFitter(ContentSizeFitter.FitMode mode)
        {
            ContentSizeFitter fitter = GameObject.AddComponent <ContentSizeFitter>();

            fitter.horizontalFit = mode;
        }
Exemplo n.º 5
0
 public unsafe override void Load(FakeStruct fake)
 {
     m_HorizontalFit = (ContentSizeFitter.FitMode)fake[0];
     m_VerticalFit   = (ContentSizeFitter.FitMode)fake[1];
 }
Exemplo n.º 6
0
 public static void SetVerticalFit(this Graphic self, ContentSizeFitter.FitMode value)
 {
     self.GetComponent <ContentSizeFitter>().verticalFit = value;
 }
        private void Update()
        {
            Canvas.ForceUpdateCanvases();

            UpdateValidColumns();

            if (rectTransform.sizeDelta.x == 0f && rectTransform.anchorMin.x == rectTransform.anchorMax.x)
            {
                rectTransform.sizeDelta = new Vector2(200f, 100f);
            }
            HandleInputs();

            bool unconstrained = (validColumns.Count == 0 || validColumns.Any(c => c.autoWidth || c.useRelativeWidth));

            ContentSizeFitter.FitMode fitMode = unconstrained ? ContentSizeFitter.FitMode.Unconstrained : ContentSizeFitter.FitMode.PreferredSize;

            if (horizontal)
            {
                fitter.verticalFit = fitMode;
            }
            else
            {
                fitter.horizontalFit = fitMode;
            }

            UpdateState();

            UpdateColumnWidths();
            UpdateRowHeights();

            if (horizontal != (hGroup is VerticalLayoutGroup))
            {
                SetDirty();
                DestroyImmediate(hGroup);
                gameObject.AddComponent(horizontal ? typeof(VerticalLayoutGroup): typeof(HorizontalLayoutGroup));
                hGroup.childControlWidth = hGroup.childControlHeight = hGroup.childForceExpandWidth = hGroup.childForceExpandHeight = true;
                hGroup.spacing           = -1f;
            }

            if (currentState == State.Valid && transform.childCount != validColumns.Count() + (rowDeleteButtons ? 1 : 0))
            {
                SetDirty();
            }

            if (isDirty)
            {
                Debug.Log("Reinitialize");
                Initialize();
            }
            //else
            {
                if (updateCellContentAtRuntime || !Application.isPlaying)
                {
                    UpdateContent();
                }
                if (updateCellStyleAtRuntime || !Application.isPlaying)
                {
                    UpdateStyle();
                }
            }

            hGroup.spacing = spacing;
        }
Exemplo n.º 8
0
        public static DialogGUIContentSizer GUIContentSizer(ContentSizeFitter.FitMode widthMode, ContentSizeFitter.FitMode heightMode, Boolean useParentSize = false, Modifier <DialogGUIContentSizer> modifier = null)
        {
            DialogGUIContentSizer element = new DialogGUIContentSizer(widthMode, heightMode, useParentSize);

            if (modifier != null)
            {
                element = modifier(element);
            }
            _elements.Add(element);
            return(element);
        }
Exemplo n.º 9
0
 /// <summary>
 /// 设置自适应情况
 /// </summary>
 public void SetFit(ContentSizeFitter.FitMode Horizontal = ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode Vertical = ContentSizeFitter.FitMode.Unconstrained)
 {
     if (mContentFitter != null)
     {
         mContentFitter.horizontalFit = Horizontal;
         mContentFitter.verticalFit   = Vertical;
     }
 }