您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
157 行
5.1 KiB
157 行
5.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using UnityEditor.Graphing;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEditor.ShaderGraph.Internal
|
|
{
|
|
[Serializable]
|
|
[FormerName("UnityEditor.ShaderGraph.FloatShaderProperty")]
|
|
[FormerName("UnityEditor.ShaderGraph.Vector1ShaderProperty")]
|
|
public sealed class Vector1ShaderProperty : AbstractShaderProperty<float>
|
|
{
|
|
internal Vector1ShaderProperty()
|
|
{
|
|
displayName = "Vector1";
|
|
}
|
|
|
|
public override PropertyType propertyType => PropertyType.Vector1;
|
|
|
|
internal override bool isBatchable => true;
|
|
internal override bool isExposable => true;
|
|
internal override bool isRenamable => true;
|
|
internal override bool isGpuInstanceable => true;
|
|
|
|
string enumTagString
|
|
{
|
|
get
|
|
{
|
|
switch(enumType)
|
|
{
|
|
case EnumType.CSharpEnum:
|
|
return $"[Enum({m_CSharpEnumType.ToString()})]";
|
|
case EnumType.KeywordEnum:
|
|
return $"[KeywordEnum({string.Join(", ", enumNames)})]";
|
|
default:
|
|
string enumValuesString = "";
|
|
for (int i = 0; i < enumNames.Count; i++)
|
|
{
|
|
int value = (i < enumValues.Count) ? enumValues[i] : i;
|
|
enumValuesString += (enumNames[i] + ", " + value + ((i != enumNames.Count - 1) ? ", " : ""));
|
|
}
|
|
return $"[Enum({enumValuesString})]";
|
|
}
|
|
}
|
|
}
|
|
|
|
internal override string GetPropertyBlockString()
|
|
{
|
|
switch(floatType)
|
|
{
|
|
case FloatType.Slider:
|
|
return $"{hideTagString}{referenceName}(\"{displayName}\", Range({NodeUtils.FloatToShaderValue(m_RangeValues.x)}, {NodeUtils.FloatToShaderValue(m_RangeValues.y)})) = {NodeUtils.FloatToShaderValue(value)}";
|
|
case FloatType.Integer:
|
|
return $"{hideTagString}{referenceName}(\"{displayName}\", Int) = {NodeUtils.FloatToShaderValue(value)}";
|
|
case FloatType.Enum:
|
|
return $"{hideTagString}{enumTagString}{referenceName}(\"{displayName}\", Float) = {NodeUtils.FloatToShaderValue(value)}";
|
|
default:
|
|
return $"{hideTagString}{referenceName}(\"{displayName}\", Float) = {NodeUtils.FloatToShaderValue(value)}";
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
FloatType m_FloatType = FloatType.Default;
|
|
|
|
public FloatType floatType
|
|
{
|
|
get => m_FloatType;
|
|
set => m_FloatType = value;
|
|
}
|
|
|
|
[SerializeField]
|
|
Vector2 m_RangeValues = new Vector2(0, 1);
|
|
|
|
public Vector2 rangeValues
|
|
{
|
|
get => m_RangeValues;
|
|
set => m_RangeValues = value;
|
|
}
|
|
|
|
EnumType m_EnumType = EnumType.Enum;
|
|
|
|
public EnumType enumType
|
|
{
|
|
get => m_EnumType;
|
|
set => m_EnumType = value;
|
|
}
|
|
|
|
Type m_CSharpEnumType;
|
|
|
|
public Type cSharpEnumType
|
|
{
|
|
get => m_CSharpEnumType;
|
|
set => m_CSharpEnumType = value;
|
|
}
|
|
|
|
List<string> m_EnumNames = new List<string>();
|
|
|
|
public List<string> enumNames
|
|
{
|
|
get => m_EnumNames;
|
|
set => m_EnumNames = value;
|
|
}
|
|
|
|
List<int> m_EnumValues = new List<int>();
|
|
|
|
public List<int> enumValues
|
|
{
|
|
get => m_EnumValues;
|
|
set => m_EnumValues = value;
|
|
}
|
|
|
|
internal override AbstractMaterialNode ToConcreteNode()
|
|
{
|
|
switch (m_FloatType)
|
|
{
|
|
case FloatType.Slider:
|
|
return new SliderNode { value = new Vector3(value, m_RangeValues.x, m_RangeValues.y) };
|
|
case FloatType.Integer:
|
|
return new IntegerNode { value = (int)value };
|
|
default:
|
|
var node = new Vector1Node();
|
|
node.FindInputSlot<Vector1MaterialSlot>(Vector1Node.InputSlotXId).value = value;
|
|
return node;
|
|
}
|
|
}
|
|
|
|
internal override PreviewProperty GetPreviewMaterialProperty()
|
|
{
|
|
return new PreviewProperty(propertyType)
|
|
{
|
|
name = referenceName,
|
|
floatValue = value
|
|
};
|
|
}
|
|
|
|
internal override ShaderInput Copy()
|
|
{
|
|
return new Vector1ShaderProperty()
|
|
{
|
|
displayName = displayName,
|
|
hidden = hidden,
|
|
value = value,
|
|
floatType = floatType,
|
|
rangeValues = rangeValues,
|
|
enumType = enumType,
|
|
enumNames = enumNames,
|
|
enumValues = enumValues
|
|
};
|
|
}
|
|
}
|
|
|
|
public enum FloatType { Default, Slider, Integer, Enum }
|
|
|
|
public enum EnumType { Enum, CSharpEnum, KeywordEnum, }
|
|
}
|