mirror of https://github.com/tuyoogame/YooAsset
Compare commits
6 Commits
b334a4986b
...
79467bbf13
Author | SHA1 | Date |
---|---|---|
|
79467bbf13 | |
|
c7d678282b | |
|
d376afc217 | |
|
a62f808591 | |
|
bdcf95384f | |
|
d910af589d |
|
@ -20,6 +20,8 @@
|
|||
/Assets/StreamingAssets.meta
|
||||
/Assets/Samples
|
||||
/Assets/Samples.meta
|
||||
/Assets/csc.rsp
|
||||
/Assets/csc.rsp.meta
|
||||
/UserSettings
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class MacroDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// YooAsset版本宏定义
|
||||
/// </summary>
|
||||
public static readonly List<string> Macros = new List<string>()
|
||||
{
|
||||
"YOO_ASSET_2",
|
||||
"YOO_ASSET_2_3",
|
||||
"YOO_ASSET_2_3_OR_NEWER",
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a61e5c2ca04aab647b1ed0492086aa8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,28 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class MacrosProcessor : AssetPostprocessor
|
||||
public class MacroProcessor : AssetPostprocessor
|
||||
{
|
||||
static MacrosProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// YooAsset版本宏定义
|
||||
/// </summary>
|
||||
private static readonly List<string> YooAssetMacros = new List<string>()
|
||||
{
|
||||
"YOO_ASSET_2",
|
||||
"YOO_ASSET_2_3",
|
||||
"YOO_ASSET_2_3_OR_NEWER",
|
||||
};
|
||||
|
||||
static string OnGeneratedCSProject(string path, string content)
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
|
@ -65,7 +52,7 @@ namespace YooAsset.Editor
|
|||
|
||||
string[] defines = childNode.InnerText.Split(';');
|
||||
HashSet<string> hashSets = new HashSet<string>(defines);
|
||||
foreach (string yooMacro in YooAssetMacros)
|
||||
foreach (string yooMacro in MacroDefine.Macros)
|
||||
{
|
||||
string tmpMacro = yooMacro.Trim();
|
||||
if (hashSets.Contains(tmpMacro) == false)
|
|
@ -0,0 +1,115 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if YOO_ASSET_EXPERIMENT
|
||||
namespace YooAsset.Editor.Experiment
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class RspGenerator
|
||||
{
|
||||
// csc.rsp文件路径
|
||||
private static string RspFilePath => Path.Combine(Application.dataPath, "csc.rsp");
|
||||
|
||||
static RspGenerator()
|
||||
{
|
||||
UpdateRspFile(MacroDefine.Macros, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新csc.rsp文件
|
||||
/// </summary>
|
||||
private static void UpdateRspFile(List<string> addMacros, List<string> removeMacros)
|
||||
{
|
||||
var existingDefines = new HashSet<string>();
|
||||
var otherLines = new List<string>();
|
||||
|
||||
// 1. 读取现有内容
|
||||
ReadRspFile(existingDefines, otherLines);
|
||||
|
||||
// 2. 添加新宏
|
||||
if (addMacros != null && addMacros.Count > 0)
|
||||
{
|
||||
addMacros.ForEach(x =>
|
||||
{
|
||||
if (existingDefines.Contains(x) == false)
|
||||
existingDefines.Add(x);
|
||||
});
|
||||
}
|
||||
|
||||
// 3. 移除指定宏
|
||||
if (removeMacros != null && removeMacros.Count > 0)
|
||||
{
|
||||
removeMacros.ForEach(x =>
|
||||
{
|
||||
existingDefines.Remove(x);
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 重新生成内容
|
||||
WriteRspFile(existingDefines, otherLines);
|
||||
|
||||
// 5. 刷新AssetDatabase
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.RequestScriptReload();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取csc.rsp文件,返回宏定义和其他行
|
||||
/// </summary>
|
||||
private static void ReadRspFile(HashSet<string> defines, List<string> others)
|
||||
{
|
||||
if (defines == null)
|
||||
defines = new HashSet<string>();
|
||||
|
||||
if (others == null)
|
||||
others = new List<string>();
|
||||
|
||||
if (File.Exists(RspFilePath) == false)
|
||||
return;
|
||||
|
||||
foreach (string line in File.ReadAllLines(RspFilePath))
|
||||
{
|
||||
if (line.StartsWith("-define:"))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, 2);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
defines.Add(parts[1].Trim());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
others.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重新写入csc.rsp文件
|
||||
/// </summary>
|
||||
private static void WriteRspFile(HashSet<string> defines, List<string> others)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (others != null && others.Count > 0)
|
||||
{
|
||||
others.ForEach(o => sb.AppendLine(o));
|
||||
}
|
||||
|
||||
if (defines != null && defines.Count > 0)
|
||||
{
|
||||
foreach (string define in defines)
|
||||
{
|
||||
sb.AppendLine($"-define:{define}");
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllText(RspFilePath, sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2662e1d33b1eea469695b68d18b1739
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -3,6 +3,16 @@ namespace YooAsset
|
|||
{
|
||||
public class AssetInfo
|
||||
{
|
||||
internal enum ELoadMethod
|
||||
{
|
||||
None = 0,
|
||||
LoadAsset,
|
||||
LoadSubAssets,
|
||||
LoadAllAssets,
|
||||
LoadScene,
|
||||
LoadRawFile,
|
||||
}
|
||||
|
||||
private readonly PackageAsset _packageAsset;
|
||||
private string _providerGUID;
|
||||
|
||||
|
@ -21,6 +31,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public string Error { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载方法
|
||||
/// </summary>
|
||||
internal ELoadMethod LoadMethod;
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
/// </summary>
|
||||
|
|
|
@ -174,7 +174,7 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源依赖列表
|
||||
/// 获取依赖列表
|
||||
/// 注意:传入的资源对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageAsset packageAsset)
|
||||
|
@ -188,6 +188,21 @@ namespace YooAsset
|
|||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取依赖列表
|
||||
/// 注意:传入的资源包对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageBundle packageBundle)
|
||||
{
|
||||
List<PackageBundle> result = new List<PackageBundle>(packageBundle.DependBundleIDs.Length);
|
||||
foreach (var dependID in packageBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = GetMainPackageBundle(dependID);
|
||||
result.Add(dependBundle);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源
|
||||
/// </summary>
|
||||
|
|
|
@ -176,7 +176,17 @@ namespace YooAsset
|
|||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
PackageBundle[] depends;
|
||||
if (assetInfo.LoadMethod == AssetInfo.ELoadMethod.LoadAllAssets)
|
||||
{
|
||||
var mainBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
depends = ActiveManifest.GetAllDependencies(mainBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
}
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
|
|
|
@ -610,6 +610,7 @@ namespace YooAsset
|
|||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadScene;
|
||||
var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode);
|
||||
var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority);
|
||||
if (waitForAsyncComplete)
|
||||
|
@ -720,6 +721,7 @@ namespace YooAsset
|
|||
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAsset;
|
||||
var handle = _resourceManager.LoadAssetAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
|
@ -829,6 +831,7 @@ namespace YooAsset
|
|||
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadSubAssets;
|
||||
var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
|
@ -938,6 +941,7 @@ namespace YooAsset
|
|||
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAllAssets;
|
||||
var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
|
|
|
@ -23,7 +23,10 @@ namespace YooAsset
|
|||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_assetBundle.TTUnload(true);
|
||||
if (_packageBundle.Encrypted)
|
||||
_assetBundle.Unload(true);
|
||||
else
|
||||
_assetBundle.TTUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace YooAsset
|
|||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
|
||||
|
||||
public WXAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
|
@ -23,7 +23,10 @@ namespace YooAsset
|
|||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_assetBundle.WXUnload(true);
|
||||
if (_packageBundle.Encrypted)
|
||||
_assetBundle.Unload(true);
|
||||
else
|
||||
_assetBundle.WXUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
|
|
Loading…
Reference in New Issue