224 lines
7.4 KiB
C#
224 lines
7.4 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Thousandto.Launcher.Form;
|
|||
|
using UnityEngine;
|
|||
|
using EventManager = UnityEngine.Gonbest.MagicCube.EventManager;
|
|||
|
using CoreEventDefine = UnityEngine.Gonbest.MagicCube.CoreEventDefine;
|
|||
|
using UnityEngine.Gonbest.MagicCube;
|
|||
|
|
|||
|
namespace Thousandto.Launcher.Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 清理缓存的面板脚本
|
|||
|
/// </summary>
|
|||
|
public class UIClearCachePanelScript : MonoBehaviour
|
|||
|
{
|
|||
|
#region //UI组件
|
|||
|
private UIButton _clearBtn;
|
|||
|
private UIButton _cancelBtn;
|
|||
|
private UIProgressBar _progressBar;
|
|||
|
private GameObject _clearPanelGo;
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//私有变量
|
|||
|
//清理任务
|
|||
|
FUnityCacheCleanupTask _task = new FUnityCacheCleanupTask();
|
|||
|
FUnityUploadLogTask _uploadTask = new FUnityUploadLogTask();
|
|||
|
CleanupStatusCode _stutus = CleanupStatusCode.CS_Wait;
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region //MonoBehaviour
|
|||
|
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
OnFirstShow(transform);
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
switch (_stutus)
|
|||
|
{
|
|||
|
case CleanupStatusCode.CS_StartUpload:
|
|||
|
Debug.Log("修复客户端:请求上传日志."+MachineUUID.Value);
|
|||
|
if (!_clearPanelGo.activeSelf)
|
|||
|
{
|
|||
|
_clearPanelGo.SetActive(true);
|
|||
|
}
|
|||
|
if (!_uploadTask.IsRunning)
|
|||
|
{
|
|||
|
_uploadTask.Start();
|
|||
|
_stutus = CleanupStatusCode.CS_Uploading;
|
|||
|
}
|
|||
|
break;
|
|||
|
case CleanupStatusCode.CS_Uploading:
|
|||
|
if (_uploadTask.IsRunning)
|
|||
|
{
|
|||
|
_progressBar.value = _uploadTask.Progress;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_stutus = CleanupStatusCode.CS_UploadFinished;
|
|||
|
}
|
|||
|
break;
|
|||
|
case CleanupStatusCode.CS_UploadFinished:
|
|||
|
_clearPanelGo.SetActive(false);
|
|||
|
_stutus = CleanupStatusCode.CS_Start;
|
|||
|
break;
|
|||
|
case CleanupStatusCode.CS_Start:
|
|||
|
Debug.Log("修复客户端:请求客户端修复操作!");
|
|||
|
if (!_clearPanelGo.activeSelf)
|
|||
|
{
|
|||
|
_clearPanelGo.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
if (!_task.IsRunning)
|
|||
|
{
|
|||
|
_task.IsRunning = true;
|
|||
|
CoroutinePool.AddTask(_task);
|
|||
|
}
|
|||
|
_stutus = CleanupStatusCode.CS_Running;
|
|||
|
break;
|
|||
|
case CleanupStatusCode.CS_Running:
|
|||
|
if (_task.IsRunning)
|
|||
|
{
|
|||
|
_progressBar.value = _task.ClearupProgress;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_stutus = CleanupStatusCode.CS_Finished;
|
|||
|
}
|
|||
|
break;
|
|||
|
case CleanupStatusCode.CS_Finished:
|
|||
|
_stutus = CleanupStatusCode.CS_Wait;
|
|||
|
_clearPanelGo.SetActive(false);
|
|||
|
ShowMessage(LauncherStringDefine.ASK_QUIT_GAME, LauncherStringDefine.OK,null, x =>
|
|||
|
{
|
|||
|
Debug.LogError("修复客户端后,没有找到重启游戏消息,退出游戏!");
|
|||
|
Application.Quit();
|
|||
|
});
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//公共函数
|
|||
|
public void DoStart()
|
|||
|
{
|
|||
|
//开始的时候清空进度条进度
|
|||
|
_progressBar.value = 0;
|
|||
|
_stutus = CleanupStatusCode.CS_Start;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//私有方法
|
|||
|
//初始化UI
|
|||
|
private void OnFirstShow(Transform trans)
|
|||
|
{
|
|||
|
//处理清理按钮
|
|||
|
var clearBtnTrans = trans.Find("Enter/DoClearBtn");
|
|||
|
if (clearBtnTrans != null)
|
|||
|
{
|
|||
|
_clearBtn = trans.Find("Enter/DoClearBtn").GetComponent<UIButton>();
|
|||
|
}
|
|||
|
|
|||
|
_cancelBtn = trans.Find("Content/CancelBtn").GetComponent<UIButton>();
|
|||
|
_progressBar = trans.Find("Content/Progress").GetComponent<UIProgressBar>();
|
|||
|
_clearPanelGo = trans.Find("Content").gameObject;
|
|||
|
|
|||
|
if (clearBtnTrans != null)
|
|||
|
{
|
|||
|
_clearBtn.onClick.Clear();
|
|||
|
_clearBtn.onClick.Add(new EventDelegate(OnClickClearBtn));
|
|||
|
}
|
|||
|
|
|||
|
_cancelBtn.onClick.Clear();
|
|||
|
_cancelBtn.onClick.Add(new EventDelegate(OnClickCancelBtn));
|
|||
|
|
|||
|
_progressBar.value = 0;
|
|||
|
_clearPanelGo.SetActive(false);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//点击清理按钮
|
|||
|
private void OnClickClearBtn()
|
|||
|
{
|
|||
|
ShowMessage(LauncherStringDefine.ASK_NEED_CLIENT_REPIRE, LauncherStringDefine.CANCEL, LauncherStringDefine.OK, x =>
|
|||
|
{
|
|||
|
if (x == 2)
|
|||
|
{
|
|||
|
ShowMessage(LauncherStringDefine.ASK_NEED_UPLOAD_LOG, LauncherStringDefine.CANCEL, LauncherStringDefine.OK, y =>
|
|||
|
{
|
|||
|
if (y == 2)
|
|||
|
{
|
|||
|
_stutus = CleanupStatusCode.CS_StartUpload;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_stutus = CleanupStatusCode.CS_Start;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
//点击取消按钮
|
|||
|
private void OnClickCancelBtn()
|
|||
|
{
|
|||
|
ShowMessage(LauncherStringDefine.ASK_CANCEL_CLIENT_REPIRE, LauncherStringDefine.CANCEL, LauncherStringDefine.OK, x =>
|
|||
|
{
|
|||
|
if (x == 2)
|
|||
|
{
|
|||
|
if (_stutus == CleanupStatusCode.CS_Uploading)
|
|||
|
{
|
|||
|
_stutus = CleanupStatusCode.CS_UploadFinished;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_stutus = CleanupStatusCode.CS_Finished;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//提示消息的函数
|
|||
|
private void ShowMessage(string msg, string btn1Str, string btn2Str, Action<int> callBackAction = null)
|
|||
|
{
|
|||
|
if (UILauncherMainForm.Instance != null)
|
|||
|
{
|
|||
|
UILauncherMainForm.Instance.ShowMessage(msg, btn1Str, btn2Str, callBackAction);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
EventManager.SharedInstance.PushFixEvent(CoreEventDefine.EID_CORE_GLOBAL_SHOW_MESSAGE_BOX, new object[] { "ShowMsgBox", msg, btn1Str, btn2Str, callBackAction });
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//子类
|
|||
|
//清理状态
|
|||
|
private enum CleanupStatusCode
|
|||
|
{
|
|||
|
//等待处理的消息
|
|||
|
CS_Wait,
|
|||
|
//开始上传日志
|
|||
|
CS_StartUpload,
|
|||
|
//正在上传日志
|
|||
|
CS_Uploading,
|
|||
|
//上传日志完毕
|
|||
|
CS_UploadFinished,
|
|||
|
//开始进行修复
|
|||
|
CS_Start,
|
|||
|
//正在修复
|
|||
|
CS_Running,
|
|||
|
//修复完毕!
|
|||
|
CS_Finished,
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|