Skip to content

Commit

Permalink
fixed #378 + fixed clear cache bug
Browse files Browse the repository at this point in the history
fixed #378 + fixed clear cache bug
  • Loading branch information
JasonXuDeveloper authored Jul 31, 2022
2 parents b158147 + 6b6124f commit 158a729
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 76 deletions.
8 changes: 4 additions & 4 deletions UnityProject/Assets/Init.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1051,15 +1051,15 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_MethodName: Clear
m_Mode: 1
- m_Target: {fileID: 964396229}
m_MethodName: ClearPackageForButton
m_Mode: 5
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_StringArgument: Main
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1277094936
Expand Down
3 changes: 3 additions & 0 deletions UnityProject/Assets/Scripts/Core.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions UnityProject/Assets/Scripts/Core/BaseUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

public class BaseUpdater : IUpdater
{
public Action<string> onMessage;
public void OnMessage(string msg)
{
onMessage?.Invoke(msg);
}

public Action<float> onProgress;
public void OnProgress(float progress)
{
onProgress?.Invoke(progress);
}

public Action<string> onVersion;
public void OnVersion(string ver)
{
onVersion?.Invoke(ver);
}

public Action<float> onLoadSceneProgress;
public void OnLoadSceneProgress(float progress)
{
onLoadSceneProgress?.Invoke(progress);
}

public Action onLoadSceneFinish;
public void OnLoadSceneFinish()
{
onLoadSceneFinish?.Invoke();
}

public Action onUpdateFailed;
public void OnUpdateFailed()
{
onUpdateFailed?.Invoke();
}


public BaseUpdater(Action<string> onMessage, Action<float> onProgress, Action<string> onVersion, Action<float> onLoadSceneProgress, Action onLoadSceneFinish, Action onUpdateFailed)
{
this.onMessage = onMessage;
this.onProgress = onProgress;
this.onVersion = onVersion;
this.onLoadSceneProgress = onLoadSceneProgress;
this.onLoadSceneFinish = onLoadSceneFinish;
this.onUpdateFailed = onUpdateFailed;
}
}
3 changes: 3 additions & 0 deletions UnityProject/Assets/Scripts/Core/BaseUpdater.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions UnityProject/Assets/Scripts/Core/IUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public interface IUpdater
{
void OnMessage(string msg);

void OnProgress(float progress);

void OnVersion(string ver);

void OnLoadSceneProgress(float progress);

void OnLoadSceneFinish();

void OnUpdateFailed();
}
3 changes: 3 additions & 0 deletions UnityProject/Assets/Scripts/Core/IUpdater.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using UnityEngine.Serialization;
using AppDomain = ILRuntime.Runtime.Enviorment.AppDomain;

public class InitJEngine : MonoBehaviour
public partial class InitJEngine : MonoBehaviour
{
//单例
public static InitJEngine Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,7 @@
using JEngine.Core;
using UnityEngine;

public interface IUpdater
{
void OnMessage(string msg);

void OnProgress(float progress);

void OnVersion(string ver);

void OnLoadSceneProgress(float progress);

void OnLoadSceneFinish();

void OnUpdateFailed();
}

public class BaseUpdater : IUpdater
{
public Action<string> onMessage;
public void OnMessage(string msg)
{
onMessage?.Invoke(msg);
}

public Action<float> onProgress;
public void OnProgress(float progress)
{
onProgress?.Invoke(progress);
}

public Action<string> onVersion;
public void OnVersion(string ver)
{
onVersion?.Invoke(ver);
}

public Action<float> onLoadSceneProgress;
public void OnLoadSceneProgress(float progress)
{
onLoadSceneProgress?.Invoke(progress);
}

public Action onLoadSceneFinish;
public void OnLoadSceneFinish()
{
onLoadSceneFinish?.Invoke();
}

public Action onUpdateFailed;
public void OnUpdateFailed()
{
onUpdateFailed?.Invoke();
}


public BaseUpdater(Action<string> onMessage, Action<float> onProgress, Action<string> onVersion, Action<float> onLoadSceneProgress, Action onLoadSceneFinish, Action onUpdateFailed)
{
this.onMessage = onMessage;
this.onProgress = onProgress;
this.onVersion = onVersion;
this.onLoadSceneProgress = onLoadSceneProgress;
this.onLoadSceneFinish = onLoadSceneFinish;
this.onUpdateFailed = onUpdateFailed;
}
}

public class Updater : MonoBehaviour
public partial class Updater : MonoBehaviour
{
[SerializeField] private string baseURL = "http://127.0.0.1:7888/DLC/";
[SerializeField] private string gameScene = "Assets/HotUpdateResources/Scene/Game.unity";
Expand Down Expand Up @@ -200,7 +135,7 @@ async void ONComplete(MessageBox.EventId ok)
{
updater.OnMessage(
$"下载中...{Tools.GetDisplaySpeed(package.DownLoadSpeed)}, 进度:{Math.Round(progress, 2)}%");
updater.OnProgress(package.Progress / 100f);
updater.OnProgress(progress / 100f);
};
await AssetComponent.DownLoadUpdate(package);
Init();
Expand Down Expand Up @@ -264,27 +199,74 @@ public static void UpdatePackage(string bundlePackageName, bool checkCRC = true,
/// <param name="bundlePackageName"></param>
public static void ClearPackage(string bundlePackageName)
{
var dir = Path.Combine(Application.persistentDataPath, "bundlePackageName");
if(Directory.Exists(dir))
var mb = MessageBox.Show("提示", "确定要删除缓存吗");

void ONComplete(MessageBox.EventId ok)
{
Directory.Delete(dir);
if (ok == MessageBox.EventId.Ok)
{
var dir = Path.Combine(Application.persistentDataPath, bundlePackageName);
if(Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
}
}
mb.onComplete = ONComplete;
}

/// <summary>
/// 给按钮拖拽赋值的点击事件,删除分包
/// </summary>
/// <param name="bundlePackageName"></param>
public void ClearPackageForButton(string bundlePackageName)
{
ClearPackage(bundlePackageName);
}

/// <summary>
/// 单例
/// </summary>
private static Updater _instance;

/// <summary>
/// 更新配置
/// </summary>
private void Awake()
{
if (_instance != null)
{
DestroyImmediate(gameObject);
return;
}

Init();
}

/// <summary>
/// 初始化配置
/// </summary>
public void Init()
{
baseURL = baseURL.EndsWith("/") ? baseURL : baseURL + "/";
AssetComponentConfig.AssetLoadMode = mode;
AssetComponentConfig.BundleServerUrl = baseURL;
AssetComponentConfig.DefaultBundlePackageName = mainPackageName;
DontDestroyOnLoad(gameObject);
_instance = this;
}

/// <summary>
/// 更新
/// </summary>
private void Update()
{
//更新BM组件
AssetComponent.Update();
}

/// <summary>
/// 下载更新
/// 给按钮拖拽赋值的点击事件,下载更新,用于初始化主包
/// </summary>
public void StartUpdate()
{
Expand Down
File renamed without changes.

0 comments on commit 158a729

Please sign in to comment.