init
This commit is contained in:
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/ExtensionClass.meta
vendored
Normal file
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/ExtensionClass.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d7171aa14ba0e649900533bfeed0edb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public static class AssetHandleExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待异步执行完毕
|
||||
/// </summary>
|
||||
public static AssetHandle WaitForAsyncOperationComplete(this AssetHandle thisHandle)
|
||||
{
|
||||
thisHandle.WaitForAsyncComplete();
|
||||
return thisHandle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0893ac05d109894e9acb6deeb688ee5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/ExtensionClass/HandleBaseExtension.cs
vendored
Normal file
12
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/ExtensionClass/HandleBaseExtension.cs
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public static class HandleBaseExtension
|
||||
{
|
||||
public static bool IsSucceed(this HandleBase thisHandle)
|
||||
{
|
||||
return thisHandle.IsDone && thisHandle.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03c367406c5062c41ba3290201be20c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/ExtensionOperation.meta
vendored
Normal file
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/ExtensionOperation.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f63bfdaa2e1fd3d48b604787fd1a8c99
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置清单文件到沙盒目录
|
||||
/// </summary>
|
||||
public class CopyBuildinManifestOperation : GameAsyncOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckHashFile,
|
||||
UnpackHashFile,
|
||||
CheckManifestFile,
|
||||
UnpackManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private UnityWebFileRequestOperation _hashFileRequestOp;
|
||||
private UnityWebFileRequestOperation _manifestFileRequestOp;
|
||||
|
||||
public CopyBuildinManifestOperation(string packageName, string packageVersion)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.CheckHashFile;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckHashFile)
|
||||
{
|
||||
string hashFilePath = GetCacheHashFilePath();
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
_steps = ESteps.CheckManifestFile;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.UnpackHashFile;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackHashFile)
|
||||
{
|
||||
if(_hashFileRequestOp == null)
|
||||
{
|
||||
string sourcePath = GetBuildinHashFilePath();
|
||||
string destPath = GetCacheHashFilePath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||
OperationSystem.StartOperation(_packageName, _hashFileRequestOp);
|
||||
}
|
||||
|
||||
if (_hashFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_hashFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CheckManifestFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _hashFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckManifestFile)
|
||||
{
|
||||
string manifestFilePath = GetCacheManifestFilePath();
|
||||
if (File.Exists(manifestFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.UnpackManifestFile;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackManifestFile)
|
||||
{
|
||||
if (_manifestFileRequestOp == null)
|
||||
{
|
||||
string sourcePath = GetBuildinManifestFilePath();
|
||||
string destPath = GetCacheManifestFilePath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||
OperationSystem.StartOperation(_packageName, _manifestFileRequestOp);
|
||||
}
|
||||
|
||||
if (_manifestFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_manifestFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _manifestFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnAbort()
|
||||
{
|
||||
}
|
||||
|
||||
private string GetBuildinYooRoot()
|
||||
{
|
||||
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
}
|
||||
private string GetBuildinHashFilePath()
|
||||
{
|
||||
string fileRoot = GetBuildinYooRoot();
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||
}
|
||||
private string GetBuildinManifestFilePath()
|
||||
{
|
||||
string fileRoot = GetBuildinYooRoot();
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||
}
|
||||
|
||||
private string GetCacheYooRoot()
|
||||
{
|
||||
return YooAssetSettingsData.GetYooDefaultCacheRoot();
|
||||
}
|
||||
private string GetCacheHashFilePath()
|
||||
{
|
||||
string fileRoot = GetCacheYooRoot();
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||
}
|
||||
private string GetCacheManifestFilePath()
|
||||
{
|
||||
string fileRoot = GetCacheYooRoot();
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41ab464f315df234fb40b0c24e97ee23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 获取包体里的内置资源清单版本
|
||||
/// </summary>
|
||||
public class GetBuildinPackageVersionOperation : GameAsyncOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private UnityWebTextRequestOperation _versionFileRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源清单版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
public GetBuildinPackageVersionOperation(string packageName)
|
||||
{
|
||||
_packageName = packageName;
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.GetPackageVersion;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetPackageVersion)
|
||||
{
|
||||
if (_versionFileRequestOp == null)
|
||||
{
|
||||
string filePath = GetBuildinPackageVersionFilePath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_versionFileRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||
OperationSystem.StartOperation(_packageName, _versionFileRequestOp);
|
||||
}
|
||||
|
||||
if (_versionFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_versionFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
PackageVersion = _versionFileRequestOp.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _versionFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnAbort()
|
||||
{
|
||||
}
|
||||
|
||||
private string GetBuildinYooRoot()
|
||||
{
|
||||
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
}
|
||||
private string GetBuildinPackageVersionFilePath()
|
||||
{
|
||||
string fileRoot = GetBuildinYooRoot();
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 609e1ce54918dab40900d532704b1187
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒目录里缓存文件大小
|
||||
/// </summary>
|
||||
public class GetCacheBundleSizeOperation : GameAsyncOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 总大小(单位:字节)
|
||||
/// </summary>
|
||||
public long TotalSize = 0;
|
||||
|
||||
|
||||
public GetCacheBundleSizeOperation(string packageName)
|
||||
{
|
||||
_packageName = packageName;
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.GetCacheFiles;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetCacheFiles)
|
||||
{
|
||||
long totalSize = 0;
|
||||
string directoryRoot = GetCacheDirectoryRoot();
|
||||
var directoryInfo = new DirectoryInfo(directoryRoot);
|
||||
if (directoryInfo.Exists)
|
||||
{
|
||||
FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
|
||||
foreach (FileInfo fileInfo in fileInfos)
|
||||
{
|
||||
totalSize += fileInfo.Length;
|
||||
}
|
||||
}
|
||||
|
||||
TotalSize = totalSize;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
protected override void OnAbort()
|
||||
{
|
||||
}
|
||||
|
||||
private string GetCacheDirectoryRoot()
|
||||
{
|
||||
string rootDirectory = YooAssetSettingsData.GetYooDefaultCacheRoot();
|
||||
string packageRoot = PathUtility.Combine(rootDirectory, _packageName);
|
||||
return PathUtility.Combine(packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8790bf5eb17db6843b696018a2b1ce6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObject : UnityEngine.Object
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAssets,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _tag;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private List<AssetHandle> _handles;
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象集合
|
||||
/// </summary>
|
||||
public List<TObject> AssetObjects { private set; get; }
|
||||
|
||||
|
||||
public LoadAssetsByTagOperation(string tag)
|
||||
{
|
||||
_tag = tag;
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.LoadAssets;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssets)
|
||||
{
|
||||
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(_tag);
|
||||
_handles = new List<AssetHandle>(assetInfos.Length);
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
var handle = YooAssets.LoadAssetAsync(assetInfo);
|
||||
_handles.Add(handle);
|
||||
}
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var handle in _handles)
|
||||
{
|
||||
if (handle.IsDone == false)
|
||||
{
|
||||
Progress = (float)index / _handles.Count;
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
AssetObjects = new List<TObject>(_handles.Count);
|
||||
foreach (var handle in _handles)
|
||||
{
|
||||
if (handle.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var assetObject = handle.AssetObject as TObject;
|
||||
if (assetObject != null)
|
||||
{
|
||||
AssetObjects.Add(assetObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"资源类型转换失败:{handle.AssetObject.name}";
|
||||
Debug.LogError($"{error}");
|
||||
AssetObjects.Clear();
|
||||
SetFinish(false, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"{handle.LastError}");
|
||||
AssetObjects.Clear();
|
||||
SetFinish(false, handle.LastError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SetFinish(true);
|
||||
}
|
||||
}
|
||||
protected override void OnAbort()
|
||||
{
|
||||
}
|
||||
private void SetFinish(bool succeed, string error = "")
|
||||
{
|
||||
Error = error;
|
||||
Status = succeed ? EOperationStatus.Succeed : EOperationStatus.Failed;
|
||||
_steps = ESteps.Done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void ReleaseHandle()
|
||||
{
|
||||
foreach (var handle in _handles)
|
||||
{
|
||||
handle.Release();
|
||||
}
|
||||
_handles.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35cd25a83a43dfb4093399183b31a0d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public static class YooAssetsExtension
|
||||
{
|
||||
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage resourcePackage, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
|
||||
{
|
||||
var operation = new LoadGameObjectOperation(location, position, rotation, parent, destroyGoOnRelease);
|
||||
YooAssets.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
public class LoadGameObjectOperation : GameAsyncOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAsset,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _location;
|
||||
private readonly Vector3 _positon;
|
||||
private readonly Quaternion _rotation;
|
||||
private readonly Transform _parent;
|
||||
private readonly bool _destroyGoOnRelease;
|
||||
private AssetHandle _handle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 加载的游戏对象
|
||||
/// </summary>
|
||||
public GameObject Go { private set; get; }
|
||||
|
||||
|
||||
public LoadGameObjectOperation(string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
|
||||
{
|
||||
_location = location;
|
||||
_positon = position;
|
||||
_rotation = rotation;
|
||||
_parent = parent;
|
||||
_destroyGoOnRelease = destroyGoOnRelease;
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (_handle == null)
|
||||
{
|
||||
_handle = YooAssets.LoadAssetAsync<GameObject>(_location);
|
||||
}
|
||||
|
||||
Progress = _handle.Progress;
|
||||
if (_handle.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_handle.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Error = _handle.LastError;
|
||||
Status = EOperationStatus.Failed;
|
||||
_steps = ESteps.Done;
|
||||
}
|
||||
else
|
||||
{
|
||||
Go = _handle.InstantiateSync(_positon, _rotation, _parent);
|
||||
Status = EOperationStatus.Succeed;
|
||||
_steps = ESteps.Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnAbort()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void ReleaseHandle()
|
||||
{
|
||||
if (_handle != null)
|
||||
{
|
||||
_handle.Release();
|
||||
|
||||
if (_destroyGoOnRelease)
|
||||
{
|
||||
if (Go != null)
|
||||
GameObject.Destroy(Go);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55478908ad5dc5541af1529a3faccee7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/GameObjectAssetReference.cs
vendored
Normal file
73
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/GameObjectAssetReference.cs
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(GameObjectAssetReference), true)]
|
||||
public class GameObjectAssetReferenceInspector : UnityEditor.Editor
|
||||
{
|
||||
private bool _init = false;
|
||||
private GameObject _cacheObject;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
GameObjectAssetReference mono = (GameObjectAssetReference)target;
|
||||
|
||||
if (_init == false)
|
||||
{
|
||||
_init = true;
|
||||
if (string.IsNullOrEmpty(mono.AssetGUID) == false)
|
||||
{
|
||||
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(mono.AssetGUID);
|
||||
if (string.IsNullOrEmpty(assetPath) == false)
|
||||
{
|
||||
_cacheObject = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameObject go = (GameObject)UnityEditor.EditorGUILayout.ObjectField(_cacheObject, typeof(GameObject), false);
|
||||
if (go != _cacheObject)
|
||||
{
|
||||
_cacheObject = go;
|
||||
string assetPath = UnityEditor.AssetDatabase.GetAssetPath(go);
|
||||
mono.AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
|
||||
UnityEditor.EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
UnityEditor.EditorGUILayout.LabelField("Asset GUID", mono.AssetGUID);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public class GameObjectAssetReference : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public string AssetGUID = "";
|
||||
|
||||
private AssetHandle _handle;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
var assetInfo = package.GetAssetInfoByGUID(AssetGUID);
|
||||
_handle = package.LoadAssetAsync(assetInfo);
|
||||
_handle.Completed += Handle_Completed;
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (_handle != null)
|
||||
{
|
||||
_handle.Release();
|
||||
_handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Handle_Completed(AssetHandle handle)
|
||||
{
|
||||
if (handle.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
handle.InstantiateSync(this.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/GameObjectAssetReference.cs.meta
vendored
Normal file
11
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/GameObjectAssetReference.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1534f1a1b207ad542bf1fc73da8b4316
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/OperationMonitor.meta
vendored
Normal file
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/OperationMonitor.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0c72b92f8bf3db4b9920e968e43b2df
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/OperationMonitor/OperationMonitor.cs
vendored
Normal file
21
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/OperationMonitor/OperationMonitor.cs
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public static class OperationMonitor
|
||||
{
|
||||
public static void RegisterOperationCallback()
|
||||
{
|
||||
OperationSystem.RegisterStartCallback(OperationStartCallback);
|
||||
OperationSystem.RegisterFinishCallback(OperationFinishCallback);
|
||||
}
|
||||
|
||||
private static void OperationStartCallback(string packageName, AsyncOperationBase operation)
|
||||
{
|
||||
Debug.Log($"Operation start : {operation.GetType().Name}");
|
||||
}
|
||||
private static void OperationFinishCallback(string packageName, AsyncOperationBase operation)
|
||||
{
|
||||
Debug.Log($"Operation finish : {operation.GetType().Name}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fecc774089972ae4eaecb16bdaf9d319
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor.meta
vendored
Normal file
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67ce0f6fc08b0724d95a9f86697bbde3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelManifest.cs
vendored
Normal file
12
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelManifest.cs
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
|
||||
public class PanelManifest : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 面板自动引用的图集
|
||||
/// </summary>
|
||||
public List<SpriteAtlas> ReferencesAtlas = new List<SpriteAtlas>();
|
||||
}
|
||||
11
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelManifest.cs.meta
vendored
Normal file
11
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelManifest.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2537124b11b52a458e01629f6b18f55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
141
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelMonitor.cs
vendored
Normal file
141
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelMonitor.cs
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
#if UNITY_EDITOR && UNITY_2021_3_OR_NEWER
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
|
||||
public static class UIPanelSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否开启面板监测
|
||||
/// </summary>
|
||||
public static bool EnablePanelMonitor = false;
|
||||
|
||||
/// <summary>
|
||||
/// 面板文件夹GUID
|
||||
/// </summary>
|
||||
private const string UIPanelDirectoryGUID = "12d33f33f3a55224c9c747d7bffa1c68";
|
||||
|
||||
/// <summary>
|
||||
/// 精灵文件夹GUID
|
||||
/// </summary>
|
||||
private const string UISpriteDirectoryGUID = "935d7f20c085cc141a3daf9cacfabfae";
|
||||
|
||||
/// <summary>
|
||||
/// 图集文件夹GUID
|
||||
/// </summary>
|
||||
private const string UIAtlasDirectoryGUID = "c355c783476322b4cacac98c5e1b46d8";
|
||||
|
||||
public static string GetPanelDirecotry()
|
||||
{
|
||||
string result = UnityEditor.AssetDatabase.GUIDToAssetPath(UIPanelDirectoryGUID);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
throw new System.Exception($"Can not found panel direcotry : {UIPanelDirectoryGUID}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static string GetSpriteDirecotry()
|
||||
{
|
||||
string result = UnityEditor.AssetDatabase.GUIDToAssetPath(UISpriteDirectoryGUID);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
throw new System.Exception($"Can not found sprite direcotry : {UISpriteDirectoryGUID}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static string GetAtlasDirecotry()
|
||||
{
|
||||
string result = UnityEditor.AssetDatabase.GUIDToAssetPath(UIAtlasDirectoryGUID);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
throw new System.Exception($"Can not found atlas direcotry : {UIAtlasDirectoryGUID}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class UIPanelMonitor : UnityEditor.Editor
|
||||
{
|
||||
[UnityEditor.InitializeOnLoadMethod]
|
||||
static void StartInitializeOnLoadMethod()
|
||||
{
|
||||
UnityEditor.SceneManagement.PrefabStage.prefabSaving += OnPrefabSaving;
|
||||
}
|
||||
|
||||
static void OnPrefabSaving(GameObject go)
|
||||
{
|
||||
if (UIPanelSettings.EnablePanelMonitor == false)
|
||||
return;
|
||||
|
||||
UnityEditor.SceneManagement.PrefabStage stage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||
if (stage != null)
|
||||
{
|
||||
string panelDirectory = UIPanelSettings.GetPanelDirecotry();
|
||||
if (stage.assetPath.StartsWith(panelDirectory))
|
||||
{
|
||||
PanelManifest manifest = go.GetComponent<PanelManifest>();
|
||||
if (manifest == null)
|
||||
manifest = go.AddComponent<PanelManifest>();
|
||||
|
||||
RefreshPanelManifest(manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新面板清单
|
||||
/// </summary>
|
||||
private static void RefreshPanelManifest(PanelManifest manifest)
|
||||
{
|
||||
manifest.ReferencesAtlas.Clear();
|
||||
|
||||
string spriteDirectory = UIPanelSettings.GetSpriteDirecotry();
|
||||
string altasDirectory = UIPanelSettings.GetAtlasDirecotry();
|
||||
|
||||
// 获取依赖的图集名称
|
||||
Transform root = manifest.transform;
|
||||
Image[] allImage = root.GetComponentsInChildren<Image>(true);
|
||||
for (int i = 0; i < allImage.Length; i++)
|
||||
{
|
||||
Image image = allImage[i];
|
||||
if (image.sprite == null)
|
||||
continue;
|
||||
|
||||
// 文件路径
|
||||
string spriteAssetPath = UnityEditor.AssetDatabase.GetAssetPath(image.sprite);
|
||||
|
||||
// 跳过系统内置资源
|
||||
if (spriteAssetPath.Contains("_builtin_"))
|
||||
continue;
|
||||
|
||||
// 跳过非图集精灵
|
||||
if (spriteAssetPath.StartsWith(spriteDirectory) == false)
|
||||
continue;
|
||||
|
||||
string atlasAssetPath = GetAtlasPath(altasDirectory, spriteAssetPath);
|
||||
SpriteAtlas spriteAtlas = UnityEditor.AssetDatabase.LoadAssetAtPath<SpriteAtlas>(atlasAssetPath);
|
||||
if (spriteAtlas == null)
|
||||
{
|
||||
throw new System.Exception($"Not found SpriteAtlas : {atlasAssetPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (manifest.ReferencesAtlas.Contains(spriteAtlas) == false)
|
||||
manifest.ReferencesAtlas.Add(spriteAtlas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取精灵所属图集
|
||||
/// </summary>
|
||||
private static string GetAtlasPath(string atlasDirectory, string assetPath)
|
||||
{
|
||||
string directory = Path.GetDirectoryName(assetPath);
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
|
||||
string atlasName = directoryInfo.Name;
|
||||
return $"{atlasDirectory}/{atlasName}.spriteatlas";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelMonitor.cs.meta
vendored
Normal file
11
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/PanelMonitor/PanelMonitor.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bed3b2eaa555ec4e9aaa22a888b504c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/SpriteAtlasLoader.meta
vendored
Normal file
8
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/SpriteAtlasLoader.meta
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eee88a2a10c99aa49b12a0fbff4084f0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
using YooAsset;
|
||||
|
||||
public class SpriteAtlasLoader : MonoBehaviour
|
||||
{
|
||||
private Dictionary<string, SpriteAtlas> _loadedAtlas = new Dictionary<string, SpriteAtlas>(1000);
|
||||
private List<AssetHandle> _loadHandles = new List<AssetHandle>(1000);
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
SpriteAtlasManager.atlasRequested += RequestAtlas;
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
foreach (var handle in _loadHandles)
|
||||
{
|
||||
handle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private void RequestAtlas(string atlasName, Action<SpriteAtlas> callback)
|
||||
{
|
||||
if (_loadedAtlas.TryGetValue(atlasName, out var value))
|
||||
{
|
||||
callback.Invoke(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
var loadHandle = package.LoadAssetSync<SpriteAtlas>(atlasName);
|
||||
if (loadHandle.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.LogWarning($"Failed to load sprite atlas : {atlasName} ! {loadHandle.LastError}");
|
||||
return;
|
||||
}
|
||||
|
||||
var atlas = loadHandle.AssetObject as SpriteAtlas;
|
||||
_loadedAtlas.Add(atlasName, atlas);
|
||||
_loadHandles.Add(loadHandle);
|
||||
callback.Invoke(atlas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a506251ccc863fe4182436d24685c181
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/YooAsset.RuntimeExtension.asmdef
vendored
Normal file
16
Assets/ThirdParty/YooAsset/2.3.17/Extension Sample/Runtime/YooAsset.RuntimeExtension.asmdef
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "YooAsset.RuntimeExtension",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fe1a3e70da50184f9897101cad7e4f2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user