浏览代码

Enum attribute control

/main
Peter Bay Bastian 7 年前
当前提交
f695b6fa
共有 16 个文件被更改,包括 63 次插入300 次删除
  1. 3
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs
  2. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs
  4. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  5. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs
  6. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs.meta
  7. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/LevelsNodePresenter.cs.meta
  8. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/MatrixCommonNodePresenter.cs.meta
  9. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SwizzleNodePresenter.cs.meta
  10. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/UVNodePresenter.cs.meta
  11. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SamplerStateNodePresenter.cs.meta
  12. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/LevelsNodePresenter.cs
  13. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SwizzleNodePresenter.cs
  14. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/MatrixCommonNodePresenter.cs
  15. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SamplerStateNodePresenter.cs
  16. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/UVNodePresenter.cs

3
MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs


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

[SerializeField]
private TextureSamplerState.FilterMode m_filter = TextureSamplerState.FilterMode.Linear;
[EnumControl]
public TextureSamplerState.FilterMode filter
{
get { return m_filter; }

[SerializeField]
private TextureSamplerState.WrapMode m_wrap = TextureSamplerState.WrapMode.Repeat;
[EnumControl]
public TextureSamplerState.WrapMode wrap
{
get { return m_wrap; }

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

[SerializeField]
private UVChannel m_OutputChannel;
[EnumControl("")]
public UVChannel uvChannel
{
get { return m_OutputChannel; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs


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

public override bool hasPreview { get { return false; } }
[EnumControl("")]
public CommonMatrixType matrix
{
get { return m_matrix; }

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


//typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
// typeMapper[typeof(Texture2DNode)] = typeof(TextureAssetNodePresenter);
// typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
typeMapper[typeof(SamplerStateNode)] = typeof(SamplerStateNodePresenter);
typeMapper[typeof(UVNode)] = typeof(UVNodePresenter);
typeMapper[typeof(PropertyNode)] = typeof(PropertyNodePresenter);
/* typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter

// typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);
typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
// typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterNodePresenter);
typeMapper[typeof(LevelsNode)] = typeof(LevelsNodePresenter);
typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
//typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);

typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
typeMapper[typeof(MatrixCommonNode)] = typeof(MatrixCommonNodePresenter);
typeMapper[typeof(TransformNode)] = typeof(TransformNodePresenter);
// typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class EnumControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public EnumControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new EnumControlView(m_Label, node, propertyInfo);
}
}
public class EnumControlView : VisualElement
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public EnumControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var value = (Enum) m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
value = EditorGUILayout.EnumPopup(m_Label, value);
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs.meta


fileFormatVersion: 2
guid: 3a1e13c5e67541d7ad7ae18ea5a834e4
timeCreated: 1507817885

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


fileFormatVersion: 2
guid: 224a0b135d08f2c46a9486ae3e9fb082
timeCreated: 1495457202
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


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

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


fileFormatVersion: 2
guid: 53bfb9e60f364eb44a4f0e0fc53f4325
timeCreated: 1495474251
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


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

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


fileFormatVersion: 2
guid: 8ffcc48ccff1aea44b90acb362bc0dfc
timeCreated: 1495659152
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/LevelsNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class LevelsControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as LevelsNode;
if (tNode == null)
return;
/*tNode.inputMin = EditorGUILayout.FloatField("InputMin:", tNode.inputMin);
tNode.inputMax = EditorGUILayout.FloatField("InputMax:", tNode.inputMax);
tNode.inputGamma = EditorGUILayout.FloatField("InputGamma:", tNode.inputGamma);
tNode.outputMin = EditorGUILayout.FloatField("OutputMin:", tNode.outputMin);
tNode.outputMax = EditorGUILayout.FloatField("OutputMax:", tNode.outputMax);*/
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 5 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class LevelsNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<LevelsControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SwizzleNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class SwizzleControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
/*var tNode = node as SwizzleNode;
if (tNode == null)
return;
SwizzleNode.SwizzleChannel[] newSwizzleChannels = (SwizzleNode.SwizzleChannel[])tNode.swizzleChannels.Clone();
EditorGUI.BeginChangeCheck();
newSwizzleChannels[0] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Red output:", newSwizzleChannels[0]);
newSwizzleChannels[1] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Green output:", newSwizzleChannels[1]);
newSwizzleChannels[2] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Blue output:", newSwizzleChannels[2]);
newSwizzleChannels[3] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Alpha output:", newSwizzleChannels[3]);
if (EditorGUI.EndChangeCheck())
{
tNode.swizzleChannels = newSwizzleChannels;
}*/
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SwizzleNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<SwizzleControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

49
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/MatrixCommonNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class MatrixCommonContolPresenter : GraphControlPresenter
{
private string[] m_MatrixTypeNames;
private string[] matrixTypeNames
{
get
{
if (m_MatrixTypeNames == null)
m_MatrixTypeNames = Enum.GetNames(typeof(CommonMatrixType));
return m_MatrixTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.MatrixCommonNode;
if (cNode == null)
return;
cNode.matrix = (CommonMatrixType)EditorGUILayout.Popup((int)cNode.matrix, matrixTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class MatrixCommonNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<MatrixCommonContolPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SamplerStateNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SamplerStateControlPresenter : GraphControlPresenter
{
private string[] samplerFilterMode;
private string[] samplerWrapMode;
private string[] _samplerFilterMode
{
get
{
if (samplerFilterMode == null)
samplerFilterMode = Enum.GetNames(typeof(TextureSamplerState.FilterMode));
return samplerFilterMode;
}
}
private string[] _samplerWrapMode
{
get
{
if (samplerWrapMode == null)
samplerWrapMode = Enum.GetNames(typeof(TextureSamplerState.WrapMode));
return samplerWrapMode;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as SamplerStateNode;
if (cNode == null)
return;
cNode.filter = (TextureSamplerState.FilterMode)EditorGUILayout.Popup((int)cNode.filter, _samplerFilterMode, EditorStyles.popup);
cNode.wrap = (TextureSamplerState.WrapMode)EditorGUILayout.Popup((int)cNode.wrap, _samplerWrapMode, EditorStyles.popup);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SamplerStateNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<SamplerStateControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/UVNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class UVNodeContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UVNode;
if (cNode == null)
return;
cNode.uvChannel = (UVChannel)EditorGUILayout.EnumPopup("Channel", cNode.uvChannel);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class UVNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<UVNodeContolPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}
正在加载...
取消
保存