using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// 队伍力量名称预设 /// public class TeamNameItem : MonoBehaviour { public Toggle TeamToggle; public Text TeamText; public static string TeamName; private void Awake() { TeamToggle = transform.Find("Toggle").GetComponent(); TeamToggle.group = transform.parent.GetComponent(); TeamText = transform.Find("Text").GetComponent(); TeamToggle.onValueChanged.AddListener(SelectTeamToggle); } public void SetTeamName(string Name) { TeamText.text = Name; } public void SelectTeamToggle(bool isOn) { var group = TeamToggle.GetComponent().group; if (group) {//因为是排他的选择框,只执行主动改值的事件 var anyIsOn = group.AnyTogglesOn(); if ((anyIsOn && isOn) || (!anyIsOn)) { if (isOn) { TeamName = GetTeamName(); } else { TeamName = string.Empty; } } } } public string GetTeamName() { return TeamText.text; } public void DestroyThis() { ResourceLoadWindow.Instance.LoadTipWindow("是否删除队伍名称?", OKDelFunc, null); } public void OKDelFunc() { TeamNameSetting.GetInstance.GetTeamNameList().Remove(GetTeamName()); Destroy(gameObject); } public void EditThis() { ResourceLoadWindow.Instance.LoadInputWindow("重新编辑", OKEditFunc, null, GetTeamName()); } public void OKEditFunc(string Name) { if (TeamNameSetting.GetInstance.CheckSameName(Name)) { ResourceLoadWindow.Instance.LoadTextHintWindow("已有相同名称", 0.5f); return; } TeamNameSetting.GetInstance.GetTeamNameList().Remove(GetTeamName()); SetTeamName(Name); TeamNameSetting.GetInstance.GetTeamNameList().Add(Name); if (TeamToggle.isOn) { TeamName = Name; GlobalVariable.TeamName = TeamName; } } }