ugui General Manager tab.

It has been a sore point, this time to solve, ugui common

the using the System.Collections;
 the using the System.Collections.Generic;
 the using the System.Linq;
 the using UnityEngine; 

///  <Summary> 
/// the UGUI tab manager
 ///  
/// manager hung UITabManager
 /// tab button hung UITabButton
 /// tab content script ITabContent hung inherited interface
 /// attention panel assigned
 ///  </ the Summary> 
public  class UITabManager: MonoBehaviour 
{ 
    // tab button list 
    public list <UITabButton> tabButtonList;
     // tab list 
    Private list <GameObject> tabContentList = new new List<GameObject>();
    //当前页签
    private GameObject curContentObj;

    // Start is called before the first frame update
    void Start()
    {
        foreach (var one in tabButtonList)
        {
            tabContentList.Add(one.tabContent);
            //默认打开第一个
            if (tabContentList.Count == 1)
            {
                curContentObj = one.tabContent;
                OpenCurTabContent();
            }
            else
            {
                one.tabContent.SetActive(to false ); 
            } 
            one.btn.onClick.AddListener (() => 
            { 
                // avoid repetitive clicks 
                IF (curContentObj =! one.tabContent) 
                { 
                    curContentObj.GetComponent <ITabContent> () .CloseTabContent (); 
                    curContentObj = one.tabContent ; 
                    OpenCurTabContent (); 
                } 
            }); 
        } 
    } 

    // the Update IS Called Once per Frame 
    void the Update () 
    { 
        
    } 

    // open this page tab 
    public  void OpenCurTabContent () 
    { 
        IF (curContentObj =! Null ) 
        { 
            Print (curContentObj.name); 
            curContentObj.GetComponent <ITabContent> () .OpenTabContent ();     
        } 
    } 
}

Mount button, and drag up UITabManager of tabButtonList

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UITabButton : MonoBehaviour
{
    public Button btn;
    public GameObject tabContent;
    
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

interface

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface ITabContent
{
    void OpenTabContent();
    void CloseTabContent();
}

 

Guess you like

Origin www.cnblogs.com/sanyejun/p/12398296.html