mirror of https://github.com/tuyoogame/YooAsset
parent
7d8fce6f46
commit
2cbfca4f3b
|
@ -11,8 +11,10 @@ using UnityEditor;
|
||||||
public class ShaderVariantCollectionManifest
|
public class ShaderVariantCollectionManifest
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ShaderVariantElement
|
public class ShaderVariantElement : IComparable<ShaderVariantElement>
|
||||||
{
|
{
|
||||||
|
public string SortValue { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pass type to use in this variant.
|
/// Pass type to use in this variant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -22,11 +24,31 @@ public class ShaderVariantCollectionManifest
|
||||||
/// Array of shader keywords to use in this variant.
|
/// Array of shader keywords to use in this variant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Keywords;
|
public string[] Keywords;
|
||||||
|
|
||||||
|
public void MakeSortValue()
|
||||||
|
{
|
||||||
|
string combineKeyword = string.Empty;
|
||||||
|
for (int i = 0; i < Keywords.Length; i++)
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
combineKeyword = Keywords[0];
|
||||||
|
else
|
||||||
|
combineKeyword = $"{combineKeyword}+{Keywords[0]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
SortValue = $"{PassType}+{combineKeyword}";
|
||||||
|
}
|
||||||
|
public int CompareTo(ShaderVariantElement other)
|
||||||
|
{
|
||||||
|
return SortValue.CompareTo(other.SortValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ShaderVariantInfo : IComparable<ShaderVariantInfo>
|
public class ShaderVariantInfo : IComparable<ShaderVariantInfo>
|
||||||
{
|
{
|
||||||
|
public string SortValue { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 着色器资源路径.
|
/// 着色器资源路径.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -47,11 +69,13 @@ public class ShaderVariantCollectionManifest
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
||||||
|
|
||||||
|
public void MakeSortValue()
|
||||||
|
{
|
||||||
|
SortValue = AssetPath + "+" + ShaderName;
|
||||||
|
}
|
||||||
public int CompareTo(ShaderVariantInfo other)
|
public int CompareTo(ShaderVariantInfo other)
|
||||||
{
|
{
|
||||||
string thisStr = AssetPath + "+" +ShaderName;
|
return SortValue.CompareTo(other.SortValue);
|
||||||
string otherStr = other.AssetPath + "+" + other.ShaderName;
|
|
||||||
return thisStr.CompareTo(otherStr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +100,15 @@ public class ShaderVariantCollectionManifest
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
||||||
{
|
{
|
||||||
|
// 排序Keyword列表
|
||||||
|
List<string> temper = new List<string>(keywords);
|
||||||
|
temper.Sort();
|
||||||
|
|
||||||
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
||||||
ShaderVariantElement element = new ShaderVariantElement();
|
ShaderVariantElement element = new ShaderVariantElement();
|
||||||
element.PassType = passType;
|
element.PassType = passType;
|
||||||
element.Keywords = keywords;
|
element.Keywords = temper.ToArray();
|
||||||
|
element.MakeSortValue();
|
||||||
info.ShaderVariantElements.Add(element);
|
info.ShaderVariantElements.Add(element);
|
||||||
info.ShaderVariantCount++;
|
info.ShaderVariantCount++;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +120,7 @@ public class ShaderVariantCollectionManifest
|
||||||
ShaderVariantInfo newInfo = new ShaderVariantInfo();
|
ShaderVariantInfo newInfo = new ShaderVariantInfo();
|
||||||
newInfo.AssetPath = assetPath;
|
newInfo.AssetPath = assetPath;
|
||||||
newInfo.ShaderName = shaderName;
|
newInfo.ShaderName = shaderName;
|
||||||
|
newInfo.MakeSortValue();
|
||||||
ShaderVariantInfos.Add(newInfo);
|
ShaderVariantInfos.Add(newInfo);
|
||||||
return newInfo;
|
return newInfo;
|
||||||
}
|
}
|
||||||
|
@ -150,6 +180,11 @@ public class ShaderVariantCollectionManifest
|
||||||
|
|
||||||
// 重新排序
|
// 重新排序
|
||||||
manifest.ShaderVariantInfos.Sort();
|
manifest.ShaderVariantInfos.Sort();
|
||||||
|
foreach (var shaderVariantInfo in manifest.ShaderVariantInfos)
|
||||||
|
{
|
||||||
|
shaderVariantInfo.ShaderVariantElements.Sort();
|
||||||
|
}
|
||||||
|
|
||||||
return manifest;
|
return manifest;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,8 +21,8 @@ public static class ShaderVariantCollector
|
||||||
WaitingDone,
|
WaitingDone,
|
||||||
}
|
}
|
||||||
|
|
||||||
private const float WaitMilliseconds = 1000f;
|
private const float WaitMilliseconds = 3000f;
|
||||||
private const float SleepMilliseconds = 2000f;
|
private const float SleepMilliseconds = 3000f;
|
||||||
private static string _savePath;
|
private static string _savePath;
|
||||||
private static string _packageName;
|
private static string _packageName;
|
||||||
private static int _processMaxNum;
|
private static int _processMaxNum;
|
||||||
|
|
Loading…
Reference in New Issue