Files
Zoomatch_unity_ios/Assets/Scripts/ModuleUI/WebView/H5UI.cs
T
2026-05-28 15:23:36 +08:00

555 lines
18 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FutureCore;
using FairyGUI;
using FGUI.ZM_H5_15;
using DG.Tweening;
using System.Linq;
using System;
using IgnoreOPS;
// using IgnoreOPS;
namespace ZooMatch
{
public class H5UI : BaseUI
{
private H5UICtrl ctrl;
private H5Model model;
public FGUI.ZM_H5_15.com_webview ui;
private Action closeCallBack;
public H5UI(H5UICtrl ctrl) : base(ctrl)
{
uiName = UIConst.H5UI;
this.ctrl = ctrl;
}
bool isScrolling;
private bool isTimeOut = false;
private decimal scrollOutTime;
private bool isLoadFinish;
private bool isCurrentTaskFinish;
private bool isCurrentTimeTask;
private bool isAddFinger;
private long openTime;
private int iconClickCount;
private int flyClickCount;
private int flyNeedClickCount = 0;
private int currentTabIndex;
private decimal makeupTaskH5NeedTime;
private Tween bubbleMoveTween;
private List<Vector3> movePointList = new List<Vector3>();
//private CountDownKit countDownKit;
private int sendH5point = 0;
private SaveingPotClass saveing_makeupTaskData;
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "ZM_H5_15";
uiInfo.assetName = "com_webview";
uiInfo.layerType = UILayerType.Popup;
uiInfo.isNeedOpenAnim = false;
uiInfo.isNeedCloseAnim = false;
uiInfo.isNeedUIMask = true;
uiInfo.isTickUpdate = true;
}
#region 生命周期
protected override void OnInit()
{
//model = ModuleManager.Instance.GetModel(ModelConst.H5Model) as H5Model;
}
public Tween delayedCall;
protected override void OnClose()
{
//WebThroughUtil.WebThroughDisable(H5WebThroughType.OnlineH5, ui.btn_icon);
//HallManager.Instance.SetInH5(false);
// StopFly();
// countDownKit?.OnDestroy();
OnStatisticH5Time();
GameDispatcher.Instance.Dispatch(GameMsg.showBroadCast);
delayedCall.Kill();
WebviewManager.Instance.setInH5View(false);
WebviewManager.Instance.ShowH5View(false);
if (GameHelper.is_first_login)
{
// UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.RainPlayUI_Open, true);
GameHelper.is_first_login = false;
}
}
private void OnStatisticH5Time()
{
var time = GameHelper.GetNowTime() - openTime;
PreferencesMgr.Instance.H5StayTime += (int)time;
}
protected override void OnBind()
{
ui = baseUI as FGUI.ZM_H5_15.com_webview;
}
protected override void OnOpenBefore(object args)
{
saveing_makeupTaskData = SaveData.GetSaveobject().saveingpot_history[SaveData.GetSaveobject().saveingpot_history.Count - 1];
if (Screen.safeArea.y != 0)
{//刘海屏
// ui.com_top.y += Screen.safeArea.y;
// ui.btn_out.y += Screen.safeArea.y;
// ui.btn_close.y += Screen.safeArea.y;
}
if (!GameHelper.IsGiftSwitch() && GameHelper.GetCommonModel().WVswitch == 1)
{
ui.com_top.conect.visible = false;
ui.btn_out.visible = false;
}
WebviewManager.Instance.setInH5View(true);
// delayedCall = DOVirtual.DelayedCall(0.3f, () =>
// {
WebviewManager.Instance.ShowH5View(true);
// });
InitData();
InitView();
GameDispatcher.Instance.Dispatch(GameMsg.hideBroadCast);
// if (!GameHelper.IsGiftSwitch())
// {
// ui.com_top.visible = ui.btn_out.visible = false;
// }
}
protected override void OnOpen(object args)
{
openTime = GameHelper.GetNowTime();
}
protected override void OnHide()
{
}
protected override void OnDisplay(object args)
{
}
#endregion
#region 消息
protected override void AddListener()
{
//UICtrlDispatcher.Instance.AddListener(SkinInfo.MakeupConfirmUI_Close, SetMakeup);
GameDispatcher.Instance.AddListener(GameMsg.RefreshMakeupData, SetMakeup);
GameDispatcher.Instance.AddListener(GameMsg.resetH5progress, resetTime);
GameDispatcher.Instance.AddListener(GameMsg.Update102, SetMakeup);
}
protected override void RemoveListener()
{
//UICtrlDispatcher.Instance.RemoveListener(UICtrlMsg.MakeupConfirmUI_Close, SetMakeup);
GameDispatcher.Instance.RemoveListener(GameMsg.RefreshMakeupData, SetMakeup);
GameDispatcher.Instance.RemoveListener(GameMsg.resetH5progress, resetTime);
GameDispatcher.Instance.RemoveListener(GameMsg.Update102, SetMakeup);
}
#endregion
void resetTime(object a = null)
{
iconTime = 0;
}
decimal iconTime = 0;
private decimal updateTime;
public override void OnUpdate()
{
if (iconTime < ConfigSystem.GetConfig<CommonModel>().ThroughRewardCD)
{
iconTime += (decimal)Time.deltaTime;
UpdateIcon();
}
CheckShowFly();
updateTime += (decimal)Time.deltaTime;
// if (makeupTaskH5NeedTime > 0 && PreferencesMgr.Instance.MakeupTaskH5Time < makeupTaskH5NeedTime)
// {
if (updateTime >= 1)
{
#if UNITY_EDITOR
updateTime = 600;
#endif
if (PreferencesMgr.Instance.MakeupTaskH5Time > 60 &&
((PreferencesMgr.Instance.MakeupTaskH5Time % 60) < 1))
{
// NetworkKit.BuriedPoint(BuriedPointEvent.h5_event, BuriedPointEvent.h5_event_time, 60);
}
if (sendH5point == 1)
{
PlayerPrefs.SetInt("sendH5point", 0);
sendH5point = 0;
}
PreferencesMgr.Instance.MakeupTaskH5Time += updateTime;
// Debug.Log(PreferencesMgr.Instance.MakeupTaskH5Time);
if (saveing_makeupTaskData.status == SaveingPotTaskStatus.None)
{
if (PreferencesMgr.Instance.ExchangeAccount != null)
{
saveing_makeupTaskData.H5Time += (float)updateTime;
}
}
updateTime = 0;
}
// }
// else if (makeupTaskH5NeedTime > 0 && PreferencesMgr.Instance.MakeupTaskH5Time >= makeupTaskH5NeedTime)
// {
// if (sendH5point == 0)
// {
// NetworkKit.BuriedPoint(BuriedPointEvent.h5_event, BuriedPointEvent.h5_event_numbers, 1);
// sendH5point = 1;
// PlayerPrefs.SetInt("sendH5point", 1);
// }
// }
}
//初始化页面逻辑
private void InitData()
{
// model.show101 = PreferencesMgr.Instance.Currency101;
flyNeedClickCount = UnityEngine.Random.Range(ConfigSystem.GetConfig<CommonModel>().flyAdTime[0],
ConfigSystem.GetConfig<CommonModel>().flyAdTime[1] + 1);
//flyNeedClickCount = 5;
// if (PreferencesMgr.Instance.MakeupTaskHistory.Count > 0)
// {
// var taskData = PreferencesMgr.Instance.MakeupTaskHistory.Last();
// if (taskData != null)
// {
// Makeup makeupVo = null;
// foreach (var makeup in ConfigSystem.GetConfig<MakeupModel>().dataList)
// {
// if (makeup.id == taskData.tableId)
// {
// makeupVo = makeup;
// break;
// }
// }
// makeupTaskH5NeedTime = makeupVo.task_need;
// }
// }
sendH5point = PlayerPrefs.GetInt("sendH5point", 0);
#if UNITY_EDITOR
isLoadFinish = true;
#endif
}
private void InitView()
{
// InitIcon();
// CheckShowFly();
// ui.com_fly.SetClick(OnClickFlyCash);
// #endif
// SetMakeup();
ui.btn_close.SetClick(() =>
{
CtrlCloseUI();
});
SetMakeup();
WebviewManager.Instance.ShowFlyBtn(true);
UpdateIcon();
}
private void UpdateIcon()
{
float amount = (float)iconTime / ConfigSystem.GetConfig<CommonModel>().ThroughRewardCD;
WebviewManager.Instance.SetIconProgress(amount);
// if (iconTime >= ConfigSystem.GetConfig<CommonModel>().ThroughRewardCD)
// {
// if (!ui.btn_icon.fx_ready.playing)
// {
// ui.btn_icon.fx_ready.Play();
// }
// ui.btn_icon.cont_state.selectedIndex = btn_icon.State_ready;
// }
// else
// {
// ui.btn_icon.fx_ready.Stop();
// }
}
private void OnClickIcon()
{
//WebThroughUtil.WebThroughClick(H5WebThroughType.OnlineH5, ui.btn_icon);
if (iconTime < ConfigSystem.GetConfig<CommonModel>().ThroughRewardCD)
{
return;
}
#if UNITY_IOS && !UNITY_EDITOR
WebviewManager.Instance.ShowH5View(false);
#endif
float[] cash_array = GameHelper.GetRewardValue(2);
// var temp = new { is_success = true, cash_number = cash_array[0], rate = cash_array[1], is_level_success = false, is_h5_reward = true };
SuccessData temp = new SuccessData();
temp.IsWin = true;
temp.cash_number = cash_array[0];
temp.rate = (int)cash_array[1];
temp.IsLevelSuccess = false;
temp.IsH5Reward = true;
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LevelSuccessUI_Open, temp);
//UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.RewardUI_Open);
// var rewardData = new RewardData();
// var rewardType = 111;
// decimal rewardValue = (decimal)GameHelper.GetRewardValue(3)[0];
// var rewardSingleData = new RewardSingleData(rewardType, rewardValue, RewardOrigin.H5Icon)
// {
// startPosition = GameHelper.GetUICenterPosition(ui.btn_icon),
// endPosition = GameHelper.GetUICenterPosition(ui.com_top.text_num)
// };
// rewardData.AddReward(rewardSingleData);
// rewardData.AddCompleted(isSuccess =>
// {
// ui.btn_icon.cont_state.selectedIndex = btn_icon.State_none;
// iconTime = 0;
// SetMakeup();
// });
// rewardData.condition = RewardCondition.AD;
// rewardData.displayType =
// RewardDisplayType.Dialog | RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
// GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
// GameHelper.addMoney((float)rewardValue);
// GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
// GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
iconTime = 0;
// SetMakeup();
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_get_number, 1);
}
private void CheckShowFly()
{
var nowTime = GameHelper.GetNowTime();
var leftTime = (int)(PreferencesMgr.Instance.AdCashFlyShowTime - nowTime);
ui.com_fly.visible = false;
ui.com_fly.visible = leftTime <= 0;
if (leftTime > 0)
{
WebviewManager.Instance.ShowFlyBtn(false);
isFlyShow = false;
}
else
{
//StartFly();
if (!isFlyShow) WebviewManager.Instance.ShowFlyBtn(true);
isFlyShow = true;
}
}
private bool isFlyShow = false;
private void StartFly()
{
var bubbleGo = ui.com_fly.displayObject.gameObject;
bubbleMoveTween = bubbleGo.transform
.DOLocalPath(movePointList.ToArray(), 10)
.SetEase(Ease.Linear)
.OnComplete(StartFly)
.SetAutoKill(true);
}
private void OnClickFlyCash()
{
PreferencesMgr.Instance.AdCashFlyShowTime =
GameHelper.GetNowTime() + ConfigSystem.GetConfig<CommonModel>().flyCD;
var rewardData = new RewardData();
var singleValue =
(decimal)Math.Round(
UnityEngine.Random.Range(ConfigSystem.GetConfig<CommonModel>().flyReward[0],
ConfigSystem.GetConfig<CommonModel>().flyReward[1]), 2);
decimal rewardValue;
if (flyClickCount >= flyNeedClickCount)
{
flyClickCount = -1;
//var rate = GameHelper.GetVideoRate();
rewardValue = singleValue;
GameHelper.ShowVideoAd("reward_fly", isCompleted =>
{
if (isCompleted)
{
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
}
});
}
else
{
rewardValue = singleValue;
}
var startPosition = GameHelper.GetUICenterPosition(ui.com_fly);
var endPosition = GameHelper.GetUICenterPosition(ui.com_top.text_num);
var rewardSingleData = new RewardSingleData(102, rewardValue, RewardOrigin.H5Fly101)
{
startPosition = startPosition,
endPosition = new Vector2(endPosition.x - 150, endPosition.y - 106)
};
rewardData.AddReward(rewardSingleData);
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
rewardData.AddCompleted(isSuccess =>
{
if (isSuccess)
{
flyClickCount++;
}
SetMakeup();
});
//GameHelper.addMoney((float)rewardValue);
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
CheckShowFly();
}
public void Set101(decimal cash = -1)
{
// if (cash < 0)
// {
// cash = PreferencesMgr.Instance.Currency102;
// }
// ui.com_top.text_num.text = "$"+ PreferencesMgr.Instance.Currency102;
}
public void OnLoadFinish()
{
isLoadFinish = true;
}
public void OnLoadH5Progress(int progress)
{
}
private void SetMakeup(object a = null)
{
var com_box = ui.com_top;
com_box.text_num.text = GameHelper.Get102Str(PreferencesMgr.Instance.Currency102);
DOVirtual.Float(0, (float)PreferencesMgr.Instance.Currency102, 1,
value => { com_box.text_num.text = GameHelper.Get102Str((decimal)value); });
if (GameHelper.IsGiftSwitch())
{
if (PreferencesMgr.Instance.MakeupTaskHistory.Count == 0)
{
return;
}
var makeupTaskData = PreferencesMgr.Instance.MakeupTaskHistory.Last();
var vo = ConfigSystem.GetConfig<MakeupModel>().GetData(makeupTaskData.tableId);
if (vo == null)
{
return;
}
var leftCash = (double)Math.Max(vo.item_need - PreferencesMgr.Instance.Currency102, 0);
com_box.text_more.SetVar("money", GameHelper.Get102Str((decimal)leftCash)).FlushVars();
com_box.pb_num.max = vo.item_need;
com_box.pb_num.TweenValue(vo.item_need - leftCash, 0.1f);
var value = Math.Min((double)PreferencesMgr.Instance.Currency102, com_box.pb_num.max);
var pbTxt = com_box.pb_num.GetChild("title");
pbTxt.text =
$"{GameHelper.Get102Str((decimal)value)}/{GameHelper.Get102Str((decimal)com_box.pb_num.max)}";
ui.btn_out.SetClick(() =>
{
#if UNITY_IOS && !UNITY_EDITOR
WebviewManager.Instance.ShowH5View(false);
#endif
// if (GameHelper.CanGuide() && !GuideCtrl.Instance.IsFinishGuide(1))
// {
// GuideCtrl.Instance.Dispatch("ClickButton");
// }
uiCtrlDispatcher.Dispatch(UICtrlMsg.MakeupConfirmUI_Open, makeupTaskData);
// MainTabUI.getIns().OnGameTab(0);
});
}
}
public void ClickBtn(string name)
{
// // Debug.Log("[UNITY] Click btn: " + name);
// FGUIHelper.PlayClickSound();
if (name == "flyBtn")
{
OnClickFlyCash();
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.collect_fly_number, 1);
//NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.collect_fly_people,1);
}
else if (name == "rewardBtn")
{
OnClickIcon();
}
}
}
}