Update basic sample
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Better.StreamingAssets;
|
||||
using System.IO;
|
||||
|
||||
public class BootScene : MonoBehaviour
|
||||
{
|
||||
@@ -61,6 +62,7 @@ public class BootScene : MonoBehaviour
|
||||
if (PlayMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var createParameters = new OfflinePlayModeParameters();
|
||||
createParameters.DecryptionServices = new BundleDecryptionServices();
|
||||
yield return defaultPackage.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -68,6 +70,7 @@ public class BootScene : MonoBehaviour
|
||||
if (PlayMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
var createParameters = new HostPlayModeParameters();
|
||||
createParameters.DecryptionServices = new BundleDecryptionServices();
|
||||
createParameters.QueryServices = new QueryStreamingAssetsFileServices();
|
||||
createParameters.DefaultHostServer = GetHostServerURL();
|
||||
createParameters.FallbackHostServer = GetHostServerURL();
|
||||
@@ -113,4 +116,27 @@ public class BootScene : MonoBehaviour
|
||||
return BetterStreamingAssets.FileExists($"{buildinFolderName}/{fileName}");
|
||||
}
|
||||
}
|
||||
private class BundleDecryptionServices : IDecryptionServices
|
||||
{
|
||||
public ulong LoadFromFileOffset(DecryptFileInfo fileInfo)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
public byte[] LoadFromMemory(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public FileStream LoadFromStream(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FilePath, FileMode.Open);
|
||||
return bundleStream;
|
||||
}
|
||||
|
||||
public uint GetManagedReadBufferSize()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class BundleStream : FileStream
|
||||
{
|
||||
public const byte KEY = 64;
|
||||
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) : base(path, mode, access, share, bufferSize, useAsync)
|
||||
{
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7da6bc93686626a4cb248691891073ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user