示例#1
0
    public static void CallBack(this ContentSizeFitter contentSizeFitter, System.Action <Vector2> change)
    {
        ContentSizeFitterEvent test = contentSizeFitter.GetComponent <ContentSizeFitterEvent>() ??
                                      contentSizeFitter.gameObject.AddComponent <ContentSizeFitterEvent>();

        test.change = change;
    }
        private void Create()
        {
            if (m_Database == null || m_Database.GetAllDataList() == null || m_Database.GetAllDataList().Count == 0)
            {
                Debug.LogWarning(GetType() + "/Create()/ data is null!");
                return;
            }

            for (int i = 0; i < m_Database.GetAllDataList().Count; i++)
            {
                TestIOCsvConfigData data = m_Database.GetAllDataList()[i];

                GameObject item = Instantiate(m_Prefab, m_Parent);
                item.SetActive(true);
                item.name = data.Id.ToString();

                item.transform.Find("Id").GetComponent <Text>().text    = data.Id.ToString();
                item.transform.Find("Name").GetComponent <Text>().text  = data.Name;
                item.transform.Find("Age").GetComponent <Text>().text   = data.Age.ToString();
                item.transform.Find("Score").GetComponent <Text>().text = data.Score.ToString();

                Text Designation = item.transform.Find("Designation").GetComponent <Text>();
                Designation.text = null;
                for (int j = 0; j < data.Designation.Length; j++)
                {
                    Designation.text += data.Designation[j] + ";";
                }
            }

            m_ContentSizeFitter.SetLayoutVertical();
            LayoutRebuilder.ForceRebuildLayoutImmediate(m_ContentSizeFitter.GetComponent <RectTransform>());
        }
示例#3
0
 /// <summary>
 /// 重新刷新所有item位置
 /// </summary>
 private void AgainRefreshItemPosition()
 {
     foreach (var item in this.itemList)
     {
         ContentSizeFitter fitter = item.GetComponentInChildren <ContentSizeFitter>(true);
         if (!fitter)
         {
             return;
         }
         RectTransform rect = fitter.GetComponent <RectTransform>();
         if (previousItemPosition == Vector3.zero)
         {
             previousItemPosition = item.RectTransform.anchoredPosition3D;
         }
         item.RectTransform.anchoredPosition3D = previousItemPosition;
         previousItemPosition = item.RectTransform.anchoredPosition3D - new Vector3(0, rect.rect.height + this.padding.y);
     }
     previousItemPosition = Vector3.zero;
 }
示例#4
0
        public void TestSetup()
        {
            m_PrefabRoot        = Object.Instantiate(Resources.Load("ContentSizeFitterTests")) as GameObject;
            m_ContentSizeFitter = m_PrefabRoot.GetComponentInChildren <ContentSizeFitter>();

            m_ContentSizeFitter.enabled = true;

            m_RectTransform           = m_ContentSizeFitter.GetComponent <RectTransform>();
            m_RectTransform.sizeDelta = new Vector2(50, 50);

            GameObject testObject = m_ContentSizeFitter.gameObject;
            // set up components
            var componentA = testObject.AddComponent <LayoutElement>();

            componentA.minWidth        = 5;
            componentA.minHeight       = 10;
            componentA.preferredWidth  = 100;
            componentA.preferredHeight = 105;
            componentA.flexibleWidth   = 0;
            componentA.flexibleHeight  = 0;
            componentA.enabled         = true;

            var componentB = testObject.AddComponent <LayoutElement>();

            componentB.minWidth        = 15;
            componentB.minHeight       = 20;
            componentB.preferredWidth  = 110;
            componentB.preferredHeight = 115;
            componentB.flexibleWidth   = 0;
            componentB.flexibleHeight  = 0;
            componentB.enabled         = true;

            var componentC = testObject.AddComponent <LayoutElement>();

            componentC.minWidth        = 25;
            componentC.minHeight       = 30;
            componentC.preferredWidth  = 120;
            componentC.preferredHeight = 125;
            componentC.flexibleWidth   = 0;
            componentC.flexibleHeight  = 0;
            componentC.enabled         = true;
        }
示例#5
0
        public void ScrollToBottom()
        {
            if (!m_consoleLogTextFitter || !m_gameLoggerTextFitter || !m_logListFitter)
            {
                return;
            }

            LayoutRebuilder.ForceRebuildLayoutImmediate(m_consoleLogTextFitter.GetComponent <RectTransform>());
            LayoutRebuilder.ForceRebuildLayoutImmediate(m_gameLoggerTextFitter.GetComponent <RectTransform>());
            LayoutRebuilder.ForceRebuildLayoutImmediate(m_logListFitter.GetComponent <RectTransform>());

            m_consoleLogTextFitter.enabled = false;
            m_logListFitter.enabled        = false;
            m_gameLoggerTextFitter.enabled = false;

            m_consoleLogTextFitter.enabled = true;
            m_logListFitter.enabled        = true;
            m_gameLoggerTextFitter.enabled = true;

            m_scrollRect.normalizedPosition = Vector2.zero;
        }
示例#6
0
 public void Awake()
 {
     sizeFitter   = GetComponentInChildren <ContentSizeFitter>();
     contentRectT = sizeFitter.GetComponent <RectTransform>();
     rectT        = GetComponent <RectTransform>();
 }