예제 #1
0
 /// <summary>
 /// 通过UI开启UI并关闭其他UI
 /// </summary>
 /// <param name="uiName"></param>
 public void OpenUIAndCloseOther(BaseUIComponent uiComponent, Action <BaseUIComponent> actionBeforeOpen = null, int layer = -1)
 {
     if (manager.uiList == null || uiComponent == null)
     {
         return;
     }
     for (int i = 0; i < manager.uiList.Count; i++)
     {
         BaseUIComponent itemUI = manager.uiList[i];
         if (!itemUI == uiComponent)
         {
             itemUI.CloseUI();
         }
     }
     for (int i = 0; i < manager.uiList.Count; i++)
     {
         BaseUIComponent itemUI = manager.uiList[i];
         if (itemUI == uiComponent)
         {
             //设置层级
             if (layer >= 0)
             {
                 itemUI.transform.SetSiblingIndex(layer);
             }
             actionBeforeOpen?.Invoke(itemUI);
             itemUI.OpenUI();
         }
     }
 }
예제 #2
0
    /// <summary>
    /// 通过UI的名字开启UI
    /// </summary>
    /// <param name="uiName"></param>
    public T OpenUI <T>(string uiName, Action <T> actionBeforeOpen = null, int layer = -1) where T : BaseUIComponent
    {
        if (uiName.IsNull())
        {
            return(null);
        }
        for (int i = 0; i < manager.uiList.Count; i++)
        {
            BaseUIComponent itemUI = manager.uiList[i];
            if (itemUI.name.Equals(uiName))
            {
                //设置层级
                if (layer >= 0)
                {
                    itemUI.transform.SetSiblingIndex(layer);
                }
                actionBeforeOpen?.Invoke(itemUI as T);
                itemUI.OpenUI();
                return(itemUI as T);
            }
        }
        T uiComponent = manager.CreateUI <T>(uiName, layer);

        if (uiComponent)
        {
            actionBeforeOpen?.Invoke(uiComponent as T);
            uiComponent.OpenUI();
            return(uiComponent);
        }
        return(null);
    }
예제 #3
0
    /// <summary>
    /// 通过UI的名字开启UI
    /// </summary>
    /// <param name="uiName"></param>
    public BaseUIComponent OpenUIByName(string uiName)
    {
        BaseUIComponent uiComponent = null;

        if (uiList == null || CheckUtil.StringIsNull(uiName))
        {
            return(uiComponent);
        }
        bool hasData = false;

        for (int i = 0; i < uiList.Count; i++)
        {
            BaseUIComponent itemUI = uiList[i];
            if (itemUI.name.Contains(uiName))
            {
                itemUI.OpenUI();
                hasData = true;
            }
        }
        if (!hasData)
        {
            BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData <BaseUIComponent>("UI/" + uiName);
            if (uiModel)
            {
                GameObject objUIComponent = Instantiate(objUIContainer, uiModel.gameObject);
                uiComponent = objUIComponent.GetComponent <BaseUIComponent>();
                uiList.Add(uiComponent);
            }
            else
            {
                LogUtil.LogError("没有找到指定UI:" + "Resources/UI/" + uiName);
            }
        }
        return(uiComponent);
    }
예제 #4
0
    /// <summary>
    /// 通过UI的名字开启UI
    /// </summary>
    /// <param name="uiName"></param>
    public T OpenUIByName <T>(string uiName) where T : BaseUIComponent
    {
        BaseUIComponent uiComponent = null;

        if (CheckUtil.StringIsNull(uiName))
        {
            return(uiComponent as T);
        }
        bool hasData = false;

        for (int i = 0; i < uiList.Count; i++)
        {
            BaseUIComponent itemUI = uiList[i];
            if (itemUI.name.Contains(uiName))
            {
                uiComponent = itemUI;
                itemUI.OpenUI();
                hasData = true;
            }
        }
        if (!hasData)
        {
            GameObject uiModel = LoadAssetUtil.SyncLoadAsset <GameObject>("ui/ui", uiName);
            //BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData<BaseUIComponent>("UI/"+ uiName);
            if (uiModel)
            {
                GameObject objUIComponent = Instantiate(gameObject, uiModel.gameObject);
                uiComponent = objUIComponent.GetComponent <BaseUIComponent>();
                uiComponent.OpenUI();
                uiList.Add(uiComponent);
            }
            else
            {
                LogUtil.LogError("没有找到指定UI:" + "ui/ui " + uiName);
            }
        }
        return(uiComponent as T);
    }
예제 #5
0
 /// <summary>
 /// 通过UI开启UI并关闭其他UI
 /// </summary>
 /// <param name="uiName"></param>
 public void OpenUIAndCloseOtherByName(BaseUIComponent uiComponent)
 {
     if (uiList == null || uiComponent == null)
     {
         return;
     }
     for (int i = 0; i < uiList.Count; i++)
     {
         BaseUIComponent itemUI = uiList[i];
         if (!itemUI == uiComponent)
         {
             itemUI.CloseUI();
         }
     }
     for (int i = 0; i < uiList.Count; i++)
     {
         BaseUIComponent itemUI = uiList[i];
         if (itemUI == uiComponent)
         {
             itemUI.OpenUI();
         }
     }
 }
예제 #6
0
    /// <summary>
    /// 通过UI的名字开启UI
    /// </summary>
    /// <param name="uiName"></param>
    public T OpenUIByName <T>(string uiName) where T : BaseUIComponent
    {
        if (CheckUtil.StringIsNull(uiName))
        {
            return(null);
        }
        for (int i = 0; i < uiList.Count; i++)
        {
            BaseUIComponent itemUI = uiList[i];
            if (itemUI.name.Equals(uiName))
            {
                itemUI.OpenUI();
                return(itemUI as T);
            }
        }
        T uiComponent = CreateUI <T>(uiName);

        if (uiComponent)
        {
            uiComponent.OpenUI();
            return(uiComponent);
        }
        return(null);
    }