Exemplo n.º 1
0
        public void SetExternalElementPrefab(string externalElmtPrefPath)
        {
            CUIListElementScript cUIListElementScript = null;
            GameObject           gameObject           = null;

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

                if (gameObject != null)
                {
                    cUIListElementScript = gameObject.GetComponent <CUIListElementScript>();
                }
            }
            if (cUIListElementScript != null && gameObject != null)
            {
                cUIListElementScript.Initialize(this.m_belongedFormScript);
                this.m_elementTemplate    = gameObject;
                this.m_elementName        = gameObject.name;
                this.m_elementDefaultSize = cUIListElementScript.m_defaultSize;
            }
            if (this.m_elementTemplate != null)
            {
                this.SetElementAmount(this.m_elementAmount);
            }
        }
Exemplo n.º 2
0
        public override void Initialize(CUIFormScript formScript)
        {
            if (this.m_isInitialized)
            {
                return;
            }
            base.Initialize(formScript);
            this.m_selectedElementIndex     = -1;
            this.m_lastSelectedElementIndex = -1;
            this.m_scrollRect = base.GetComponentInChildren <ScrollRect>(base.gameObject);
            if (this.m_scrollRect != null)
            {
                this.m_scrollRect.enabled = false;
                RectTransform rectTransform = this.m_scrollRect.transform as RectTransform;
                this.m_scrollAreaSize = new Vector2(rectTransform.rect.width, rectTransform.rect.height);
                this.m_content        = this.m_scrollRect.get_content().gameObject;
            }
            this.m_scrollBar = base.GetComponentInChildren <Scrollbar>(base.gameObject);
            if (this.m_listType == enUIListType.Vertical || this.m_listType == enUIListType.VerticalGrid)
            {
                if (this.m_scrollBar != null)
                {
                    this.m_scrollBar.set_direction(2);
                }
                DebugHelper.Assert(this.m_scrollRect != null);
                if (this.m_scrollRect != null)
                {
                    this.m_scrollRect.set_horizontal(false);
                    this.m_scrollRect.set_vertical(true);
                    this.m_scrollRect.set_horizontalScrollbar(null);
                    this.m_scrollRect.set_verticalScrollbar(this.m_scrollBar);
                }
            }
            else if (this.m_listType == enUIListType.Horizontal || this.m_listType == enUIListType.HorizontalGrid)
            {
                if (this.m_scrollBar != null)
                {
                    this.m_scrollBar.set_direction(0);
                }
                DebugHelper.Assert(this.m_scrollRect != null);
                if (this.m_scrollRect != null)
                {
                    this.m_scrollRect.set_horizontal(true);
                    this.m_scrollRect.set_vertical(false);
                    this.m_scrollRect.set_horizontalScrollbar(this.m_scrollBar);
                    this.m_scrollRect.set_verticalScrollbar(null);
                }
            }
            this.m_elementScripts       = new ListView <CUIListElementScript>();
            this.m_unUsedElementScripts = new ListView <CUIListElementScript>();
            if (this.m_useOptimized && this.m_elementsRect == null)
            {
                this.m_elementsRect = new List <stRect>();
            }
            CUIListElementScript cUIListElementScript = null;

            if (this.m_useExternalElement)
            {
                GameObject gameObject = null;
                if (this.m_externalElementPrefabPath != null)
                {
                    gameObject = (GameObject)Singleton <CResourceManager> .GetInstance().GetResource(this.m_externalElementPrefabPath, typeof(GameObject), enResourceType.UIPrefab, false, false).m_content;

                    if (gameObject != null)
                    {
                        cUIListElementScript = gameObject.GetComponent <CUIListElementScript>();
                    }
                }
                if (cUIListElementScript != null && gameObject != null)
                {
                    cUIListElementScript.Initialize(formScript);
                    this.m_elementTemplate    = gameObject;
                    this.m_elementName        = gameObject.name;
                    this.m_elementDefaultSize = cUIListElementScript.m_defaultSize;
                }
            }
            else
            {
                cUIListElementScript = base.GetComponentInChildren <CUIListElementScript>(base.gameObject);
                if (cUIListElementScript != null)
                {
                    cUIListElementScript.Initialize(formScript);
                    this.m_elementTemplate    = cUIListElementScript.gameObject;
                    this.m_elementName        = cUIListElementScript.gameObject.name;
                    this.m_elementDefaultSize = cUIListElementScript.m_defaultSize;
                    if (this.m_elementTemplate != null)
                    {
                        this.m_elementTemplate.name = this.m_elementName + "_Template";
                    }
                }
            }
            if (this.m_elementTemplate != null)
            {
                CUIListElementScript component = this.m_elementTemplate.GetComponent <CUIListElementScript>();
                if (component != null && component.m_useSetActiveForDisplay)
                {
                    this.m_elementTemplate.CustomSetActive(false);
                }
                else
                {
                    if (!this.m_elementTemplate.activeSelf)
                    {
                        this.m_elementTemplate.SetActive(true);
                    }
                    CanvasGroup canvasGroup = this.m_elementTemplate.GetComponent <CanvasGroup>();
                    if (canvasGroup == null)
                    {
                        canvasGroup = this.m_elementTemplate.AddComponent <CanvasGroup>();
                    }
                    canvasGroup.alpha          = 0f;
                    canvasGroup.blocksRaycasts = false;
                }
            }
            if (this.m_content != null)
            {
                this.m_contentRectTransform                  = (this.m_content.transform as RectTransform);
                this.m_contentRectTransform.pivot            = new Vector2(0f, 1f);
                this.m_contentRectTransform.anchorMin        = new Vector2(0f, 1f);
                this.m_contentRectTransform.anchorMax        = new Vector2(0f, 1f);
                this.m_contentRectTransform.anchoredPosition = Vector2.zero;
                this.m_contentRectTransform.localRotation    = Quaternion.identity;
                this.m_contentRectTransform.localScale       = new Vector3(1f, 1f, 1f);
                this.m_lastContentPosition = this.m_contentRectTransform.anchoredPosition;
            }
            if (this.m_extraContent != null)
            {
                RectTransform rectTransform2 = this.m_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 (this.m_elementTemplate != null)
                {
                    rectTransform2.sizeDelta = new Vector2((this.m_elementTemplate.transform as RectTransform).rect.width, rectTransform2.sizeDelta.y);
                }
                if (rectTransform2.parent != null && this.m_content != null)
                {
                    rectTransform2.parent.SetParent(this.m_content.transform);
                }
                this.m_extraContent.SetActive(false);
            }
            this.m_isExtraContentEnabled = true;
            if (this.m_elementTemplate != null)
            {
                this.SetElementAmount(this.m_elementAmount);
            }
        }
