制作新UI
This commit is contained in:
89
Assets/Scripts/UI/Common/Menu/MainMenu.cs
Normal file
89
Assets/Scripts/UI/Common/Menu/MainMenu.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class MainMenu : GComponent
|
||||
{
|
||||
public event Action<int> OnTabChange;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
List.onClickItem.Add(OnClickItem);
|
||||
}
|
||||
|
||||
private string _leftActionName;
|
||||
private string _rightActionName;
|
||||
|
||||
public void SetBtnActionName(string leftActionName, string rightActionName)
|
||||
{
|
||||
_leftActionName = leftActionName;
|
||||
_rightActionName = rightActionName;
|
||||
BtnPrev.SetData(leftActionName, string.Empty);
|
||||
BtnNext.SetData(rightActionName, string.Empty);
|
||||
}
|
||||
|
||||
public void SetTabs(List<TabItemData> tabList, int selectIndex = 0)
|
||||
{
|
||||
SetBtnActionName(InputDef.UI.Prev, InputDef.UI.Next);
|
||||
List.RemoveChildrenToPool();
|
||||
var listWidth = 0f;
|
||||
for (int i = 0; i < tabList.Count; i++)
|
||||
{
|
||||
var tabData = tabList[i];
|
||||
var tabItem = List.AddItemFromPool().asButton;
|
||||
tabItem.SetLanguage(tabData.Key);
|
||||
|
||||
listWidth += tabItem.width;
|
||||
if (i > 0)
|
||||
{
|
||||
listWidth += List.columnGap;
|
||||
}
|
||||
}
|
||||
|
||||
Log.Info($"Set tab index={List.selectedIndex}");
|
||||
List.selectedIndex = selectIndex;
|
||||
List.width = listWidth;
|
||||
OnClickItem();
|
||||
}
|
||||
|
||||
|
||||
private void OnClickItem()
|
||||
{
|
||||
OnTabChange?.Invoke(List.selectedIndex);
|
||||
}
|
||||
|
||||
public void OnClickBtnPrev()
|
||||
{
|
||||
if (List.selectedIndex > 0)
|
||||
{
|
||||
List.selectedIndex -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
List.selectedIndex = List.numItems - 1;
|
||||
}
|
||||
|
||||
OnClickItem();
|
||||
}
|
||||
|
||||
public void OnClickBtnNext()
|
||||
{
|
||||
if (List.selectedIndex < List.numItems - 1)
|
||||
{
|
||||
List.selectedIndex += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
List.selectedIndex = 0;
|
||||
}
|
||||
|
||||
OnClickItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user