海淀天下城电子沙盘单机版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

4 years ago
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 队伍力量名称预设
/// </summary>
public class TeamNameItem : MonoBehaviour
{
public Toggle TeamToggle;
public Text TeamText;
public static string TeamName;
private void Awake()
{
TeamToggle = transform.Find("Toggle").GetComponent<Toggle>();
TeamToggle.group = transform.parent.GetComponent<ToggleGroup>();
TeamText = transform.Find("Text").GetComponent<Text>();
TeamToggle.onValueChanged.AddListener(SelectTeamToggle);
}
public void SetTeamName(string Name)
{
TeamText.text = Name;
}
public void SelectTeamToggle(bool isOn)
{
var group = TeamToggle.GetComponent<Toggle>().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;
}
}
}