219 lines
6.2 KiB
C#
219 lines
6.2 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.EventSystems;
|
|||
|
using System.Collections;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using System;
|
|||
|
using Games.LogicObj;
|
|||
|
using GCGame.Table;
|
|||
|
|
|||
|
public class TeamList : MonoBehaviour
|
|||
|
{
|
|||
|
private static TeamList m_Instance = null;
|
|||
|
public static TeamList Instance()
|
|||
|
{
|
|||
|
return m_Instance;
|
|||
|
}
|
|||
|
|
|||
|
public MemberUIInfo[] m_MemberUI;
|
|||
|
public float changeCaptainTime = 600.0f; // N秒后自动弹出跟换队长提示
|
|||
|
|
|||
|
// Awake
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
m_Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
// Use this for initialization
|
|||
|
void Start ()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
m_Instance = null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void OnEnable()
|
|||
|
{
|
|||
|
ClearTeamListUI();
|
|||
|
UpdateTeamMember();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//更新队员的信息
|
|||
|
public void UpdateTeamMember()
|
|||
|
{
|
|||
|
//ClearTeamListUI();
|
|||
|
//如果没有队,则清空
|
|||
|
if (GameManager.gameManager.PlayerDataPool.TeamInfo.TeamID < 0)
|
|||
|
{
|
|||
|
ClearTeamListUI();
|
|||
|
StopCountCaptainLeaveTime();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (null == Singleton<ObjManager>.GetInstance().MainPlayer)
|
|||
|
{
|
|||
|
StopCountCaptainLeaveTime();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//同时更新自己的队长图标
|
|||
|
if (null != PlayerFrameLogic.Instance() &&
|
|||
|
null != Singleton<ObjManager>.GetInstance().MainPlayer)
|
|||
|
{
|
|||
|
//PlayerFrameLogic.Instance().SetTeamCaptain(Singleton<ObjManager>.GetInstance().MainPlayer.IsTeamLeader());
|
|||
|
}
|
|||
|
|
|||
|
int index = 0;
|
|||
|
TeamMember[] member = GameManager.gameManager.PlayerDataPool.TeamInfo.teamMember;
|
|||
|
for (int i = 0; i < member.Length; ++i)
|
|||
|
{
|
|||
|
if (Singleton<ObjManager>.GetInstance().MainPlayer.IsTeamLeader(member[i].Guid))
|
|||
|
{
|
|||
|
captain = member[i];
|
|||
|
}
|
|||
|
|
|||
|
//如果队员的GUID为非空,并且和主角不一样,则显示
|
|||
|
if (member[i].Guid != GlobeVar.INVALID_GUID && member[i].Guid != GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid)
|
|||
|
{
|
|||
|
ShowMemberInfo(m_MemberUI[index], member[i]);
|
|||
|
if (Singleton<ObjManager>.GetInstance().MainPlayer.IsTeamLeader(member[i].Guid))
|
|||
|
{
|
|||
|
TryCountCpatainLevelTime();
|
|||
|
}
|
|||
|
|
|||
|
index++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (Singleton<ObjManager>.GetInstance().MainPlayer.IsTeamLeader())
|
|||
|
{
|
|||
|
StopCountCaptainLeaveTime();
|
|||
|
}
|
|||
|
|
|||
|
for (int i = index; i < m_MemberUI.Length; ++i)
|
|||
|
{
|
|||
|
m_MemberUI[i].gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//显示某一个队员的信息
|
|||
|
void ShowMemberInfo(MemberUIInfo teamMemberUI, TeamMember memberInfo)
|
|||
|
{
|
|||
|
if (null == teamMemberUI)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (!teamMemberUI.gameObject.activeSelf)
|
|||
|
teamMemberUI.gameObject.SetActive(true);
|
|||
|
teamMemberUI.UpdateInfo(memberInfo);
|
|||
|
}
|
|||
|
|
|||
|
//清空信息
|
|||
|
public void ClearTeamListUI()
|
|||
|
{
|
|||
|
for (int i = 0; i < m_MemberUI.Length; ++i)
|
|||
|
{
|
|||
|
if (null != m_MemberUI[i])
|
|||
|
{
|
|||
|
m_MemberUI[i].gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
//foreach (MemberUIInfo teamMemberUI in m_MemberUI)
|
|||
|
//{
|
|||
|
// if (null != teamMemberUI)
|
|||
|
// {
|
|||
|
// teamMemberUI.gameObject.SetActive(false);
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
private Coroutine captainStopCount = null; // 队长未移动计时
|
|||
|
private Vector2 captainPosCache = Vector2.zero; //
|
|||
|
|
|||
|
private float timeMark; // 开始停止移动的时间点
|
|||
|
|
|||
|
public TeamMember captain;
|
|||
|
private ulong lastLeaderGuid = 0; // 上一个队长的GUID
|
|||
|
|
|||
|
// 尝试开始队长离开
|
|||
|
public void TryCountCpatainLevelTime(bool isRestart = false)
|
|||
|
{
|
|||
|
var mainPlayer = Singleton<ObjManager>.GetInstance().MainPlayer;
|
|||
|
|
|||
|
if (mainPlayer != null && mainPlayer.IsTeamLeader(captain.Guid)
|
|||
|
&& !mainPlayer.IsTeamLeader())
|
|||
|
{
|
|||
|
if(captain.Guid != lastLeaderGuid)
|
|||
|
{
|
|||
|
lastLeaderGuid = captain.Guid;
|
|||
|
TryCountCpatainLevelTime(true);
|
|||
|
return;
|
|||
|
}
|
|||
|
else if (isRestart == true || captainStopCount == null)
|
|||
|
{
|
|||
|
//放到GameManager.gameManager开启,存在UI隐藏的情况,会把计时暂停
|
|||
|
if(captainStopCount != null)
|
|||
|
{
|
|||
|
StopCoroutine(captainStopCount);
|
|||
|
captainStopCount = GameManager.gameManager.StartCoroutine(CountCaptainTime());
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
captainStopCount = GameManager.gameManager.StartCoroutine(CountCaptainTime());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (captainStopCount != null)
|
|||
|
{
|
|||
|
StopCoroutine(captainStopCount);
|
|||
|
captainStopCount = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator CountCaptainTime()
|
|||
|
{
|
|||
|
timeMark = Time.realtimeSinceStartup;
|
|||
|
while (true)
|
|||
|
{
|
|||
|
if (!GameManager.gameManager.PlayerDataPool.IsHaveTeam())
|
|||
|
{
|
|||
|
TryCountCpatainLevelTime(true);
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
if (Vector2.Distance(captain.ScenePos, captainPosCache) > 0.0001f)
|
|||
|
{
|
|||
|
captainPosCache = captain.ScenePos;
|
|||
|
timeMark = Time.realtimeSinceStartup;
|
|||
|
}
|
|||
|
|
|||
|
if (Time.realtimeSinceStartup - timeMark > TeamList.Instance().changeCaptainTime)
|
|||
|
{
|
|||
|
CG_REQ_OTHER_BATTLE_STATE req = (CG_REQ_OTHER_BATTLE_STATE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_OTHER_BATTLE_STATE);
|
|||
|
req.Guid = (long)captain.Guid;
|
|||
|
req.SendPacket();
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void StopCountCaptainLeaveTime()
|
|||
|
{
|
|||
|
if(captainStopCount != null)
|
|||
|
{
|
|||
|
StopCoroutine(captainStopCount);
|
|||
|
captainStopCount = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|