mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交热更新
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d11821e0e1c8454f95b48b4de4f9d509
|
||||
timeCreated: 1728983038
|
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HotMain.SHGame.YooAsset.StreamingAssetsHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置资源清单
|
||||
/// </summary>
|
||||
public class BuildinFileManifest : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public class Element
|
||||
{
|
||||
public string PackageName;
|
||||
public string FileName;
|
||||
public string FileCRC32;
|
||||
}
|
||||
|
||||
public List<Element> BuildinFiles = new List<Element>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71b02dfa7aa9d4545b3417a18477fbee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace HotMain.SHGame.YooAsset.StreamingAssetsHelper
|
||||
{
|
||||
public class StreamingAssetsDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根目录名称(保持和YooAssets资源系统一致)
|
||||
/// </summary>
|
||||
public const string RootFolderName = "yoo";
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e44d691f47abe34e9deb9cb309074f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,165 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace HotMain.SHGame.YooAsset.StreamingAssetsHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IBuildinQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询内置文件的时候,是否比对文件哈希值
|
||||
/// </summary>
|
||||
public static bool CompareFileCRC = false;
|
||||
|
||||
public bool Query(string packageName, string fileName, string fileCRC)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return StreamingAssetsHelper.FileExists(packageName, fileName, fileCRC);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
public static void Init() { }
|
||||
public static bool FileExists(string packageName, string fileName, string fileCRC)
|
||||
{
|
||||
string filePath = Path.Combine(Application.streamingAssetsPath, StreamingAssetsDefine.RootFolderName, packageName, fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
if (GameQueryServices.CompareFileCRC)
|
||||
{
|
||||
string crc32 = HashUtility.FileCRC32(filePath);
|
||||
return crc32 == fileCRC;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
private class PackageQuery
|
||||
{
|
||||
public readonly Dictionary<string, BuildinFileManifest.Element> Elements = new Dictionary<string, BuildinFileManifest.Element>(1000);
|
||||
}
|
||||
|
||||
private static bool _isInit = false;
|
||||
private static readonly Dictionary<string, PackageQuery> _packages = new Dictionary<string, PackageQuery>(10);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public static void Init()
|
||||
{
|
||||
if (_isInit == false)
|
||||
{
|
||||
_isInit = true;
|
||||
|
||||
var manifest = Resources.Load<BuildinFileManifest>("BuildinFileManifest");
|
||||
if (manifest != null)
|
||||
{
|
||||
foreach (var element in manifest.BuildinFiles)
|
||||
{
|
||||
if (_packages.TryGetValue(element.PackageName, out PackageQuery package) == false)
|
||||
{
|
||||
package = new PackageQuery();
|
||||
_packages.Add(element.PackageName, package);
|
||||
}
|
||||
package.Elements.Add(element.FileName, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询方法
|
||||
/// </summary>
|
||||
public static bool FileExists(string packageName, string fileName, string fileCRC32)
|
||||
{
|
||||
if (_isInit == false)
|
||||
Init();
|
||||
|
||||
if (_packages.TryGetValue(packageName, out PackageQuery package) == false)
|
||||
return false;
|
||||
|
||||
if (package.Elements.TryGetValue(fileName, out var element) == false)
|
||||
return false;
|
||||
|
||||
if (GameQueryServices.CompareFileCRC)
|
||||
{
|
||||
return element.FileCRC32 == fileCRC32;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder { get { return 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// 在构建应用程序前处理
|
||||
/// 原理:在构建APP之前,搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入内置清单,内置清单存储在Resources文件夹下。
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
{
|
||||
string saveFilePath = "Assets/Resources/BuildinFileManifest.asset";
|
||||
if (File.Exists(saveFilePath))
|
||||
{
|
||||
File.Delete(saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
|
||||
DirectoryInfo root = new DirectoryInfo(folderPath);
|
||||
if (root.Exists == false)
|
||||
{
|
||||
Debug.LogWarning($"没有发现YooAsset内置目录 : {folderPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||
FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
|
||||
foreach (var fileInfo in files)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta")
|
||||
continue;
|
||||
if (fileInfo.Name.StartsWith("PackageManifest_"))
|
||||
continue;
|
||||
|
||||
BuildinFileManifest.Element element = new BuildinFileManifest.Element();
|
||||
element.PackageName = fileInfo.Directory.Name;
|
||||
element.FileCRC32 = HashUtility.FileCRC32(fileInfo.FullName);
|
||||
element.FileName = fileInfo.Name;
|
||||
manifest.BuildinFiles.Add(element);
|
||||
}
|
||||
|
||||
if (Directory.Exists("Assets/Resources") == false)
|
||||
Directory.CreateDirectory("Assets/Resources");
|
||||
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca0617f5ec2b4504b923e3205dc77f54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -2,7 +2,7 @@
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace Plugins.SHFrame.SHGame.YooAsset
|
||||
namespace HotMain.SHGame.YooAsset
|
||||
{
|
||||
public class RemoteServices : IRemoteServices
|
||||
{
|
||||
@@ -17,12 +17,12 @@ namespace Plugins.SHFrame.SHGame.YooAsset
|
||||
|
||||
public string GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return defaultHostServer;
|
||||
return $"{defaultHostServer}/{fileName}";
|
||||
}
|
||||
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return fallbackHostServer;
|
||||
return $"{fallbackHostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user