您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
117 行
3.9 KiB
117 行
3.9 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
public class PropertyCollector
|
|
{
|
|
public struct TextureInfo
|
|
{
|
|
public string name;
|
|
public int textureId;
|
|
public bool modifiable;
|
|
}
|
|
|
|
private readonly List<IShaderProperty> m_Properties = new List<IShaderProperty>();
|
|
|
|
public void AddShaderProperty(IShaderProperty chunk)
|
|
{
|
|
if (m_Properties.Any(x => x.referenceName == chunk.referenceName))
|
|
return;
|
|
m_Properties.Add(chunk);
|
|
}
|
|
|
|
public string GetPropertiesBlock(int baseIndentLevel)
|
|
{
|
|
var sb = new StringBuilder();
|
|
foreach (var prop in m_Properties.Where(x => x.generatePropertyBlock))
|
|
{
|
|
for (var i = 0; i < baseIndentLevel; i++)
|
|
{
|
|
//sb.Append("\t");
|
|
sb.Append(" "); // unity convention use space instead of tab...
|
|
}
|
|
sb.AppendLine(prop.GetPropertyBlockString());
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
public string GetPropertiesDeclaration(int baseIndentLevel)
|
|
{
|
|
var builder = new ShaderStringBuilder(baseIndentLevel);
|
|
GetPropertiesDeclaration(builder);
|
|
return builder.ToString();
|
|
}
|
|
|
|
public void GetPropertiesDeclaration(ShaderStringBuilder builder)
|
|
{
|
|
foreach (var prop in m_Properties)
|
|
{
|
|
builder.AppendLine(prop.GetPropertyDeclarationString());
|
|
}
|
|
}
|
|
|
|
public List<TextureInfo> GetConfiguredTexutres()
|
|
{
|
|
var result = new List<TextureInfo>();
|
|
|
|
foreach (var prop in m_Properties.OfType<TextureShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
|
|
foreach (var prop in m_Properties.OfType<Texture2DArrayShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.textureArray != null ? prop.value.textureArray.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
|
|
foreach (var prop in m_Properties.OfType<Texture3DShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
|
|
foreach (var prop in m_Properties.OfType<CubemapShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.cubemap != null ? prop.value.cubemap.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|