430 lines
12 KiB
C#
430 lines
12 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.LogicObj;
|
|||
|
using Games.Mission;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using Module.Log;
|
|||
|
using Games.Item;
|
|||
|
|
|||
|
// 每日/每周跑环
|
|||
|
public class MissionCircleAward : MonoBehaviour
|
|||
|
{
|
|||
|
public CircleMissionManager.CircleType cricleType;
|
|||
|
private static MissionCircleAward _instance_day;
|
|||
|
private static MissionCircleAward _instance_week;
|
|||
|
|
|||
|
public static MissionCircleAward MissionCircleAward_Day
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if(_instance_day != null)
|
|||
|
{
|
|||
|
return _instance_day;
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static MissionCircleAward MissionCircleAward_Week
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_instance_week != null)
|
|||
|
{
|
|||
|
return _instance_week;
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public CircleAnim _OutCircle;
|
|||
|
public CommonItemContainerItem[] _AwardItems;
|
|||
|
public CircleAnim _InnerCircle;
|
|||
|
public Text[] _AwardRate;
|
|||
|
public Text _AutoTips;
|
|||
|
public Text _LastTimes;
|
|||
|
public Button _BtnSelect;
|
|||
|
public Button _BtnGet;
|
|||
|
public Toggle _SkipAnim;
|
|||
|
public float _OutAwardPosRange;
|
|||
|
public float _InAwardPosRange;
|
|||
|
public float _InitIdxOut;
|
|||
|
public float _InitIdxIn;
|
|||
|
public float _TargetIdxOut;
|
|||
|
public float _TargetIdxIn;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
//InitAward();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
if (_instance_day == null && cricleType == CircleMissionManager.CircleType.daily)
|
|||
|
{
|
|||
|
_instance_day = this;
|
|||
|
}
|
|||
|
|
|||
|
if (_instance_week == null && cricleType == CircleMissionManager.CircleType.weekly)
|
|||
|
{
|
|||
|
_instance_week = this;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
Refresh();
|
|||
|
InitBtn();
|
|||
|
_AutoTips.text = "";
|
|||
|
|
|||
|
_SkipAnim.isOn = GameManager.gameManager.CircleMissionManager.SkilAnimByType(cricleType);
|
|||
|
|
|||
|
StartCoroutine(InitAward());
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
if (cricleType == CircleMissionManager.CircleType.daily)
|
|||
|
{
|
|||
|
_instance_day = null;
|
|||
|
}
|
|||
|
|
|||
|
if (cricleType == CircleMissionManager.CircleType.weekly)
|
|||
|
{
|
|||
|
_instance_week = null;
|
|||
|
}
|
|||
|
|
|||
|
WaittingAward = false;
|
|||
|
GameManager.gameManager.CircleMissionManager.GetAward(cricleType);
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
//AutoUpdate();
|
|||
|
|
|||
|
for (int i = 0; i < _AwardItems.Length; ++i)
|
|||
|
{
|
|||
|
_AwardItems[i]._ItemSlot.rotation = Quaternion.Euler(Vector3.zero);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Close()
|
|||
|
{
|
|||
|
if (cricleType == CircleMissionManager.CircleType.daily)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.MissionCircleAward_Day);
|
|||
|
}
|
|||
|
|
|||
|
if (cricleType == CircleMissionManager.CircleType.weekly)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.MissionCircleAward_Week);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Rot
|
|||
|
|
|||
|
private float _DeltaAngleIn = 0;
|
|||
|
private float _DeltaAngleOut = 0;
|
|||
|
|
|||
|
private IEnumerator InitAward()
|
|||
|
{
|
|||
|
var mainRole = Singleton<ObjManager>.GetInstance().MainPlayer;
|
|||
|
while (mainRole == null || mainRole.BaseAttr.Level <= 0)
|
|||
|
{
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
int roleLevel = mainRole.BaseAttr.Level;
|
|||
|
float startAngle = 0;
|
|||
|
_DeltaAngleOut = 360.0f / _AwardItems.Length;
|
|||
|
Tab_CircleTaskGameRewards awardRecord = null;
|
|||
|
var ciclrRewardTabs = TableManager.GetCircleTaskGameRewards().Values;
|
|||
|
|
|||
|
// 读表,获得适合玩家当前等级的一组奖励和倍数
|
|||
|
// 每日是 1 每周是 2
|
|||
|
int ctID = cricleType == CircleMissionManager.CircleType.daily ? 1 : 2;
|
|||
|
foreach (var circleRewardTab in ciclrRewardTabs)
|
|||
|
{
|
|||
|
if (circleRewardTab.LevelMin <= roleLevel
|
|||
|
&& circleRewardTab.LevelMax >= roleLevel
|
|||
|
&& circleRewardTab.CircleType == ctID)
|
|||
|
{
|
|||
|
awardRecord = circleRewardTab;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 外圈奖品内容初始化
|
|||
|
for (int i = 0; i < _AwardItems.Length; ++i)
|
|||
|
{
|
|||
|
var missionParam = new CommonItemContainerItem.ItemInfo();
|
|||
|
missionParam.itemNum = awardRecord.GetRewardNumbyIndex(i);
|
|||
|
missionParam.itemID = awardRecord.GetRewardSubTypebyIndex(i);
|
|||
|
_AwardItems[i].InitItem(missionParam);
|
|||
|
|
|||
|
Vector2 gemPos = Vector2.zero;
|
|||
|
gemPos.x = Mathf.Sin((_DeltaAngleOut * i + startAngle) * Mathf.Deg2Rad) * _OutAwardPosRange;
|
|||
|
gemPos.y = Mathf.Cos((_DeltaAngleOut * i + startAngle) * Mathf.Deg2Rad) * _OutAwardPosRange;
|
|||
|
_AwardItems[i].GetComponent<RectTransform>().anchoredPosition = gemPos;
|
|||
|
_AwardItems[i].GetComponent<RectTransform>().localRotation = Quaternion.Euler(new Vector3(0, 0, -_DeltaAngleOut * i - startAngle));
|
|||
|
_AwardItems[i]._ItemSlot.rotation = Quaternion.Euler(Vector3.zero);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// 内圈倍率初始化,
|
|||
|
float startAngleInner = 0;
|
|||
|
_DeltaAngleIn = 360.0f / _AwardRate.Length;
|
|||
|
|
|||
|
// 每日是 1 每周是 2
|
|||
|
int ctmID = cricleType == CircleMissionManager.CircleType.daily ? 1 : 2;
|
|||
|
var awardMulti = TableManager.GetCircleTaskGameRewardMultiByID(ctmID, 0);
|
|||
|
for (int i = 0; i < _AwardRate.Length; ++i)
|
|||
|
{
|
|||
|
_AwardRate[i].text = StrDictionary.GetClientDictionaryString("#{46264}", awardMulti.GetMultiNumbyIndex(i).ToString());
|
|||
|
|
|||
|
Vector2 gemPos = Vector2.zero;
|
|||
|
gemPos.x = Mathf.Sin((_DeltaAngleIn * i + startAngleInner) * Mathf.Deg2Rad) * _InAwardPosRange;
|
|||
|
gemPos.y = Mathf.Cos((_DeltaAngleIn * i + startAngleInner) * Mathf.Deg2Rad) * _InAwardPosRange;
|
|||
|
_AwardRate[i].GetComponent<RectTransform>().anchoredPosition = gemPos;
|
|||
|
_AwardRate[i].GetComponent<RectTransform>().localRotation = Quaternion.Euler(new Vector3(0, 0, -_DeltaAngleIn * i - startAngleInner));
|
|||
|
}
|
|||
|
|
|||
|
InitCircleAngle();
|
|||
|
}
|
|||
|
|
|||
|
public void InitCircleAngle()
|
|||
|
{
|
|||
|
var initAngelOut = _DeltaAngleOut * GameManager.gameManager.CircleMissionManager.RewardIndexByType(cricleType);
|
|||
|
_OutCircle.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, initAngelOut));
|
|||
|
|
|||
|
var initAngelIn = _DeltaAngleIn * GameManager.gameManager.CircleMissionManager.MultiNumIndexByType(cricleType);
|
|||
|
_InnerCircle.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, initAngelIn));
|
|||
|
}
|
|||
|
|
|||
|
public void Refresh()
|
|||
|
{
|
|||
|
_AutoStartTime = Time.time;
|
|||
|
_OutCircle.ResetAll();
|
|||
|
_InnerCircle.ResetAll();
|
|||
|
InitBtn();
|
|||
|
|
|||
|
InitCircleAngle();
|
|||
|
|
|||
|
_LastTimes.text = StrDictionary.GetClientDictionaryString("#{46265}", GameManager.gameManager.CircleMissionManager.LastAwardCntByType(cricleType));
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region auto
|
|||
|
|
|||
|
private float _AutoStartTime;
|
|||
|
private float _AutoSelectTime = 10;
|
|||
|
private float _AutoGetTime = 5;
|
|||
|
private bool _AutoAwarding = false;
|
|||
|
|
|||
|
private void AutoUpdate()
|
|||
|
{
|
|||
|
//if (!_AutoAwarding)
|
|||
|
// return;
|
|||
|
if (_BtnSelect.gameObject.activeSelf)
|
|||
|
{
|
|||
|
if (!_BtnSelect.interactable)
|
|||
|
{
|
|||
|
_AutoTips.text = StrDictionary.GetClientDictionaryString("#{46261}");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (Time.time - _AutoStartTime > _AutoSelectTime)
|
|||
|
{
|
|||
|
OnBtnSelect();
|
|||
|
//_BtnSelect.interactable = false;
|
|||
|
_AutoStartTime = Time.time;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
int autoDelay = (int)(_AutoSelectTime - (Time.time - _AutoStartTime));
|
|||
|
_AutoTips.text = StrDictionary.GetClientDictionaryString("#{46260}", autoDelay);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if(_BtnGet.gameObject.activeSelf)
|
|||
|
{
|
|||
|
if (_BtnGet.interactable)
|
|||
|
{
|
|||
|
if (Time.time - _AutoStartTime > _AutoGetTime)
|
|||
|
{
|
|||
|
OnBtnGet();
|
|||
|
//_BtnSelect.interactable = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
int autoDelay = (int)(_AutoGetTime - (Time.time - _AutoStartTime));
|
|||
|
_AutoTips.text = StrDictionary.GetClientDictionaryString("#{46262}", autoDelay);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_AutoTips.text = StrDictionary.GetClientDictionaryString("#{46261}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region interface
|
|||
|
|
|||
|
private int _ActingCircleCnt = 0;
|
|||
|
private bool _WaittingAward = false;
|
|||
|
public bool WaittingAward
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _WaittingAward;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
_WaittingAward = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void InitBtn()
|
|||
|
{
|
|||
|
HideBtnEffect();
|
|||
|
HideItemEffect();
|
|||
|
|
|||
|
if (GameManager.gameManager.CircleMissionManager.CurStateByType(cricleType) == 2)
|
|||
|
{
|
|||
|
_BtnSelect.gameObject.SetActive(false);
|
|||
|
_BtnSelect.interactable = true;
|
|||
|
_BtnGet.gameObject.SetActive(true);
|
|||
|
_BtnGet.interactable = true;
|
|||
|
PlayBtnEffect();
|
|||
|
PlayItemEffect();
|
|||
|
}
|
|||
|
else if (GameManager.gameManager.CircleMissionManager.LastAwardCntByType(cricleType) > 0)
|
|||
|
{
|
|||
|
_BtnSelect.gameObject.SetActive(true);
|
|||
|
_BtnSelect.interactable = true;
|
|||
|
_BtnGet.gameObject.SetActive(false);
|
|||
|
_AutoAwarding = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_BtnSelect.gameObject.SetActive(true);
|
|||
|
_BtnSelect.interactable = false;
|
|||
|
_BtnGet.gameObject.SetActive(false);
|
|||
|
_AutoTips.text = "";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnBtnSelect()
|
|||
|
{
|
|||
|
GameManager.gameManager.CircleMissionManager.SelectAward(cricleType);
|
|||
|
WaittingAward = true;
|
|||
|
}
|
|||
|
|
|||
|
public void SelectAward()
|
|||
|
{
|
|||
|
WaittingAward = false;
|
|||
|
|
|||
|
// 将服务器确定好的索引转成角度,设置到内外圈动画的目标角度中
|
|||
|
float deltaAngle = 360.0f / _AwardItems.Length;
|
|||
|
_OutCircle._TargetAngle = deltaAngle * _TargetIdxOut;
|
|||
|
float deltaAngleInner = 360.0f / _AwardRate.Length;
|
|||
|
_InnerCircle._TargetAngle = deltaAngleInner * _TargetIdxIn;
|
|||
|
|
|||
|
// 更新按钮状态
|
|||
|
_BtnSelect.gameObject.SetActive(false);
|
|||
|
_BtnGet.gameObject.SetActive(true);
|
|||
|
_BtnGet.interactable = false;
|
|||
|
|
|||
|
// 若跳过动画勾选
|
|||
|
if (_SkipAnim.isOn)
|
|||
|
{
|
|||
|
_ActingCircleCnt = 1;
|
|||
|
|
|||
|
// 直接设定内外圈角度,并停止动画。
|
|||
|
_OutCircle._RotCircle.localRotation = Quaternion.Euler(new Vector3(0, 0, _OutCircle._TargetAngle));
|
|||
|
_InnerCircle._RotCircle.localRotation = Quaternion.Euler(new Vector3(0, 0, _InnerCircle._TargetAngle));
|
|||
|
StopAnimCircleBack();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_ActingCircleCnt = 2;
|
|||
|
|
|||
|
_OutCircle.StartRot();
|
|||
|
_InnerCircle.StartRot();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnBtnGet()
|
|||
|
{
|
|||
|
GameManager.gameManager.CircleMissionManager.GetAward(cricleType);
|
|||
|
if (GameManager.gameManager.CircleMissionManager.LastAwardCntByType(cricleType) > 1)
|
|||
|
{
|
|||
|
//Refresh();
|
|||
|
}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// Close();
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 跳过动画设置,并保存设置
|
|||
|
/// </summary>
|
|||
|
public void OnSkilAnim()
|
|||
|
{
|
|||
|
GameManager.gameManager.CircleMissionManager.SetSkilAnimByType(cricleType, _SkipAnim.isOn);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 停止动画,并播放奖励特效,“获取” 按钮可用
|
|||
|
/// </summary>
|
|||
|
public void StopAnimCircleBack()
|
|||
|
{
|
|||
|
--_ActingCircleCnt;
|
|||
|
if (_ActingCircleCnt == 0)
|
|||
|
{
|
|||
|
_AutoStartTime = Time.time;
|
|||
|
_BtnGet.interactable = true;
|
|||
|
PlayBtnEffect();
|
|||
|
}
|
|||
|
|
|||
|
PlayItemEffect();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region effect
|
|||
|
|
|||
|
public GameObject _BtnEffect;
|
|||
|
public GameObject _ItemEffect;
|
|||
|
|
|||
|
public void PlayBtnEffect()
|
|||
|
{
|
|||
|
_BtnEffect.transform.position = _BtnGet.transform.position;
|
|||
|
_BtnEffect.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public void HideBtnEffect()
|
|||
|
{
|
|||
|
_BtnEffect.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
public void PlayItemEffect()
|
|||
|
{
|
|||
|
// 为防止位置不正确,将再赋值特效位置
|
|||
|
_ItemEffect.transform.position = _AwardItems[(int)_TargetIdxOut]._ItemSlot.transform.position;
|
|||
|
_ItemEffect.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public void HideItemEffect()
|
|||
|
{
|
|||
|
_ItemEffect.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|