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.
175 lines
5.9 KiB
175 lines
5.9 KiB
using AX.MessageSystem; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
/// <summary> |
|
/// 此脚本挂在4GPersonItem上 |
|
/// </summary> |
|
public class FourthGPersonItemCtrl : BaseToggle { |
|
public Toggle toggle; |
|
public ToggleGroup toggleGroup; |
|
public UserData data; |
|
public CloneGameObjInfo info; |
|
public Text userName; |
|
private static List<Toggle> toggles = new List<Toggle>(4); |
|
|
|
public override void RespondFun(bool value) |
|
{ |
|
if (QuadrupleMode.quadingMode ==false) |
|
{ |
|
PersonSelected(value); //不在四分屏模式时的选中 |
|
} |
|
else |
|
{ |
|
PersonDisplayed(value); //四分屏模式下的选中 |
|
} |
|
} |
|
|
|
// Use this for initialization |
|
void Start () { |
|
|
|
} |
|
|
|
public void SetPersonInfo(CloneGameObjInfo userInfo,UserData userData) |
|
{ |
|
info = userInfo; |
|
data = userData; |
|
userName = transform.Find("Label").GetComponent<Text>(); |
|
userName.text = data.UserInfo.RealName + "(外)"; //判断室内室外 |
|
toggle = GetComponent<Toggle>(); |
|
toggleGroup = transform.parent.GetComponent<ToggleGroup>(); |
|
if (QuadrupleMode.quadingMode == false) //如果当前不在四分屏模式,就添加toggleGroup,不能多选 |
|
{ |
|
toggle.group = toggleGroup; |
|
} |
|
else //如果当前在四分屏模式下 |
|
{ |
|
if (toggles.Count > 3) //如果已经选了4个 |
|
{ |
|
toggle.interactable = false; //不能再选此toggle了 |
|
} |
|
MessageDispatcher.AddListener("QuadDisplayMore", DisableToggle); //限制只能选4个 |
|
} |
|
//toggle.onValueChanged.AddListener(PersonSelected); |
|
MessageDispatcher.AddListener("QuadrupleMode", SwitchToggle); |
|
} |
|
void PersonSelected(bool isON) |
|
{ |
|
//如果没有人员被选中,就取消地图相机跟随 |
|
if (!toggleGroup.AnyTogglesOn()) |
|
{ |
|
//取消相机跟随 FourthGCamCtrl.NobodySelected() |
|
//清空LookOver的selectedInfo FourthGLookOver.ClearSelectedPerson() |
|
MessageDispatcher.SendMessage("4GNobodySelected"); |
|
} |
|
MapSelectedPair pair = new MapSelectedPair() |
|
{ |
|
gameObjID = info.gameObjID, |
|
isOn = isON |
|
}; |
|
MessageDispatcher.SendMessage("4GPersonSelected", pair); |
|
if (isON == true) |
|
{ |
|
//查看按钮设置对象 FourthGLookOver.SetSelectedPerson() |
|
MessageDispatcher.SendMessage("FourthGLookOver", info); |
|
} |
|
} |
|
/// <summary> |
|
/// 是否分屏显示此人员 |
|
/// </summary> |
|
/// <param name="isON"></param> |
|
void PersonDisplayed(bool isON) |
|
{ |
|
if (isON) //被选中显示 |
|
{ |
|
//创建相机 |
|
MessageDispatcher.SendMessage("QuadDisplay", info); |
|
toggles.Add(toggle); |
|
if (toggles.Count > 3) //已经选了4个显示人员 |
|
{ |
|
MessageDispatcher.SendMessage("QuadDisplayMore",false); //禁用其他toggle,不能再选人员了 |
|
} |
|
} |
|
else //被取消选中 |
|
{ |
|
if (toggles.Contains(toggle)) |
|
{ |
|
//取消相机 |
|
MessageDispatcher.SendMessage("CancelQuadDisplay", info); |
|
toggles.Remove(toggle); |
|
if (toggles.Count < 4) |
|
{ |
|
MessageDispatcher.SendMessage("QuadDisplayMore", true); //没有选到4个人,则可以再选中 |
|
} |
|
} |
|
} |
|
} |
|
void DisableToggle(IMessage obj) |
|
{ |
|
var canMore = (bool)obj.Data; //是否可以选中更多 |
|
if (canMore == false) //不能再选中了 |
|
{ |
|
if (toggle && toggle.isOn == false) //如果此按钮没被选中 |
|
{ |
|
toggle.interactable = false; //则不可以再选中了 |
|
} |
|
} |
|
else //可以再选中 |
|
{ |
|
if (toggle && toggle.interactable == false) //如果当前toggle被禁用 |
|
{ |
|
toggle.interactable = true; //解禁 |
|
} |
|
} |
|
} |
|
// Update is called once per frame |
|
void Update () { |
|
|
|
} |
|
/// <summary> |
|
/// 开启、取消四分屏模式,相应的toggle变化控制 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
void SwitchToggle(IMessage obj) |
|
{ |
|
var isQuaded = (bool)obj.Data; |
|
if (isQuaded) //开启四分屏模式 |
|
{ |
|
toggle.isOn = false; |
|
//StartCoroutine(SwitchIntoQuad()); |
|
toggle.group = null; |
|
toggleGroup.UnregisterToggle(toggle); |
|
MessageDispatcher.AddListener("QuadDisplayMore", DisableToggle); //限制只能选4个 |
|
toggle.interactable = true; |
|
} |
|
else //关闭四分屏 |
|
{ |
|
toggles.Clear(); |
|
if (toggle) |
|
{ |
|
toggle.group = toggleGroup; |
|
//toggle.onValueChanged.RemoveListener(PersonDisplayed); |
|
toggle.isOn = false; //取消选中此toggle |
|
//toggle.onValueChanged.AddListener(PersonSelected); |
|
toggle.interactable = true; //如果之前禁用了此toggle,则恢复 |
|
} |
|
MessageDispatcher.RemoveListener("QuadDisplayMore", DisableToggle); |
|
} |
|
} |
|
public override void OnDestroy() |
|
{ |
|
base.OnDestroy(); |
|
RespondFun(false); |
|
if (QuadrupleMode.quadingMode) |
|
{ |
|
MessageDispatcher.AddListener("QuadDisplayMore", DisableToggle); |
|
} |
|
MessageDispatcher.RemoveListener("QuadrupleMode", SwitchToggle); |
|
} |
|
} |
|
public class MapSelectedPair |
|
{ |
|
public long gameObjID; |
|
public bool isOn; |
|
}
|
|
|