mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
临时提交
This commit is contained in:
53
JNFrame2/Assets/HotMain/ConsoleToScreen.cs
Normal file
53
JNFrame2/Assets/HotMain/ConsoleToScreen.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConsoleToScreen : MonoBehaviour
|
||||
{
|
||||
const int maxLines = 50;
|
||||
const int maxLineLength = 120;
|
||||
private string _logStr = "";
|
||||
|
||||
private readonly List<string> _lines = new();
|
||||
|
||||
public int fontSize = 15;
|
||||
|
||||
void OnEnable() { Application.logMessageReceived += Log; }
|
||||
void OnDisable() { Application.logMessageReceived -= Log; }
|
||||
|
||||
public void Log(string logString, string stackTrace, LogType type)
|
||||
{
|
||||
foreach (var line in logString.Split('\n'))
|
||||
{
|
||||
if (line.Length <= maxLineLength)
|
||||
{
|
||||
_lines.Add(line);
|
||||
continue;
|
||||
}
|
||||
var lineCount = line.Length / maxLineLength + 1;
|
||||
for (int i = 0; i < lineCount; i++)
|
||||
{
|
||||
if ((i + 1) * maxLineLength <= line.Length)
|
||||
{
|
||||
_lines.Add(line.Substring(i * maxLineLength, maxLineLength));
|
||||
}
|
||||
else
|
||||
{
|
||||
_lines.Add(line.Substring(i * maxLineLength, line.Length - i * maxLineLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_lines.Count > maxLines)
|
||||
{
|
||||
_lines.RemoveRange(0, _lines.Count - maxLines);
|
||||
}
|
||||
// _lines.Add(stackTrace);
|
||||
_logStr = string.Join("\n", _lines);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,
|
||||
new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));
|
||||
GUI.Label(new Rect(10, 10, 800, 370), _logStr, new GUIStyle { fontSize = 10 });
|
||||
}
|
||||
}
|
11
JNFrame2/Assets/HotMain/ConsoleToScreen.cs.meta
Normal file
11
JNFrame2/Assets/HotMain/ConsoleToScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f75d46640fcd41f49a2bc14a946c16cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
339
JNFrame2/Assets/HotMain/HotMain.unity
Normal file
339
JNFrame2/Assets/HotMain/HotMain.unity
Normal file
@@ -0,0 +1,339 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 12
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 2
|
||||
m_BakeBackend: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 256
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 1
|
||||
m_PVRDenoiserTypeDirect: 1
|
||||
m_PVRDenoiserTypeIndirect: 1
|
||||
m_PVRDenoiserTypeAO: 1
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_LightingSettings: {fileID: 0}
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 3
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
buildHeightMesh: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &790008994
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 790008996}
|
||||
- component: {fileID: 790008995}
|
||||
m_Layer: 0
|
||||
m_Name: Directional Light
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!108 &790008995
|
||||
Light:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 790008994}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 10
|
||||
m_Type: 1
|
||||
m_Shape: 0
|
||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||
m_Intensity: 1
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
m_InnerSpotAngle: 21.80208
|
||||
m_CookieSize: 10
|
||||
m_Shadows:
|
||||
m_Type: 2
|
||||
m_Resolution: -1
|
||||
m_CustomResolution: -1
|
||||
m_Strength: 1
|
||||
m_Bias: 0.05
|
||||
m_NormalBias: 0.4
|
||||
m_NearPlane: 0.2
|
||||
m_CullingMatrixOverride:
|
||||
e00: 1
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 1
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 1
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 1
|
||||
m_UseCullingMatrixOverride: 0
|
||||
m_Cookie: {fileID: 0}
|
||||
m_DrawHalo: 0
|
||||
m_Flare: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingLayerMask: 1
|
||||
m_Lightmapping: 4
|
||||
m_LightShadowCasterMode: 0
|
||||
m_AreaSize: {x: 1, y: 1}
|
||||
m_BounceIntensity: 1
|
||||
m_ColorTemperature: 6570
|
||||
m_UseColorTemperature: 0
|
||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_UseBoundingSphereOverride: 0
|
||||
m_UseViewFrustumForShadowCasterCull: 1
|
||||
m_ShadowRadius: 0
|
||||
m_ShadowAngle: 0
|
||||
--- !u!4 &790008996
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 790008994}
|
||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||
--- !u!1 &1371947665
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1371947668}
|
||||
- component: {fileID: 1371947667}
|
||||
- component: {fileID: 1371947666}
|
||||
- component: {fileID: 1371947669}
|
||||
- component: {fileID: 1371947670}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!81 &1371947666
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1371947665}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &1371947667
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1371947665}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_Iso: 200
|
||||
m_ShutterSpeed: 0.005
|
||||
m_Aperture: 16
|
||||
m_FocusDistance: 10
|
||||
m_FocalLength: 50
|
||||
m_BladeCount: 5
|
||||
m_Curvature: {x: 2, y: 11}
|
||||
m_BarrelClipping: 0.25
|
||||
m_Anamorphism: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &1371947668
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1371947665}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1371947669
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1371947665}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f75d46640fcd41f49a2bc14a946c16cf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
fontSize: 36
|
||||
--- !u!114 &1371947670
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1371947665}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 21612b697232f004dbebce22c0000dd8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
PlayMode: 0
|
7
JNFrame2/Assets/HotMain/HotMain.unity.meta
Normal file
7
JNFrame2/Assets/HotMain/HotMain.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7ad21e5080633342835fcd9ae35443e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
297
JNFrame2/Assets/HotMain/LoadDll.cs
Normal file
297
JNFrame2/Assets/HotMain/LoadDll.cs
Normal file
@@ -0,0 +1,297 @@
|
||||
using HybridCLR;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using HotMain;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 脚本工作流程:
|
||||
/// 1.下载资源,用YooAsset资源框架进行下载
|
||||
/// 1)资源文件,ab包等
|
||||
/// 2)热更新dll
|
||||
/// 3) AOT泛型补充元数据dll
|
||||
/// 2.给AOT dll补充元数据,通过RuntimeApi.LoadMetadataForAOTAssembly()
|
||||
/// 3.通过实例化一个prefab,运行热更新代码
|
||||
/// </summary>
|
||||
public class LoadDll : MonoBehaviour
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 资源系统运行模式
|
||||
/// </summary>
|
||||
public EPlayMode PlayMode = EPlayMode.OfflinePlayMode;
|
||||
|
||||
//补充元数据dll的列表,
|
||||
//通过RuntimeApi.LoadMetadataForAOTAssembly()函数来补充AOT泛型的原始元数据
|
||||
public static List<string> AOTMetaAssemblyNames { get; } = new List<string>()
|
||||
{
|
||||
"mscorlib.dll",
|
||||
"System.dll",
|
||||
"System.Core.dll",
|
||||
};
|
||||
|
||||
void Start()
|
||||
{
|
||||
//StartCoroutine(DownLoadAssets(this.StartGame));
|
||||
|
||||
StartCoroutine(DownLoadAssetsByYooAssets(this.StartGame));
|
||||
}
|
||||
|
||||
private static Dictionary<string, byte[]> s_assetDatas = new Dictionary<string, byte[]>();
|
||||
|
||||
public static byte[] GetAssetData(string dllName)
|
||||
{
|
||||
return s_assetDatas[dllName];
|
||||
}
|
||||
|
||||
private string GetWebRequestPath(string asset)
|
||||
{
|
||||
var path = $"{Application.streamingAssetsPath}/{asset}";
|
||||
if (!path.Contains("://"))
|
||||
{
|
||||
path = "file://" + path;
|
||||
}
|
||||
if (path.EndsWith(".dll"))
|
||||
{
|
||||
path += ".bytes";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
IEnumerator DownLoadAssetsByYooAssets(Action onDownloadComplete)
|
||||
{
|
||||
// 1.初始化资源系统
|
||||
YooAssets.Initialize();
|
||||
|
||||
string packageName = "DefaultPackage";
|
||||
// 创建默认的资源包
|
||||
var package = YooAssets.TryGetPackage(packageName) ?? YooAssets.CreatePackage(packageName);
|
||||
|
||||
// 设置该资源包为默认的资源包,可以使用YooAssets相关加载接口加载该资源包内容。
|
||||
YooAssets.SetDefaultPackage(package);
|
||||
|
||||
if (PlayMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
Debug.Log("编辑器模式");
|
||||
//编辑器模拟模式
|
||||
var initParameters = new EditorSimulateModeParameters();
|
||||
initParameters.EditorFileSystemParameters =
|
||||
FileSystemParameters.CreateDefaultEditorFileSystemParameters(
|
||||
EditorSimulateModeHelper.SimulateBuild(EDefaultBuildPipeline.ScriptableBuildPipeline, "DefaultPackage")
|
||||
);
|
||||
yield return package.InitializeAsync(initParameters);
|
||||
}
|
||||
else if (PlayMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
Debug.Log("在线模式");
|
||||
// 注意:GameQueryServices.cs 太空战机的脚本类,详细见StreamingAssetsHelper.cs
|
||||
string defaultHostServer = "http://127.0.0.1/CDN/Android/v1.0";
|
||||
string fallbackHostServer = "http://127.0.0.1/CDN/Android/v1.0";
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
var cacheFileSystem = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
||||
var buildinFileSystem = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
|
||||
var initParameters = new HostPlayModeParameters();
|
||||
initParameters.BuildinFileSystemParameters = buildinFileSystem;
|
||||
initParameters.CacheFileSystemParameters = cacheFileSystem;
|
||||
|
||||
yield return package.InitializeAsync(initParameters);
|
||||
}
|
||||
else if (PlayMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
Debug.Log("离线模式");
|
||||
// var buildinFileSystem = FileSystemParameters.CreateDefaultBuildinRawFileSystemParameters();
|
||||
// var initParameters = new OfflinePlayModeParameters();
|
||||
// initParameters.BuildinFileSystemParameters = buildinFileSystem;
|
||||
// yield return package.InitializeAsync(initParameters);
|
||||
// var initParametersOfflinePlayMode = new OfflinePlayModeParameters();
|
||||
// yield return package.InitializeAsync(initParametersOfflinePlayMode);
|
||||
|
||||
var createParameters = new OfflinePlayModeParameters();
|
||||
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(new FileStreamDecryption());
|
||||
yield return package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
|
||||
//2.获取资源版本
|
||||
var operation = package.RequestPackageVersionAsync();
|
||||
yield return operation;
|
||||
|
||||
if (operation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
//TODO
|
||||
yield break;
|
||||
}
|
||||
string PackageVersion = operation.PackageVersion;
|
||||
|
||||
//3.更新补丁清单
|
||||
var operation2 = package.UpdatePackageManifestAsync(PackageVersion);
|
||||
yield return operation2;
|
||||
|
||||
if (operation2.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation2.Error);
|
||||
//TODO:
|
||||
yield break;
|
||||
}
|
||||
|
||||
//4.下载补丁包
|
||||
yield return Download();
|
||||
//TODO:判断是否下载成功...
|
||||
|
||||
var assets = new List<string>
|
||||
{
|
||||
"HotSamples.dll",
|
||||
}.Concat(AOTMetaAssemblyNames);
|
||||
|
||||
foreach (var asset in assets)
|
||||
{
|
||||
var handle = package.LoadRawFileAsync(asset);
|
||||
yield return handle;
|
||||
byte[] fileData = handle.GetRawFileData();
|
||||
s_assetDatas[asset] = fileData;
|
||||
Debug.Log($"dll:{asset} size:{fileData.Length}");
|
||||
}
|
||||
|
||||
onDownloadComplete();
|
||||
}
|
||||
|
||||
IEnumerator Download()
|
||||
{
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
int timeout = 60;
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain, timeout);
|
||||
|
||||
//没有需要下载的资源
|
||||
if (downloader.TotalDownloadCount == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
//需要下载的文件总数和总大小
|
||||
int totalDownloadCount = downloader.TotalDownloadCount;
|
||||
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
||||
|
||||
//注册回调方法
|
||||
downloader.OnDownloadErrorCallback = OnDownloadErrorFunction;
|
||||
downloader.OnDownloadProgressCallback = OnDownloadProgressUpdateFunction;
|
||||
downloader.OnDownloadOverCallback = OnDownloadOverFunction;
|
||||
downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
|
||||
|
||||
//开启下载
|
||||
downloader.BeginDownload();
|
||||
yield return downloader;
|
||||
|
||||
//检测下载结果
|
||||
if (downloader.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//下载成功
|
||||
Debug.Log("更新完成!");
|
||||
//TODO:
|
||||
}
|
||||
else
|
||||
{
|
||||
//下载失败
|
||||
Debug.LogError("更新失败!");
|
||||
//TODO:
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始下载
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="sizeBytes"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnStartDownloadFileFunction(string fileName, long sizeBytes)
|
||||
{
|
||||
Debug.Log(string.Format("开始下载:文件名:{0}, 文件大小:{1}", fileName, sizeBytes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载完成
|
||||
/// </summary>
|
||||
/// <param name="isSucceed"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnDownloadOverFunction(bool isSucceed)
|
||||
{
|
||||
Debug.Log("下载" + (isSucceed ? "成功" : "失败"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新中
|
||||
/// </summary>
|
||||
/// <param name="totalDownloadCount"></param>
|
||||
/// <param name="currentDownloadCount"></param>
|
||||
/// <param name="totalDownloadBytes"></param>
|
||||
/// <param name="currentDownloadBytes"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnDownloadProgressUpdateFunction(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes)
|
||||
{
|
||||
Debug.Log(string.Format("文件总数:{0}, 已下载文件数:{1}, 下载总大小:{2}, 已下载大小:{3}", totalDownloadCount, currentDownloadCount, totalDownloadBytes, currentDownloadBytes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载出错
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="error"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnDownloadErrorFunction(string fileName, string error)
|
||||
{
|
||||
Debug.LogError(string.Format("下载出错:文件名:{0}, 错误信息:{1}", fileName, error));
|
||||
}
|
||||
|
||||
void StartGame()
|
||||
{
|
||||
LoadMetadataForAOTAssemblies();
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
System.Reflection.Assembly.Load(GetAssetData("HotSamples.dll"));
|
||||
#endif
|
||||
|
||||
//委托加载方式,加载prefab
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
AssetHandle handle = package.LoadAssetAsync<GameObject>("HotPrefab");
|
||||
handle.Completed += Handle_Completed;
|
||||
|
||||
//AssetBundle prefabAb = AssetBundle.LoadFromMemory(GetAssetData("prefabs"));
|
||||
//GameObject testPrefab = Instantiate(prefabAb.LoadAsset<GameObject>("HotUpdatePrefab.prefab"));
|
||||
}
|
||||
|
||||
private void Handle_Completed(AssetHandle obj)
|
||||
{
|
||||
GameObject go = obj.InstantiateSync();
|
||||
Debug.Log($"Prefab name is {go.name}");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 为aot assembly加载原始metadata, 这个代码放aot或者热更新都行。
|
||||
/// 一旦加载后,如果AOT泛型函数对应native实现不存在,则自动替换为解释模式执行
|
||||
/// </summary>
|
||||
private static void LoadMetadataForAOTAssemblies()
|
||||
{
|
||||
/// 注意,补充元数据是给AOT dll补充元数据,而不是给热更新dll补充元数据。
|
||||
/// 热更新dll不缺元数据,不需要补充,如果调用LoadMetadataForAOTAssembly会返回错误
|
||||
///
|
||||
HomologousImageMode mode = HomologousImageMode.SuperSet;
|
||||
foreach (var aotDllName in AOTMetaAssemblyNames)
|
||||
{
|
||||
byte[] dllBytes = GetAssetData(aotDllName);
|
||||
// 加载assembly对应的dll,会自动为它hook。一旦aot泛型函数的native函数不存在,用解释器版本代码
|
||||
LoadImageErrorCode err = RuntimeApi.LoadMetadataForAOTAssembly(dllBytes, mode);
|
||||
Debug.Log($"LoadMetadataForAOTAssembly:{aotDllName}. mode:{mode} ret:{err}");
|
||||
}
|
||||
}
|
||||
}
|
11
JNFrame2/Assets/HotMain/LoadDll.cs.meta
Normal file
11
JNFrame2/Assets/HotMain/LoadDll.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21612b697232f004dbebce22c0000dd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
105
JNFrame2/Assets/HotMain/YooAssetDefault.cs
Normal file
105
JNFrame2/Assets/HotMain/YooAssetDefault.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace HotMain
|
||||
{
|
||||
public class RemoteServices : IRemoteServices
|
||||
{
|
||||
private string defaultHostServer;
|
||||
private string fallbackHostServer;
|
||||
|
||||
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
this.defaultHostServer = defaultHostServer;
|
||||
this.fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
|
||||
public string GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return defaultHostServer;
|
||||
}
|
||||
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return fallbackHostServer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件解密流
|
||||
/// </summary>
|
||||
public class BundleStream : FileStream
|
||||
{
|
||||
public const byte KEY = 64;
|
||||
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
||||
{
|
||||
}
|
||||
|
||||
public BundleStream(string path, FileMode mode) : base(path, mode)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Read(byte[] array, int offset, int count)
|
||||
{
|
||||
var index = base.Read(array, offset, count);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] ^= KEY;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件流加载解密类
|
||||
/// </summary>
|
||||
class FileStreamDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static uint GetManagedReadBufferSize()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
}
|
3
JNFrame2/Assets/HotMain/YooAssetDefault.cs.meta
Normal file
3
JNFrame2/Assets/HotMain/YooAssetDefault.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c2a4207de1f4b1995db5f2f3a8d6e62
|
||||
timeCreated: 1728649446
|
Reference in New Issue
Block a user