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
 protected void RecycleElement(UIListElementScript elementScript, bool disableElement)
 {
     if (disableElement)
     {
         elementScript.Disable();
     }
     m_elementScripts.Remove(elementScript);
     m_unUsedElementScripts.Add(elementScript);
 }
Ejemplo n.º 3
0
 protected void RecycleElement(bool disableElement)
 {
     while (m_elementScripts.Count > 0)
     {
         UIListElementScript uiListElementScript = m_elementScripts[0];
         m_elementScripts.RemoveAt(0);
         if (disableElement)
         {
             uiListElementScript.Disable();
         }
         m_unUsedElementScripts.Add(uiListElementScript);
     }
 }
Ejemplo n.º 4
0
 public override void SelectElement(int index, bool isDispatchSelectedChangeEvent = true)
 {
     if (isMultiSelected)
     {
         bool flag = m_multiSelected[index];
         flag = !flag;
         m_multiSelected[index] = flag;
         UIListElementScript elemenet = base.GetElemenet(index);
         if (elemenet != null)
         {
             elemenet.ChangeDisplay(flag);
         }
         DispatchElementSelectChangedEvent();
     }
     else
     {
         if (index == m_selected)
         {
             if (alwaysDispatchSelectedChangeEvent)
             {
                 DispatchElementSelectChangedEvent();
             }
             return;
         }
         if (m_selected >= 0)
         {
             UIListElementScript elemenet2 = base.GetElemenet(m_selected);
             if (elemenet2 != null)
             {
                 elemenet2.ChangeDisplay(false);
             }
         }
         m_selected = index;
         if (m_selected >= 0)
         {
             UIListElementScript elemenet3 = base.GetElemenet(m_selected);
             if (elemenet3 != null)
             {
                 elemenet3.ChangeDisplay(true);
             }
         }
         DispatchElementSelectChangedEvent();
     }
 }
Ejemplo n.º 5
0
 public virtual void SelectElement(int index, bool isDispatchSelectedChangeEvent = true)
 {
     m_lastSelectedElementIndex = m_selectedElementIndex;
     m_selectedElementIndex     = index;
     if (m_lastSelectedElementIndex == m_selectedElementIndex)
     {
         if (alwaysDispatchSelectedChangeEvent && isDispatchSelectedChangeEvent)
         {
             DispatchElementSelectChangedEvent();
         }
         return;
     }
     if (m_lastSelectedElementIndex >= 0)
     {
         UIListElementScript elemenet = GetElemenet(m_lastSelectedElementIndex);
         if (elemenet != null)
         {
             elemenet.ChangeDisplay(false);
         }
     }
     if (m_selectedElementIndex >= 0)
     {
         UIListElementScript elemenet2 = GetElemenet(m_selectedElementIndex);
         if (elemenet2 != null)
         {
             elemenet2.ChangeDisplay(true);
             if (elemenet2.onSelected != null)
             {
                 elemenet2.onSelected();
             }
         }
     }
     if (isDispatchSelectedChangeEvent)
     {
         DispatchElementSelectChangedEvent();
     }
 }
Ejemplo n.º 6
0
    protected UIListElementScript CreateElement(int index, ref stRect rect)
    {
        UIListElementScript uiListElementScript = null;

        if (m_unUsedElementScripts.Count > 0)
        {
            uiListElementScript = m_unUsedElementScripts[0];
            m_unUsedElementScripts.RemoveAt(0);
        }
        else if (m_elementTemplate != null)
        {
            GameObject gameObject1 = GameObject.Instantiate(m_elementTemplate);
            gameObject1.transform.SetParent(m_content.transform);
            gameObject1.transform.localScale = Vector3.one;
            base.InitializeComponent(gameObject1);
            uiListElementScript = gameObject1.GetComponent <UIListElementScript>();
        }
        if (uiListElementScript != null)
        {
            uiListElementScript.Enable(this, index, m_elementName, ref rect, IsSelectedIndex(index));
            m_elementScripts.Add(uiListElementScript);
        }
        return(uiListElementScript);
    }
Ejemplo n.º 7
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);
        }
    }