浏览代码

Change GetPreviewProperty to return list for multiple properties from one slot

/main
Matt Dean 6 年前
当前提交
348a9654
共有 18 个文件被更改,包括 193 次插入60 次删除
  1. 7
      com.unity.shadergraph/Editor/Data/Graphs/BooleanMaterialSlot.cs
  2. 7
      com.unity.shadergraph/Editor/Data/Graphs/ColorMaterialSlot.cs
  3. 7
      com.unity.shadergraph/Editor/Data/Graphs/ColorRGBMaterialSlot.cs
  4. 7
      com.unity.shadergraph/Editor/Data/Graphs/CubemapInputMaterialSlot.cs
  5. 13
      com.unity.shadergraph/Editor/Data/Graphs/DynamicValueMaterialSlot.cs
  6. 7
      com.unity.shadergraph/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
  7. 115
      com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs
  8. 7
      com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs
  9. 7
      com.unity.shadergraph/Editor/Data/Graphs/Matrix2MaterialSlot.cs
  10. 9
      com.unity.shadergraph/Editor/Data/Graphs/Matrix3MaterialSlot.cs
  11. 9
      com.unity.shadergraph/Editor/Data/Graphs/Matrix4MaterialSlot.cs
  12. 9
      com.unity.shadergraph/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs
  13. 9
      com.unity.shadergraph/Editor/Data/Graphs/Vector1MaterialSlot.cs
  14. 9
      com.unity.shadergraph/Editor/Data/Graphs/Vector2MaterialSlot.cs
  15. 7
      com.unity.shadergraph/Editor/Data/Graphs/Vector3MaterialSlot.cs
  16. 7
      com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs
  17. 9
      com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs
  18. 8
      com.unity.shadergraph/Editor/Drawing/Views/Slots/GradientSlotControlView.cs

7
com.unity.shadergraph/Editor/Data/Graphs/BooleanMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

public override SlotValueType valueType { get { return SlotValueType.Boolean; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Boolean; } }
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)

7
com.unity.shadergraph/Editor/Data/Graphs/ColorMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
}
}

7
com.unity.shadergraph/Editor/Data/Graphs/ColorRGBMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
}
}

7
com.unity.shadergraph/Editor/Data/Graphs/CubemapInputMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(prop);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)

13
com.unity.shadergraph/Editor/Data/Graphs/DynamicValueMaterialSlot.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;

m_ConcreteValueType = valueType;
}
public override PreviewProperty GetPreviewProperty(string name)
{
var propType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType);
public override List<PreviewProperty> GetPreviewProperties(string name)
{
List<PreviewProperty> props = new List<PreviewProperty>();
var propType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType);
return pp;
}
props.Add(pp);
return props;
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{

7
com.unity.shadergraph/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;

m_ConcreteValueType = valueType;
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
var propType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType);
var pp = new PreviewProperty(propType) { name = name };
if (propType == PropertyType.Vector1)

return pp;
props.Add(pp);
return props;
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

115
com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

{
[Serializable]
public class GradientInputMaterialSlot : GradientMaterialSlot
public class GradientInputMaterialSlot : GradientMaterialSlot, IMaterialSlotHasValue<Gradient>
private Gradient m_Gradient = new Gradient();
Gradient m_Value = new Gradient();
public Gradient gradient
{
get { return m_Gradient; }
set { m_Gradient = value; }
}
[SerializeField]
Gradient m_DefaultValue;
public GradientInputMaterialSlot()
{

{
}
public Gradient value
{
get { return m_Value; }
set { m_Value = value; }
}
public Gradient defaultValue { get { return m_DefaultValue; } }
public override VisualElement InstantiateControl()
{
return new GradientSlotControlView(this);

if (matOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
if(generationMode == GenerationMode.Preview)
{
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("{0}_Type", matOwner.GetVariableNameForSlot(id)),
value = (int)value.mode,
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("{0}_ColorsLength", matOwner.GetVariableNameForSlot(id)),
value = value.colorKeys.Length,
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("{0}_AlphasLength", matOwner.GetVariableNameForSlot(id)),
value = value.alphaKeys.Length,
generatePropertyBlock = false
});
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("{0}_ColorKey{1}", matOwner.GetVariableNameForSlot(id), i),
value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero,
generatePropertyBlock = false
});
}
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("{0}_AlphaKey{1}", matOwner.GetVariableNameForSlot(id), i),
value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero,
generatePropertyBlock = false
});
}
}
prop.value = gradient;
prop.value = value;
if(generationMode == GenerationMode.Preview)
prop.OverrideMembers(matOwner.GetVariableNameForSlot(id));
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
var pp = new PreviewProperty(PropertyType.Gradient)
List<PreviewProperty> props = new List<PreviewProperty>();
props.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("{0}_Type", name),
floatValue = 0
});
props.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("{0}_ColorsLength", name),
floatValue = value.colorKeys.Length
});
props.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("{0}_AlphasLength", name),
floatValue = value.alphaKeys.Length
});
for(int i = 0; i < 8; i++)
name = name,
gradientValue = gradient
};
return pp;
props.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("{0}_ColorKey{1}", name, i),
vector4Value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero
});
}
for(int i = 0; i < 8; i++)
{
props.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("{0}_AlphaKey{1}", name, i),
vector4Value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero
});
}
return props;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)

