288 lines
9.8 KiB
C#
288 lines
9.8 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using UnityEngine.EventSystems;
|
|||
|
using System.Collections;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using Games.ImpactModle;
|
|||
|
using GCGame;
|
|||
|
using Games.LogicObj;
|
|||
|
using GCGame.Table;
|
|||
|
|
|||
|
public class MemberUIInfo : MonoBehaviour, IPointerClickHandler
|
|||
|
{
|
|||
|
public Image m_HeadIcon; //头像
|
|||
|
public Text m_MemberName; //名字
|
|||
|
public Text m_LevelText; //等级
|
|||
|
public Slider m_HPSlider;
|
|||
|
public Text m_HPText; //生命值数值
|
|||
|
public Image m_Captain; //队长图标
|
|||
|
public GameObject _FollowObj; //跟随标志
|
|||
|
public GameObject _ShowPopMenuPos;
|
|||
|
public Text _Pos;
|
|||
|
public Image _HPValueImg;
|
|||
|
public GameObject _OffLineGO;
|
|||
|
private Coroutine captainStopCount = null; // 队长未移动计时
|
|||
|
private Vector2 captainPosCache = Vector2.zero; //
|
|||
|
|
|||
|
private float timeMark; // 开始停止移动的时间点
|
|||
|
|
|||
|
private TeamMember _TeamMember;
|
|||
|
private ulong lastLeaderGuid = 0; // 上一个队长的GUID
|
|||
|
|
|||
|
public const float _UpdatePosInterval = 1.0f;
|
|||
|
private float _LastUpdateTime = 0;
|
|||
|
|
|||
|
public void Update()
|
|||
|
{
|
|||
|
if (_TeamMember == null)
|
|||
|
return;
|
|||
|
|
|||
|
if (Time.time - _LastUpdateTime > _UpdatePosInterval)
|
|||
|
{
|
|||
|
if (_TeamMember.IsOnline)
|
|||
|
{
|
|||
|
var sceneCopy = TableManager.GetFubenByID(_TeamMember.SceneClassID, 0);
|
|||
|
if (sceneCopy == null)
|
|||
|
{
|
|||
|
_Pos.text = StrDictionary.GetClientDictionaryString("#{5160}");
|
|||
|
}
|
|||
|
else if (sceneCopy.GetSceneIdbyIndex(0) != GameManager.gameManager.RunningScene || _TeamMember.SceneInstID != SceneData.SceneInst)
|
|||
|
{
|
|||
|
var sceneTableRecord = TableManager.GetSceneClassByID(sceneCopy.GetSceneIdbyIndex(0), 0);
|
|||
|
if (sceneTableRecord != null)
|
|||
|
{
|
|||
|
_Pos.text = sceneTableRecord.Name;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
int dis = (int)Vector2.Distance(_TeamMember.ScenePos, new Vector2(Singleton<ObjManager>.GetInstance().MainPlayer.Position.x, Singleton<ObjManager>.GetInstance().MainPlayer.Position.z));
|
|||
|
_Pos.text = StrDictionary.GetClientDictionaryString("#{5150}", dis);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_Pos.text = StrDictionary.GetClientDictionaryString("#{5151}");
|
|||
|
}
|
|||
|
|
|||
|
_LastUpdateTime = Time.time;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator CountCaptainTime()
|
|||
|
{
|
|||
|
timeMark = Time.realtimeSinceStartup;
|
|||
|
while (true)
|
|||
|
{
|
|||
|
if (!GameManager.gameManager.PlayerDataPool.IsHaveTeam())
|
|||
|
{
|
|||
|
TryCpatainCountTime(true);
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
if (Vector2.Distance(_TeamMember.ScenePos, captainPosCache) > 0.0001f)
|
|||
|
{
|
|||
|
captainPosCache = _TeamMember.ScenePos;
|
|||
|
timeMark = Time.realtimeSinceStartup;
|
|||
|
}
|
|||
|
|
|||
|
if (Time.realtimeSinceStartup - timeMark > TeamList.Instance().changeCaptainTime)
|
|||
|
{
|
|||
|
string tip = StrDictionary.GetClientDictionaryString("#{52007}");
|
|||
|
//MessageBoxLogic.OpenOKCancelBox(tip, null,
|
|||
|
// () =>
|
|||
|
// {
|
|||
|
// if (null == Singleton<ObjManager>.GetInstance().MainPlayer)
|
|||
|
// {
|
|||
|
// return;
|
|||
|
// }
|
|||
|
|
|||
|
// CG_REQ_BECOME_TEAM_LEADER packet = (CG_REQ_BECOME_TEAM_LEADER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_BECOME_TEAM_LEADER);
|
|||
|
// packet.Nilparam = 1;
|
|||
|
// packet.SendPacket();
|
|||
|
// },
|
|||
|
// disableCallBack:() =>
|
|||
|
// {
|
|||
|
// TryCpatainCountTime(true);
|
|||
|
// });
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void StopCount()
|
|||
|
{
|
|||
|
if (captainStopCount != null)
|
|||
|
{
|
|||
|
StopCoroutine(captainStopCount);
|
|||
|
captainStopCount = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 尝试开始队长离开
|
|||
|
public void TryCpatainCountTime(bool isRestart = false)
|
|||
|
{
|
|||
|
Obj_MainPlayer mainPlayer = null;
|
|||
|
if (null != Singleton<ObjManager>.GetInstance().MainPlayer && null != m_Captain)
|
|||
|
{
|
|||
|
mainPlayer = ObjManager.Instance.MainPlayer;
|
|||
|
}
|
|||
|
|
|||
|
//(AnimLogic.IsPlayAnim(idleAnimId) || AnimLogic.IsPlayAnim(fightIdleAnimId)
|
|||
|
|
|||
|
if (mainPlayer != null && mainPlayer.IsTeamLeader(_TeamMember.Guid)
|
|||
|
&& _TeamMember.Guid == lastLeaderGuid)
|
|||
|
{
|
|||
|
if (isRestart == true || captainStopCount == null)
|
|||
|
{
|
|||
|
//放到GameManager.gameManager开启,存在UI隐藏的情况,会把计时暂停
|
|||
|
captainStopCount = GameManager.gameManager.StartCoroutine(CountCaptainTime());
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (captainStopCount != null)
|
|||
|
{
|
|||
|
StopCoroutine(captainStopCount);
|
|||
|
captainStopCount = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (mainPlayer != null && mainPlayer.IsTeamLeader(_TeamMember.Guid))
|
|||
|
{
|
|||
|
lastLeaderGuid = _TeamMember.Guid;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateInfo(TeamMember member)
|
|||
|
{
|
|||
|
if (member.Guid == GlobeVar.INVALID_GUID)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Obj_MainPlayer mainPlayer = null;
|
|||
|
if (null != Singleton<ObjManager>.GetInstance().MainPlayer && null != m_Captain)
|
|||
|
{
|
|||
|
mainPlayer = ObjManager.Instance.MainPlayer;
|
|||
|
}
|
|||
|
|
|||
|
_TeamMember = member;
|
|||
|
//TryCpatainCountTime();
|
|||
|
|
|||
|
if (null != m_HeadIcon)
|
|||
|
{
|
|||
|
if (member.Profession >= 0 && member.Profession < (int) CharacterDefine.PROFESSION.MAX)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(m_HeadIcon, Utils.GetProfessionSpriteName(member.Profession));
|
|||
|
}
|
|||
|
|
|||
|
if (member.IsOnline)
|
|||
|
{
|
|||
|
m_HeadIcon.material = null;
|
|||
|
_HPValueImg.material = null;
|
|||
|
_OffLineGO.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
m_HeadIcon.material = FriendChatItem.ImageGrayMaterial;
|
|||
|
_HPValueImg.material = FriendChatItem.ImageGrayMaterial;
|
|||
|
_OffLineGO.gameObject.SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (null != m_LevelText)
|
|||
|
{
|
|||
|
m_LevelText.text = member.Level.ToString();
|
|||
|
}
|
|||
|
|
|||
|
if (null != m_MemberName)
|
|||
|
{
|
|||
|
m_MemberName.text = member.MemberName;
|
|||
|
}
|
|||
|
|
|||
|
if (null != m_HPSlider && null != m_HPText)
|
|||
|
{
|
|||
|
if (member.MaxHP == 0)
|
|||
|
{
|
|||
|
m_HPSlider.value = 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
m_HPSlider.value = (float) member.HP / (float) member.MaxHP;
|
|||
|
}
|
|||
|
|
|||
|
m_HPText.text = member.HP.ToString() + '/' + member.MaxHP.ToString();
|
|||
|
}
|
|||
|
|
|||
|
_FollowObj.SetActive(member.FollowLeader());
|
|||
|
|
|||
|
if (mainPlayer != null && null != m_Captain)
|
|||
|
{
|
|||
|
if (mainPlayer.IsTeamLeader(member.Guid))
|
|||
|
{
|
|||
|
_FollowObj.SetActive(false);
|
|||
|
m_Captain.gameObject.SetActive(true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
m_Captain.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//if (Time.time - _LastUpdateTime > _UpdatePosInterval)
|
|||
|
//{
|
|||
|
// if (_TeamMember.IsOnline)
|
|||
|
// {
|
|||
|
// if (_TeamMember.SceneClassID != GameManager.gameManager.RunningScene || _TeamMember.SceneInstID != SceneData.SceneInst)
|
|||
|
// {
|
|||
|
// var sceneCopy = TableManager.GetFubenByID(_TeamMember.SceneClassID, 0);
|
|||
|
// if (sceneCopy != null)
|
|||
|
// {
|
|||
|
// var sceneTableRecord = TableManager.GetSceneClassByID(sceneCopy.GetSceneIdbyIndex(0), 0);
|
|||
|
// if (sceneTableRecord != null)
|
|||
|
// {
|
|||
|
// _Pos.text = sceneTableRecord.Name;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// _Pos.text = StrDictionary.GetClientDictionaryString("#{5160}");
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// int dis = (int)Vector2.Distance(_TeamMember.ScenePos, new Vector2(Singleton<ObjManager>.GetInstance().MainPlayer.Position.x, Singleton<ObjManager>.GetInstance().MainPlayer.Position.z));
|
|||
|
// _Pos.text = StrDictionary.GetClientDictionaryString("#{5150}", dis);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// _Pos.text = StrDictionary.GetClientDictionaryString("#{5151}");
|
|||
|
// }
|
|||
|
|
|||
|
// _LastUpdateTime = Time.time;
|
|||
|
//}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//打开组队界面
|
|||
|
public void OpenTeamWindow()
|
|||
|
{
|
|||
|
UIManager.ShowUI(UIInfo.TeamInfoRoot);
|
|||
|
}
|
|||
|
|
|||
|
public void OnPointerClick(PointerEventData eventData)
|
|||
|
{
|
|||
|
//if (Singleton<ObjManager>.GetInstance().MainPlayer.IsTeamLeader(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid))
|
|||
|
PopMenuLogic.ShowMenu("TeamMemberPopMenu", _ShowPopMenuPos, _TeamMember.Guid, _TeamMember.MemberName);
|
|||
|
var obj = Singleton<ObjManager>.GetInstance().FindOtherPlayerByGuid(_TeamMember.Guid);
|
|||
|
if (obj == null)
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{8021}", _TeamMember.MemberName));
|
|||
|
else if (!obj.IsDisableState(DISABLESTATE.Disable_BeSelect))
|
|||
|
Singleton<ObjManager>.GetInstance().MainPlayer.SetSelectTarget(obj);
|
|||
|
}
|
|||
|
}
|