Exemplo n.º 3
0
        public override void Initialize(CUIFormScript formScript)
        {
            if (!base.m_isInitialized)
            {
                base.Initialize(formScript);
                this.m_selectedElementIndex     = -1;
                this.m_lastSelectedElementIndex = -1;
                this.m_scrollRect = base.GetComponentInChildren <ScrollRect>(base.gameObject);
                if (this.m_scrollRect != null)
                {
                    this.m_scrollRect.enabled = false;
                    RectTransform transform = this.m_scrollRect.transform as RectTransform;
                    this.m_scrollAreaSize = new Vector2(transform.rect.width, transform.rect.height);
                    this.m_content        = this.m_scrollRect.content.gameObject;
                }
                this.m_scrollBar = base.GetComponentInChildren <Scrollbar>(base.gameObject);
                if ((this.m_listType == enUIListType.Vertical) || (this.m_listType == enUIListType.VerticalGrid))
                {
                    if (this.m_scrollBar != null)
                    {
                        this.m_scrollBar.direction = Scrollbar.Direction.BottomToTop;
                    }
                    DebugHelper.Assert(this.m_scrollRect != null);
                    if (this.m_scrollRect != null)
                    {
                        this.m_scrollRect.horizontal          = false;
                        this.m_scrollRect.vertical            = true;
                        this.m_scrollRect.horizontalScrollbar = null;
                        this.m_scrollRect.verticalScrollbar   = this.m_scrollBar;
                    }
                }
                else if ((this.m_listType == enUIListType.Horizontal) || (this.m_listType == enUIListType.HorizontalGrid))
                {
                    if (this.m_scrollBar != null)
                    {
                        this.m_scrollBar.direction = Scrollbar.Direction.LeftToRight;
                    }
                    DebugHelper.Assert(this.m_scrollRect != null);
                    if (this.m_scrollRect != null)
                    {
                        this.m_scrollRect.horizontal          = true;
                        this.m_scrollRect.vertical            = false;
                        this.m_scrollRect.horizontalScrollbar = this.m_scrollBar;
                        this.m_scrollRect.verticalScrollbar   = null;
                    }
                }
                this.m_elementScripts       = new ListView <CUIListElementScript>();
                this.m_unUsedElementScripts = new ListView <CUIListElementScript>();
                if (this.m_useOptimized)
                {
                    this.m_elementsRect = new List <stRect>();
                }
                CUIListElementScript component = null;
                if (this.m_useExternalElement)
                {
                    GameObject content = (GameObject)Singleton <CResourceManager> .GetInstance().GetResource(this.m_externalElementPrefabPath, typeof(GameObject), enResourceType.UIPrefab, false, false).m_content;

                    component = content.GetComponent <CUIListElementScript>();
                    if (component != null)
                    {
                        component.Initialize(formScript);
                        this.m_elementTemplate    = content;
                        this.m_elementName        = content.name;
                        this.m_elementDefaultSize = component.m_defaultSize;
                    }
                }
                else
                {
                    component = base.GetComponentInChildren <CUIListElementScript>(base.gameObject);
                    if (component != null)
                    {
                        component.Initialize(formScript);
                        this.m_elementTemplate    = component.gameObject;
                        this.m_elementName        = component.gameObject.name;
                        this.m_elementDefaultSize = component.m_defaultSize;
                        if (this.m_elementTemplate != null)
                        {
                            this.m_elementTemplate.name = this.m_elementName + "_Template";
                        }
                    }
                }
                if (this.m_elementTemplate != null)
                {
                    CUIListElementScript script2 = this.m_elementTemplate.GetComponent <CUIListElementScript>();
                    if ((script2 != null) && script2.m_useSetActiveForDisplay)
                    {
                        this.m_elementTemplate.CustomSetActive(false);
                    }
                    else
                    {
                        if (!this.m_elementTemplate.activeSelf)
                        {
                            this.m_elementTemplate.SetActive(true);
                        }
                        CanvasGroup group = this.m_elementTemplate.GetComponent <CanvasGroup>();
                        if (group == null)
                        {
                            group = this.m_elementTemplate.AddComponent <CanvasGroup>();
                        }
                        group.alpha          = 0f;
                        group.blocksRaycasts = false;
                    }
                }
                if (this.m_content != null)
                {
                    this.m_contentRectTransform                  = this.m_content.transform as RectTransform;
                    this.m_contentRectTransform.pivot            = new Vector2(0f, 1f);
                    this.m_contentRectTransform.anchorMin        = new Vector2(0f, 1f);
                    this.m_contentRectTransform.anchorMax        = new Vector2(0f, 1f);
                    this.m_contentRectTransform.anchoredPosition = Vector2.zero;
                    this.m_contentRectTransform.localRotation    = Quaternion.identity;
                    this.m_contentRectTransform.localScale       = new Vector3(1f, 1f, 1f);
                    this.m_lastContentPosition = this.m_contentRectTransform.anchoredPosition;
                }
                if (this.m_extraContent != null)
                {
                    RectTransform transform2 = this.m_extraContent.transform as RectTransform;
                    transform2.pivot            = new Vector2(0f, 1f);
                    transform2.anchorMin        = new Vector2(0f, 1f);
                    transform2.anchorMax        = new Vector2(0f, 1f);
                    transform2.anchoredPosition = Vector2.zero;
                    transform2.localRotation    = Quaternion.identity;
                    transform2.localScale       = Vector3.one;
                    if (this.m_elementTemplate != null)
                    {
                        transform2.sizeDelta = new Vector2((this.m_elementTemplate.transform as RectTransform).rect.width, transform2.sizeDelta.y);
                    }
                    if ((transform2.parent != null) && (this.m_content != null))
                    {
                        transform2.parent.SetParent(this.m_content.transform);
                    }
                    this.m_extraContent.SetActive(false);
                }
                this.SetElementAmount(this.m_elementAmount);
            }
        }