412 lines
11 KiB
C#
412 lines
11 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-01-11
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "LevelUnlockBox.View" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
using DG.Tweening;
|
|||
|
using System.Collections;
|
|||
|
|
|||
|
using TMPro;
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class JobWidget : KUIWidget
|
|||
|
{
|
|||
|
[KUIFlag]
|
|||
|
Button _btnAdd;
|
|||
|
|
|||
|
Slider _slider;
|
|||
|
|
|||
|
private void OnAddBtnClick()
|
|||
|
{
|
|||
|
if (!_anim)
|
|||
|
if (this.data is RadarChart radar)
|
|||
|
{
|
|||
|
radar.radio[this.index] += 0.02f;
|
|||
|
radar.InitHandlers();
|
|||
|
|
|||
|
StartCoroutine(doAnim());
|
|||
|
|
|||
|
if (Random.value < 0.2f)
|
|||
|
{
|
|||
|
//AdventureProxy.Instance.ShowGlobalAdventure();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private bool _anim;
|
|||
|
|
|||
|
private IEnumerator doAnim()
|
|||
|
{
|
|||
|
_anim = true;
|
|||
|
yield return null;
|
|||
|
|
|||
|
var target = _slider.value + Random.value * 0.6f;
|
|||
|
|
|||
|
while (true)
|
|||
|
{
|
|||
|
_slider.value += 0.05f;
|
|||
|
if (_slider.value >= 1f)
|
|||
|
{
|
|||
|
target -= 1f;
|
|||
|
_slider.value = 0f;
|
|||
|
}
|
|||
|
|
|||
|
if (_slider.value >= target)
|
|||
|
{
|
|||
|
_slider.value = target;
|
|||
|
break;
|
|||
|
}
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
|
|||
|
_anim = false;
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
_btnAdd.onClick.AddListener(this.OnAddBtnClick);
|
|||
|
_slider = GetComponent<Slider>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
_anim = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
partial class LevelUnlockBox
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goLevel;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpName;
|
|||
|
[KUIFlag]
|
|||
|
Image _imgFigure;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnBg;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnCollect;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listReward;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _tmpHint;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goReward;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goFunction;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpFunctionName;
|
|||
|
[KUIFlag]
|
|||
|
Image _imgFunctionIcon;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
RadarChart _goRadarChart;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listAttr;
|
|||
|
[KUIFlag]
|
|||
|
|
|||
|
GameObject _goFunctionAnimation;
|
|||
|
[KUIFlag]
|
|||
|
Image _imgFunctionMove;
|
|||
|
[KUIFlag]
|
|||
|
Image _imgFunctionAnimation;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpFunctionDescribe;
|
|||
|
[KUIFlag]
|
|||
|
Animation _imgBG_01;
|
|||
|
[KUIFlag]
|
|||
|
Animation _imgBG_02;
|
|||
|
[KUIFlag]
|
|||
|
Animation _tmpCloseTip;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnStartMove;
|
|||
|
[KUIFlag]
|
|||
|
Animation _imgFunction_UnlockPanle;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goEffectsOne;
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void InitView()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
__listReward.AddTemplate<PropWidget>(true);
|
|||
|
_btnBg.onClick.AddListener(this.OnCloseBtnClick);
|
|||
|
_btnCollect.onClick.AddListener(this.OnCollectBtnClick);
|
|||
|
//_btnStartMove.onClick.AddListener(this.OnStartMoveBtnClick);
|
|||
|
|
|||
|
__listAttr.AddTemplate<JobWidget>();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void RefreshView()
|
|||
|
{
|
|||
|
_btnBg.gameObject.SetActive(true);
|
|||
|
if (this.data is ItemLevel levelItem)
|
|||
|
{
|
|||
|
__listReward.gameObject.SetActive(true);
|
|||
|
__listReward.Clear();
|
|||
|
if (levelItem.rewardInfos != null && levelItem.rewardInfos.Length > 0)
|
|||
|
{
|
|||
|
_btnCollect.gameObject.SetActive(true);
|
|||
|
_btnBg.interactable = false;
|
|||
|
_goReward.SetActive(true);
|
|||
|
_tmpHint.SetActive(false);
|
|||
|
|
|||
|
for (int i = 0; i < levelItem.rewardInfos.Length; i++)
|
|||
|
{
|
|||
|
__listReward.GetItem<PropWidget>().SetItem(levelItem.rewardInfos[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_btnCollect.gameObject.SetActive(false);
|
|||
|
_btnBg.interactable = true;
|
|||
|
_goReward.SetActive(false);
|
|||
|
_tmpHint.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
var function = FunctionProxy.Instance.CheckNew();
|
|||
|
if (function == null)
|
|||
|
{
|
|||
|
__listReward.gameObject.SetActive(true);
|
|||
|
_goFunctionAnimation.SetActive(false);
|
|||
|
_goFunction.SetActive(false);
|
|||
|
_goLevel.SetActive(true);
|
|||
|
_tmpName.text = levelItem.name;
|
|||
|
if (!string.IsNullOrEmpty(levelItem.figure))
|
|||
|
{
|
|||
|
StartCoroutine(SetFigure(levelItem.chapter.atlas, levelItem.figure));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_imgFigure.overrideSprite = null;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goLevel.SetActive(false);
|
|||
|
//_goFunction.SetActive(true);
|
|||
|
|
|||
|
//_tmpFunctionName.text = function.lockText;
|
|||
|
//IconProxy.Instance.SetSprite(_imgFunctionIcon, function.icon);
|
|||
|
|
|||
|
StartCoroutine(PlayFunctionUnlockAnimation(function));//新增新功能开启动画
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#if UNITY_EDITOR && !UNITY_WEBGL
|
|||
|
if (KGMOptions.Instance.自动挂机)
|
|||
|
{
|
|||
|
StartCoroutine(AutoGame());
|
|||
|
}
|
|||
|
#endif
|
|||
|
//RefreshJobs();
|
|||
|
}
|
|||
|
private IEnumerator PlayFunctionUnlockAnimation(FunctionProxy.Function function)//功能开启动画
|
|||
|
{
|
|||
|
//关闭非解锁新功能界面
|
|||
|
_goFunction.SetActive(false);
|
|||
|
__listReward.gameObject.SetActive(false);
|
|||
|
_btnCollect.gameObject.SetActive(false);
|
|||
|
_goReward.SetActive(false);
|
|||
|
_btnBg.gameObject.SetActive(false);
|
|||
|
//解锁新功能动画控制
|
|||
|
_goFunctionAnimation.SetActive(true);
|
|||
|
_btnStartMove.gameObject.SetActive(false);
|
|||
|
_tmpFunctionDescribe.text = function.item.describe;
|
|||
|
_imgFunctionMove.gameObject.SetActive(false);
|
|||
|
IconProxy.Instance.SetSprite(_imgFunctionAnimation, function.icon);
|
|||
|
IconProxy.Instance.SetSprite(_imgFunctionMove, function.icon);
|
|||
|
_imgFunctionMove.GetComponent<RectTransform>().sizeDelta = new Vector2(210, 210);
|
|||
|
_imgFunctionAnimation.gameObject.SetActive(true);
|
|||
|
StartCoroutine(PlayUnlockEffectsOne());//水墨特效1
|
|||
|
_imgFunctionMove.transform.GetChild(0).gameObject.SetActive(false);//水墨特效2
|
|||
|
_imgBG_01.transform.GetChild(0).gameObject.SetActive(true);//背景特效
|
|||
|
|
|||
|
yield return new WaitForSeconds(1.5f);
|
|||
|
|
|||
|
var aniDes = _tmpFunctionDescribe.transform.GetComponent<Animation>();
|
|||
|
aniDes["Function_Describe"].speed = 0;
|
|||
|
_imgBG_01["FunctionBG_01"].speed = 0;
|
|||
|
_imgBG_02["FunctionBG_02"].speed = 0;
|
|||
|
_tmpCloseTip["Function_Describe"].speed = 0;
|
|||
|
_imgFunction_UnlockPanle["Function_UnlockPanle"].speed = 0;
|
|||
|
|
|||
|
_imgFunctionMove.transform.GetComponent<RectTransform>().position = _imgFunctionAnimation.transform.GetComponent<RectTransform>().position;
|
|||
|
_btnStartMove.gameObject.SetActive(true);
|
|||
|
_imgFunctionMove.gameObject.SetActive(true);
|
|||
|
_imgFunctionAnimation.gameObject.SetActive(false);
|
|||
|
_btnStartMove.onClick.RemoveAllListeners();
|
|||
|
_btnStartMove.onClick.AddListener(() => { PlayFunctionUnlock(function); });
|
|||
|
|
|||
|
}
|
|||
|
private IEnumerator PlayUnlockEffectsOne()//水墨特效1
|
|||
|
{
|
|||
|
_goEffectsOne.SetActive(false);
|
|||
|
yield return new WaitForSeconds(0.26f);
|
|||
|
_goEffectsOne.SetActive(true);
|
|||
|
}
|
|||
|
private IEnumerator EndPlayDelay()//关闭延迟
|
|||
|
{
|
|||
|
_imgFunctionMove.transform.GetChild(0).gameObject.SetActive(true);
|
|||
|
yield return new WaitForSeconds(0.45f);
|
|||
|
_goFunctionAnimation.SetActive(false);
|
|||
|
ConcealGetBtnClick();
|
|||
|
}
|
|||
|
private void PlayFunctionUnlock(FunctionProxy.Function function)//功能开启动画
|
|||
|
{
|
|||
|
var ani = _tmpFunctionDescribe.transform.GetComponent<Animation>();
|
|||
|
ani["Function_Describe"].speed = 1;
|
|||
|
_imgBG_01["FunctionBG_01"].speed = 1;
|
|||
|
_imgBG_02["FunctionBG_02"].speed = 1;
|
|||
|
_tmpCloseTip["Function_Describe"].speed = 1;
|
|||
|
_imgFunction_UnlockPanle["Function_UnlockPanle"].speed = 1;
|
|||
|
_btnStartMove.gameObject.SetActive(false);
|
|||
|
_imgBG_01.transform.GetChild(0).gameObject.SetActive(false);//背景特效
|
|||
|
|
|||
|
var btnG = GameObject.Find(function.item.button);//查找目标
|
|||
|
if (btnG)
|
|||
|
{
|
|||
|
var RT = btnG.transform as RectTransform;
|
|||
|
var screenPoint = RectTransformUtility.WorldToScreenPoint(KUIRoot.RootCamera, RT.position);
|
|||
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)this.transform, screenPoint, KUIRoot.RootCamera, out var localPoint))
|
|||
|
{
|
|||
|
_imgFunctionMove.GetComponent<RectTransform>().DOAnchorPos(localPoint, 1.25f).SetEase(Ease.InQuint)
|
|||
|
.OnUpdate(() =>
|
|||
|
{
|
|||
|
|
|||
|
})
|
|||
|
.OnComplete(() =>
|
|||
|
{
|
|||
|
StartCoroutine(EndPlayDelay());
|
|||
|
});
|
|||
|
if (function.id == FunctionProxy.FunctionId.产业)
|
|||
|
{
|
|||
|
_imgFunctionMove.GetComponent<RectTransform>().DOSizeDelta(new Vector2(265,245), 1f).SetEase(Ease.InQuint);
|
|||
|
}
|
|||
|
if (function.id == FunctionProxy.FunctionId.解锁武林大会功能)
|
|||
|
{
|
|||
|
_imgFunctionMove.GetComponent<RectTransform>().DOSizeDelta(RT.sizeDelta, 1f).SetEase(Ease.InQuint);
|
|||
|
}
|
|||
|
if (function.id == FunctionProxy.FunctionId.Jingjie)
|
|||
|
{
|
|||
|
_imgFunctionMove.GetComponent<RectTransform>().DOSizeDelta(RT.sizeDelta, 1f).SetEase(Ease.InQuint);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goFunctionAnimation.SetActive(false);
|
|||
|
ConcealGetBtnClick();
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goFunctionAnimation.SetActive(false);
|
|||
|
ConcealGetBtnClick();
|
|||
|
}
|
|||
|
}
|
|||
|
private void ConcealGetBtnClick()//隐式领取通关奖励
|
|||
|
{
|
|||
|
if (this.data is ItemLevel levelItem)
|
|||
|
{
|
|||
|
RewardProxy.Instance.GetRewards(levelItem.rewardInfos);
|
|||
|
}
|
|||
|
CloseWindow(this);
|
|||
|
PostNotification(GlobalDefine.EVENT_WINDOW_CLOSED, "", nameof(RewardWindow));
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator SetFigure(string atlas, string figure)
|
|||
|
{
|
|||
|
var handle = AssetProxy.Instance.TryGetGlobalAssetAsync<UnityEngine.U2D.SpriteAtlas>(atlas);
|
|||
|
yield return handle;
|
|||
|
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
|
|||
|
{
|
|||
|
_imgFigure.gameObject.SetActive(true);
|
|||
|
_imgFigure.overrideSprite = handle.Result.GetSprite(figure);
|
|||
|
_imgFigure.SetNativeSize();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_imgFigure.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void RefreshJobs()
|
|||
|
{
|
|||
|
var ratio = _goRadarChart.radio;
|
|||
|
for (int i = 0; i < ratio.Length; i++)
|
|||
|
{
|
|||
|
ratio[i] = Random.Range(0.6f, 0.8f);
|
|||
|
}
|
|||
|
|
|||
|
__listAttr.Clear();
|
|||
|
var jobItems = ItemProxy.Instance.GetStaticItems<ItemChaJob>();
|
|||
|
for (int i = 0; i < jobItems.Count; i++)
|
|||
|
{
|
|||
|
__listAttr.GetItem().SetData(jobItems[i]);
|
|||
|
}
|
|||
|
_goRadarChart.InitHandlers();
|
|||
|
}
|
|||
|
|
|||
|
private void OnCollectBtnClick()
|
|||
|
{
|
|||
|
if (this.data is ItemLevel levelItem)
|
|||
|
{
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(levelItem.rewardInfos, (error, message) =>
|
|||
|
{
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
#if UNITY_IOS
|
|||
|
RateBox.AppRatingByLevel(levelItem.id);
|
|||
|
#endif
|
|||
|
});
|
|||
|
}
|
|||
|
CloseWindow(this);
|
|||
|
}
|
|||
|
|
|||
|
private void OnCloseBtnClick()
|
|||
|
{
|
|||
|
CloseWindow(this);
|
|||
|
}
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
|
|||
|
private System.Collections.IEnumerator AutoGame()
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(1f);
|
|||
|
OnCollectBtnClick();
|
|||
|
}
|
|||
|
|
|||
|
#endif
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|