using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class FairyCallMemberBehaviour : MonoBehaviour
|
{
|
[SerializeField] Button m_CallMember;
|
[SerializeField] Text m_Timer;
|
[SerializeField] UIEffect m_Effect;
|
[SerializeField] RotationTween m_Tween;
|
|
long lastTick = 0;
|
|
FairyGrabBossModel model { get { return ModelCenter.Instance.GetModel<FairyGrabBossModel>(); } }
|
|
private void Awake()
|
{
|
m_CallMember.AddListener(CallMember);
|
}
|
|
public void Init()
|
{
|
model.bossGrabHintEvent += BossGrabHintEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo;
|
GlobalTimeEvent.Instance.secondEvent += DisplayTimer;
|
Display();
|
DisplayTimer();
|
DisplayEffect();
|
}
|
|
public void UnInit()
|
{
|
model.bossGrabHintEvent -= BossGrabHintEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo;
|
GlobalTimeEvent.Instance.secondEvent -= DisplayTimer;
|
}
|
|
private void BossGrabHintEvent()
|
{
|
Display();
|
}
|
|
private void OnRefreshFairyInfo()
|
{
|
Display();
|
}
|
|
void Display()
|
{
|
m_CallMember.gameObject.SetActive(CheckCallMember());
|
DisplayEffect();
|
}
|
|
bool CheckCallMember()
|
{
|
if (PlayerDatas.Instance.baseData.FamilyId == 0
|
|| !model.grabBossHintOpen)
|
{
|
return false;
|
}
|
var fairyMember = PlayerDatas.Instance.fairyData.mine;
|
if (fairyMember == null || fairyMember.FamilyLV < model.callMemberDuty)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
private void CallMember()
|
{
|
var bossId = 0;
|
var list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFightBoss);
|
if (list != null)
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
GA_NpcFightBoss bossActor = list[i] as GA_NpcFightBoss;
|
if (bossActor != null && model.bosses.Contains(bossActor.NpcConfig.NPCID))
|
{
|
bossId = bossActor.NpcConfig.NPCID;
|
break;
|
}
|
}
|
}
|
if (bossId != 0)
|
{
|
var deltaTick = DateTime.Now.Ticks - lastTick;
|
var ts = new TimeSpan(deltaTick);
|
if (ts.TotalSeconds >= model.callMemberSeconds)
|
{
|
lastTick = DateTime.Now.Ticks;
|
DisplayTimer();
|
CAC05_tagCGCallupFamilyMemberToBoss pak = new CAC05_tagCGCallupFamilyMemberToBoss();
|
pak.NPCID = (uint)bossId;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("FairyCallMemberCd");
|
}
|
}
|
}
|
|
void DisplayTimer()
|
{
|
if (m_CallMember.gameObject.activeInHierarchy)
|
{
|
var ticks = DateTime.Now.Ticks - lastTick;
|
var ts = new TimeSpan(ticks < 0 ? 0 : ticks);
|
var seconds = (int)(model.callMemberSeconds - ts.TotalSeconds);
|
if (seconds <= 0 && m_Timer.gameObject.activeSelf)
|
{
|
m_Timer.gameObject.SetActive(false);
|
DisplayEffect();
|
}
|
else if (seconds > 0)
|
{
|
if (!m_Timer.gameObject.activeSelf)
|
{
|
m_Timer.gameObject.SetActive(true);
|
DisplayEffect();
|
}
|
m_Timer.text = StringUtility.Contact(seconds, Language.Get("RealmWin_Bewrite_35"));
|
}
|
}
|
}
|
|
void DisplayEffect()
|
{
|
var ticks = DateTime.Now.Ticks - lastTick;
|
var ts = new TimeSpan(ticks < 0 ? 0 : ticks);
|
var seconds = (int)(model.callMemberSeconds - ts.TotalSeconds);
|
if (seconds > 0 || !m_CallMember.gameObject.activeInHierarchy)
|
{
|
if (m_Effect.IsPlaying)
|
{
|
m_Effect.StopImediatly();
|
}
|
if (m_Tween.enabled)
|
{
|
m_Tween.enabled = false;
|
m_Tween.transform.localEulerAngles = Vector3.zero;
|
}
|
}
|
else
|
{
|
if (!m_Effect.IsPlaying)
|
{
|
m_Effect.Play();
|
}
|
if (!m_Tween.enabled)
|
{
|
m_Tween.enabled = true;
|
}
|
}
|
}
|
}
|
}
|