浏览代码

Color attribute control

/main
Peter Bay Bastian 7 年前
当前提交
811d7dab
共有 7 个文件被更改,包括 41 次插入86 次删除
  1. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs
  2. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs
  3. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs.meta
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
  5. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  6. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/ColorNodePresenter.cs.meta
  7. 40
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/ColorNodePresenter.cs

23
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs


using System.Collections.Generic;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
[SerializeField]
private bool m_HDR;
[SerializeField]
public bool HDR
{
get { return m_HDR; }
set
{
if (m_HDR == value)
return;
m_HDR = value;
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
public ColorNode()
{
name = "Color";

RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
[ColorControl("")]
public Color color
{
get { return m_Color; }

overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = color,
HDR = HDR
HDR = false
});
}

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs


namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
string m_Label;
public ColorControlAttribute(string label = null)
{
m_Label = label;
}
return new ColorControlView(() => (Color) propertyInfo.GetValue(node, null), (value) => propertyInfo.SetValue(node, value, null));
return new ColorControlView(m_Label, node, propertyInfo);
readonly Func<Color> m_Getter;
readonly Action<Color> m_Setter;
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public ColorControlView(Func<Color> getter, Action<Color> setter)
public ColorControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
m_Getter = getter;
m_Setter = setter;
m_Node = node;
m_PropertyInfo = propertyInfo;
if (propertyInfo.PropertyType != typeof(Color))
throw new ArgumentException("Property must be of type Color.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
var value = m_Getter();
var newValue = EditorGUILayout.ColorField("", value);
if (newValue != value)
m_Setter(newValue);
var value = (Color) m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
value = EditorGUILayout.ColorField(m_Label, value);
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs.meta


fileFormatVersion: 2
guid: 34e77444559b414f9fe81f9775229abf
timeCreated: 1507733396
fileFormatVersion: 2
guid: 34e77444559b414f9fe81f9775229abf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs


{
if (MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
return new MultiFloatControlView(null, "X", "Y", "Z", "W", node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Color))
return new ColorControlView(null, node, propertyInfo);
return null;
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


{
typeMapper = new GraphTypeMapper(typeof(MaterialNodePresenter));
typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
// typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/ColorNodePresenter.cs.meta


fileFormatVersion: 2
guid: 9ea4884532b198441a14c69dae0a63f6
timeCreated: 1476707367
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

40
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/ColorNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class ColorContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.ColorNode;
if (cNode == null)
return;
cNode.color = EditorGUILayout.ColorField(new GUIContent("Color"), cNode.color, true, true, cNode.HDR, new ColorPickerHDRConfig(0f, 8f, 0.125f, 3f));
cNode.HDR = EditorGUILayout.Toggle("HDR", cNode.HDR);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 18 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ColorNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<ColorContolPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}
正在加载...
取消
保存