Ejemplo n.º 1
0
    public void SetExternalElementPrefab(string externalElmtPrefPath)
    {
        UIListElementScript uiListElementScript = null;
        GameObject          gameObject          = null;

        if (externalElmtPrefPath != null)
        {
            gameObject = (GameObject)Singleton <ResourceManager> .GetInstance().GetResource(externalElmtPrefPath, typeof(GameObject), enResourceType.UIPrefab, false, false).content;

            if (gameObject != null)
            {
                uiListElementScript = gameObject.GetComponent <UIListElementScript>();
            }
        }
        if (uiListElementScript != null && gameObject != null)
        {
            uiListElementScript.Initialize(belongedFormScript);
            m_elementTemplate    = gameObject;
            m_elementName        = gameObject.name;
            m_elementDefaultSize = uiListElementScript.m_defaultSize;
        }
        if (m_elementTemplate != null)
        {
            SetElementAmount(elementAmount);
        }
    }
Ejemplo n.º 2
0
    public override void Initialize(UIFormScript formScript)
    {
        if (m_isInitialized)
        {
            return;
        }
        base.Initialize(formScript);
        m_selectedElementIndex     = -1;
        m_lastSelectedElementIndex = -1;
        scrollRect = GetComponentInChildren <ScrollRect>(gameObject);
        if (scrollRect != null)
        {
            scrollRect.enabled = false;
            RectTransform rectTransform = scrollRect.transform as RectTransform;
            scrollAreaSize = new Vector2(rectTransform.rect.width, rectTransform.rect.height);
            m_content      = scrollRect.content.gameObject;
        }
        m_scrollBar = base.GetComponentInChildren <Scrollbar>(gameObject);
        if (listType == enUIListType.Vertical || listType == enUIListType.VerticalGrid)
        {
            if (m_scrollBar != null)
            {
                m_scrollBar.direction = Scrollbar.Direction.BottomToTop;
            }
            // DebugHelper.Assert(scrollRect != null);
            if (scrollRect != null)
            {
                scrollRect.horizontal          = false;
                scrollRect.vertical            = true;
                scrollRect.horizontalScrollbar = null;
                scrollRect.verticalScrollbar   = m_scrollBar;
            }
        }
        else if (listType == enUIListType.Horizontal || listType == enUIListType.HorizontalGrid)
        {
            if (m_scrollBar != null)
            {
                m_scrollBar.direction = Scrollbar.Direction.LeftToRight;
            }
            //    DebugHelper.Assert(scrollRect != null);
            if (scrollRect != null)
            {
                scrollRect.horizontal          = true;
                scrollRect.vertical            = false;
                scrollRect.horizontalScrollbar = m_scrollBar;
                scrollRect.verticalScrollbar   = null;
            }
        }
        m_elementScripts       = new List <UIListElementScript>();
        m_unUsedElementScripts = new List <UIListElementScript>();
        if (useOptimized && m_elementsRect == null)
        {
            m_elementsRect = new List <stRect>();
        }
        UIListElementScript uiListElementScript = null;

        if (useExternalElement)
        {
            GameObject gameObject1 = null;
            if (externalElementPrefabPath != null)
            {
                gameObject1 = (GameObject)Singleton <ResourceManager> .GetInstance().GetResource(externalElementPrefabPath, typeof(GameObject), enResourceType.UIPrefab, false, false).content;

                if (gameObject1 != null)
                {
                    uiListElementScript = gameObject1.GetComponent <UIListElementScript>();
                }
            }
            if (uiListElementScript != null && gameObject1 != null)
            {
                uiListElementScript.Initialize(formScript);
                m_elementTemplate    = gameObject1;
                m_elementName        = gameObject1.name;
                m_elementDefaultSize = uiListElementScript.m_defaultSize;
            }
        }
        else
        {
            uiListElementScript = GetComponentInChildren <UIListElementScript>(gameObject);
            if (uiListElementScript != null)
            {
                uiListElementScript.Initialize(formScript);
                m_elementTemplate    = uiListElementScript.gameObject;
                m_elementName        = uiListElementScript.gameObject.name;
                m_elementDefaultSize = uiListElementScript.m_defaultSize;
                if (m_elementTemplate != null)
                {
                    m_elementTemplate.name = m_elementName + "_Template";
                }
            }
        }
        if (m_elementTemplate != null)
        {
            UIListElementScript component = m_elementTemplate.GetComponent <UIListElementScript>();
            if (component != null && component.m_useSetActiveForDisplay)
            {
                m_elementTemplate.SetActive(false);
            }
            else
            {
                if (!m_elementTemplate.activeSelf)
                {
                    m_elementTemplate.SetActive(true);
                }
                CanvasGroup canvasGroup = m_elementTemplate.GetComponent <CanvasGroup>();
                if (canvasGroup == null)
                {
                    canvasGroup = m_elementTemplate.AddComponent <CanvasGroup>();
                }
                canvasGroup.alpha          = 0f;
                canvasGroup.blocksRaycasts = false;
            }
        }
        if (m_content != null)
        {
            m_contentRectTransform                  = (m_content.transform as RectTransform);
            m_contentRectTransform.pivot            = new Vector2(0f, 1f);
            m_contentRectTransform.anchorMin        = new Vector2(0f, 1f);
            m_contentRectTransform.anchorMax        = new Vector2(0f, 1f);
            m_contentRectTransform.anchoredPosition = Vector2.zero;
            m_contentRectTransform.localRotation    = Quaternion.identity;
            m_contentRectTransform.localScale       = new Vector3(1f, 1f, 1f);
            m_lastContentPosition = m_contentRectTransform.anchoredPosition;
        }
        if (extraContent != null)
        {
            RectTransform rectTransform2 = extraContent.transform as RectTransform;
            rectTransform2.pivot            = new Vector2(0f, 1f);
            rectTransform2.anchorMin        = new Vector2(0f, 1f);
            rectTransform2.anchorMax        = new Vector2(0f, 1f);
            rectTransform2.anchoredPosition = Vector2.zero;
            rectTransform2.localRotation    = Quaternion.identity;
            rectTransform2.localScale       = Vector3.one;
            if (m_elementTemplate != null)
            {
                rectTransform2.sizeDelta = new Vector2((m_elementTemplate.transform as RectTransform).rect.width, rectTransform2.sizeDelta.y);
            }
            if (rectTransform2.parent != null && m_content != null)
            {
                rectTransform2.parent.SetParent(m_content.transform);
            }
            extraContent.SetActive(false);
        }
        m_isExtraContentEnabled = true;
        if (m_elementTemplate != null)
        {
            SetElementAmount(elementAmount);
        }
    }