52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class UIShuttleBox : MonoBehaviour
|
|
{
|
|
public List<Toggle> leftToggles; // 左侧切换按钮数组
|
|
public List<Toggle> rightToggles; // 右侧切换按钮数组
|
|
|
|
|
|
[ContextMenu("移动到右侧面板")]
|
|
public void MoveToRight()
|
|
{
|
|
foreach (Toggle toggle in leftToggles)
|
|
{
|
|
if (toggle.isOn)
|
|
{
|
|
toggle.transform.SetParent(transform.Find("RightPanel")); // 将选中的切换按钮移动到右侧面板
|
|
}
|
|
}
|
|
|
|
updateBox();
|
|
}
|
|
|
|
[ContextMenu("移动到左侧面板")]
|
|
public void MoveToLeft()
|
|
{
|
|
foreach (Toggle toggle in rightToggles)
|
|
{
|
|
if (toggle.isOn)
|
|
{
|
|
toggle.transform.SetParent(transform.Find("LeftPanel")); // 将选中的切换按钮移动到左侧面板
|
|
}
|
|
}
|
|
|
|
updateBox();
|
|
}
|
|
|
|
|
|
|
|
public void updateBox()
|
|
{
|
|
leftToggles.Clear();
|
|
rightToggles.Clear();
|
|
|
|
leftToggles = transform.Find("LeftPanel").GetComponentsInChildren<Toggle>().ToList();
|
|
rightToggles = transform.Find("RightPanel").GetComponentsInChildren<Toggle>().ToList();
|
|
}
|
|
|
|
}
|