浏览代码

Remove last node presenters and also type mapper in MaterialGraphPresenter

/main
Peter Bay Bastian 7 年前
当前提交
3790252c
共有 14 个文件被更改,包括 56 次插入215 次删除
  1. 5
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/BlendModeNode.cs
  2. 2
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs
  3. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
  5. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  7. 12
      MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs.meta
  8. 12
      MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs.meta
  9. 12
      MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs.meta
  10. 43
      MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs
  11. 49
      MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs
  12. 45
      MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs
  13. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta

5
MaterialGraphProject/Assets/NewNodes/Editor/Keep/BlendModeNode.cs


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

}
[SerializeField]
private BlendModesEnum m_BlendMode;
BlendModesEnum m_BlendMode;
[EnumControl("")]
public BlendModesEnum blendMode
{
get { return m_BlendMode; }

2
MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs


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

private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Constant";
[EnumControl("")]
public ConstantType constant
{
get { return m_constant; }

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs


using System;
using System.Reflection;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

name = "SubGraphOutputs";
}
[SubGraphOutputControl]
int controlDummy { get; set; }
public override int AddSlot()
{
var index = GetInputSlots<ISlot>().Count() + 1;

}
public override bool allowedInRemapGraph { get { return false; } }
}
public class SubGraphOutputControlAttribute : Attribute, IControlAttribute
{
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (!(node is AbstractSubGraphIONode))
throw new ArgumentException("Node must inherit from AbstractSubGraphIONode.", "node");
return new SubGraphOutputControlView((AbstractSubGraphIONode)node);
}
}
public class SubGraphOutputControlView : VisualElement
{
AbstractSubGraphIONode m_Node;
public SubGraphOutputControlView(AbstractSubGraphIONode node)
{
m_Node = node;
Add(new Button(OnAdd) { text = "Add Slot" });
Add(new Button(OnRemove) { text = "Remove Slot" });
}
void OnAdd()
{
m_Node.AddSlot();
}
void OnRemove()
{
m_Node.RemoveSlot();
}
}
}

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


using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{

public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (propertyInfo.PropertyType == typeof(Color))
return new ColorControlView(null, node, propertyInfo);
if (typeof(Enum).IsAssignableFrom(propertyInfo.PropertyType))
return new EnumControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Gradient))
return new GradientControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Color))
return new ColorControlView(null, node, propertyInfo);
if (typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
return new ObjectControlView(null, node, propertyInfo);
return null;
}
}

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


[Serializable]
public class MaterialGraphPresenter : GraphViewPresenter
{
GraphTypeMapper typeMapper { get; set; }
PreviewSystem m_PreviewSystem;
public IGraph graph { get; private set; }

protected MaterialGraphPresenter()
{
typeMapper = new GraphTypeMapper(typeof(MaterialNodePresenter));
typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
// typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
//typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
//typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);
//typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
// typeMapper[typeof(Texture2DNode)] = typeof(TextureAssetNodePresenter);
// typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
// typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
// typeMapper[typeof(ToggleNode)] = typeof(ToggleNodePresenter);
/* typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(RadialShearNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphereWarpNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphericalIndentationNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboardNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboard3dNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter*/
typeMapper[typeof(SubGraphNode)] = typeof(SubgraphNodePresenter);
typeMapper[typeof(MasterRemapNode)] = typeof(MasterRemapNodePresenter);
// typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);
typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
// typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterNodePresenter);
typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
//typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
typeMapper[typeof(BlendModeNode)] = typeof(BlendModeNodePresenter);
// typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
//typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
// typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);
}
public override List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)

void NodeAdded(NodeAddedGraphChange change)
{
var nodePresenter = (MaterialNodePresenter)typeMapper.Create(change.node);
var nodePresenter = CreateInstance<MaterialNodePresenter>();
change.node.onModified += OnNodeChanged;
nodePresenter.Initialize(change.node, m_PreviewSystem);
m_Elements.Add(nodePresenter);

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


if (!nodePresenter.node.guid.Equals(m_NodeGuid))
{
m_ControlViews.Clear();
foreach (var propertyInfo in nodePresenter.node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
foreach (var propertyInfo in nodePresenter.node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false))
m_ControlViews.Add(attribute.InstantiateControl(nodePresenter.node, propertyInfo));

12
MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs.meta


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

12
MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs.meta


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

12
MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs.meta


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

43
MaterialGraphProject/Assets/NewNodes/Editor/BlendModeNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class BlendModeNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as BlendModeNode;
if (cNode == null)
return;
cNode.blendMode = (BlendModesEnum)EditorGUILayout.EnumPopup("", cNode.blendMode);
}
/* public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
*/
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class BlendModeNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<BlendModeNodeControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

49
MaterialGraphProject/Assets/NewNodes/Editor/ConstantsNodePresenter.cs


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

45
MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
/* [Serializable]
class ToggleNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as ToggleNode;
if (cNode == null)
return;
cNode.value = EditorGUILayout.Toggle(cNode.value);
cNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), cNode.exposedState);
}
/* public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
*
public override float GetHeight()
{
return 2 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ToggleNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<ToggleNodeControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}*/
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta


fileFormatVersion: 2
guid: 7e4695133ddd49cf97b1629ca5537e5b
timeCreated: 1502981029
正在加载...
取消
保存