m_Gradient = slot.gradient;
value = slot.value;
}
}
}

7
com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;

}
}
public virtual PreviewProperty GetPreviewProperty(string name)
public virtual List<PreviewProperty> GetPreviewProperties(string name)
return default(PreviewProperty);
List<PreviewProperty> props = new List<PreviewProperty>();
props.Add(default(PreviewProperty));
return props;
}
public abstract void CopyValuesFrom(MaterialSlot foundSlot);

7
com.unity.shadergraph/Editor/Data/Graphs/Matrix2MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
public override SlotValueType valueType { get { return SlotValueType.Matrix2; } }

9
com.unity.shadergraph/Editor/Data/Graphs/Matrix3MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

};
properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
public override SlotValueType valueType { get { return SlotValueType.Matrix3; } }

9
com.unity.shadergraph/Editor/Data/Graphs/Matrix4MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
vector4Value = new Vector4(value.GetRow(0).x, value.GetRow(0).y, value.GetRow(0).z, value.GetRow(0).w)
vector4Value = new Vector4(value.GetRow(0).x, value.GetRow(0).y, value.GetRow(0).z, value.GetRow(0).w),
return pp;
props.Add(pp);
return props;
}
public override SlotValueType valueType { get { return SlotValueType.Matrix4; } }

9
com.unity.shadergraph/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(prop);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
textureValue = texture
textureValue = texture,
return pp;
props.Add(pp);
return props;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)

9
com.unity.shadergraph/Editor/Data/Graphs/Vector1MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

public override SlotValueType valueType { get { return SlotValueType.Vector1; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector1; } }
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
floatValue = value
floatValue = value,
return pp;
props.Add(pp);
return props;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)

9
com.unity.shadergraph/Editor/Data/Graphs/Vector2MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
vector4Value = new Vector4(value.x, value.y, 0, 0)
vector4Value = new Vector4(value.x, value.y, 0, 0),
return pp;
props.Add(pp);
return props;
}
public override SlotValueType valueType { get { return SlotValueType.Vector2; } }

7
com.unity.shadergraph/Editor/Data/Graphs/Vector3MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
public override SlotValueType valueType { get { return SlotValueType.Vector3; } }

7
com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

properties.AddShaderProperty(property);
}
public override PreviewProperty GetPreviewProperty(string name)
public override List<PreviewProperty> GetPreviewProperties(string name)
List<PreviewProperty> props = new List<PreviewProperty>();
return pp;
props.Add(pp);
return props;
}
public override SlotValueType valueType { get { return SlotValueType.Vector4; } }

9
com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs


if (s_TempEdges.Any())
continue;
var item = s.GetPreviewProperty(GetVariableNameForSlot(s.id));
if (item.name == null)
var items = s.GetPreviewProperties(GetVariableNameForSlot(s.id));
for(int i = 0; i < items.Count; i++)
{
if (items[i].name == null)
properties.Add(item);
properties.Add(items[i]);
}
}
}

8
com.unity.shadergraph/Editor/Drawing/Views/Slots/GradientSlotControlView.cs


public void OnNodeModified(ModificationScope scope)
{
if (scope == ModificationScope.Graph)
if (scope == ModificationScope.Node)
m_Container.Dirty(ChangeType.Repaint);
}

m_GradientObject.gradient.SetKeys(m_Slot.gradient.colorKeys, m_Slot.gradient.alphaKeys);
m_GradientObject.gradient.SetKeys(m_Slot.value.colorKeys, m_Slot.value.alphaKeys);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{

{
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Gradient");
m_Slot.gradient = m_GradientObject.gradient;
m_Slot.owner.Dirty(ModificationScope.Graph);
m_Slot.value = m_GradientObject.gradient;
m_Slot.owner.Dirty(ModificationScope.Node);
m_Container.Dirty(ChangeType.Repaint);
}
}

正在加载...
取消
保存