浏览代码

[material Graph] Fix non detected renames and add subgraph nodes.

/main
Tim Cooper 9 年前
当前提交
25971c00
共有 25 个文件被更改,包括 105 次插入600 次删除
  1. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
  2. 28
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  3. 16
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  4. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  6. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs
  9. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphIONode.cs
  10. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs
  11. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs.meta
  12. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/AbstractMaterialGraph.cs
  13. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/AbstractMaterialGraph.cs.meta
  14. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraph.cs.meta
  15. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraphAsset.cs.meta
  16. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialOptions.cs.meta
  17. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/PixelGraph.cs.meta
  18. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/TitleAttribute.cs.meta
  19. 97
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraph.cs
  20. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraphAsset.cs
  21. 201
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialOptions.cs
  22. 101
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/PixelGraph.cs
  23. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/TitleAttribute.cs
  24. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphIONode.cs.meta
  25. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphIONode.cs

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs


// output port
pos.x = width;
pos.y = yStart;
bool first = true;
if (!node.drawState.expanded && !edges.Any())
if (!node.drawState.expanded && !edges.Any() && !first)
first = false;
}
pos.y += 22;

if (modificationType != GUIModificationType.None)
m_Data.MarkDirty();
if (modificationType == GUIModificationType.DataChanged)
if (modificationType == GUIModificationType.ModelChanged)
ValidateDependentNodes(m_Node);
m_Node.owner.ValidateGraph();
ParentCanvas().Invalidate();
ParentCanvas().ReloadData();
ParentCanvas().Repaint();

28
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


namespace UnityEditor.Graphing.Drawing
{
public class GraphEditWindow : AbstractGraphEditWindow<SerializableGraphAsset>
public class GraphEditWindow : AbstractGraphEditWindow<IGraphAsset>
{
[MenuItem("Window/Graph Editor")]
public static void OpenMenu()

}
public abstract class AbstractGraphEditWindow<T> : EditorWindow where T : ScriptableObject, IGraphAsset
public abstract class AbstractGraphEditWindow<T> : EditorWindow, ISerializationCallbackReceiver where T : class, IGraphAsset
[NonSerialized]
private T m_LastSelection;
private T m_LastSelection;
private ScriptableObject m_LastSelectedGraphSerialized;
[NonSerialized]
private Canvas2D m_Canvas;

if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject))
return;
if (Selection.activeObject is T)
if (Selection.activeObject is ScriptableObject)
var selection = (T) Selection.activeObject;
var selection = Selection.activeObject as T;
if (selection != m_LastSelection)
{
m_LastSelection = selection;

GUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}*/
public void OnBeforeSerialize()
{
var o = m_LastSelection as ScriptableObject;
if (o != null)
m_LastSelectedGraphSerialized = o;
}
public void OnAfterDeserialize()
{
if (m_LastSelectedGraphSerialized != null)
m_LastSelection = m_LastSelectedGraphSerialized as T;
m_LastSelectedGraphSerialized = null;
}
}
}

16
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


//manually modifies serialized data
//of if they delete a node in the inspector
//debug view.
var allNodeGUIDs = nodes.Select(x => x.guid).ToList();
if (allNodeGUIDs.Contains(edge.inputSlot.nodeGuid) && allNodeGUIDs.Contains(edge.outputSlot.nodeGuid))
continue;
var outputNode = GetNodeFromGuid(edge.outputSlot.nodeGuid);
var inputNode = GetNodeFromGuid(edge.inputSlot.nodeGuid);
//orphaned edge
RemoveEdgeNoValidate(edge);
if (outputNode == null
|| inputNode == null
|| outputNode.FindOutputSlot(edge.outputSlot.slotName) == null
|| inputNode.FindInputSlot(edge.inputSlot.slotName) == null)
{
//orphaned edge
RemoveEdgeNoValidate(edge);
}
}
foreach (var node in nodes)

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs


using System.IO;
using UnityEditor.ProjectWindowCallback;
using UnityEngine.MaterialGraph;
/*public class CreateShaderSubGraph : EndNameEditActionCallback
public class CreateShaderSubGraph : EndNameEditAction
[MenuItem("Assets/Create/Shader Sub-Graph", false, 209)]
[MenuItem("Assets/Create/Shader Sub Graph", false, 208)]
"New Shader SubGraph.ShaderSubGraph", null, null);
"New Shader Sub-Graph.ShaderSubGraph", null, null);
var graph = CreateInstance<MaterialSubGraph>();
var graph = CreateInstance<MaterialSubGraphAsset>();
graph.AddSubAssetsToAsset();
graph.PostCreate();
}*/
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


namespace UnityEditor.MaterialGraph
{
public class MaterialGraphEditWindow : AbstractGraphEditWindow<MaterialGraphAsset>
public class MaterialGraphEditWindow : AbstractGraphEditWindow<IMaterialGraphAsset>
{
[MenuItem("Window/Material Editor")]
public static void OpenMenu()

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs


namespace UnityEditor.MaterialGraph
{
[CustomNodeUI(typeof(AbstractMaterialNode))]
public class AbstractMaterialNodeUI : ICustomNodeUi
{

if (!m_Node.drawState.expanded)
return 0;
if (m_Node.hasPreview == false)
return 0;
m_PreviewWidth = width - 20;
return m_PreviewWidth;
}

public virtual GUIModificationType Render(Rect area)
{
if (m_Node == null || !m_Node.drawState.expanded)
return GUIModificationType.None;
if (m_Node.hasPreview == false)
return GUIModificationType.None;
if (m_LastShaderVersion != m_Node.version)

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs


namespace UnityEngine.MaterialGraph
{
public class SubGraphInputNode : SubGraphIOBaseNode, IGenerateProperties
public class SubGraphInputNode : AbstractSubGraphIONode, IGenerateProperties
{
public SubGraphInputNode(IGraph theOwner) : base(theOwner)
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs


namespace UnityEngine.MaterialGraph
{
public class SubGraphOutputNode : SubGraphIOBaseNode
public class SubGraphOutputNode : AbstractSubGraphIONode
{
public SubGraphOutputNode(IGraph theOwner) : base(theOwner)
{

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphIONode.cs


namespace UnityEngine.MaterialGraph
{
public abstract class SubGraphIOBaseNode : AbstractMaterialNode
public abstract class AbstractSubGraphIONode : AbstractMaterialNode
protected SubGraphIOBaseNode(IGraph theOwner) : base(theOwner)
protected AbstractSubGraphIONode(IGraph theOwner) : base(theOwner)
{}
/*public void FooterUI(GraphGUI host)

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs


using UnityEditor.Graphing;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph
{
[CustomNodeUI(typeof(AbstractSubGraphIONode))]
public class SubGraphIONodeUI : ICustomNodeUi
{
private AbstractSubGraphIONode m_Node;
public float GetNodeUiHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public GUIModificationType Render(Rect area)
{
return GUIModificationType.None;
}
public void SetNode(INode node)
{
if (node is AbstractSubGraphIONode)
m_Node = (AbstractSubGraphIONode) node;
}
public float GetNodeWidth()
{
return 100;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs.meta


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

56
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/AbstractMaterialGraph.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Serializable]
public abstract class AbstractMaterialGraph : SerializableGraph
{
public IEnumerable<AbstractMaterialNode> materialNodes
{
get { return nodes.OfType<AbstractMaterialNode>(); }
}
public bool requiresRepaint
{
get { return nodes.Any(x => x is IRequiresTime); }
}
public override void AddNode(INode node)
{
if (node is AbstractMaterialNode)
{
base.AddNode(node);
}
else
{
Debug.LogWarningFormat("Trying to add node {0} to Material graph, but it is not a {1}", node, typeof(AbstractMaterialNode));
}
}
public override bool RequiresConstantRepaint()
{
return nodes.OfType<IRequiresTime>().Any();
}
/*public PreviewRenderUtility previewUtility
{
get
{
if (m_PreviewUtility == null)
{
m_PreviewUtility = new PreviewRenderUtility();
EditorUtility.SetCameraAnimateMaterials(m_PreviewUtility.m_Camera, true);
}
return m_PreviewUtility;
}
}
[NonSerialized]
private PreviewRenderUtility m_PreviewUtility;*/
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/AbstractMaterialGraph.cs.meta


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraph.cs.meta


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraphAsset.cs.meta


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialOptions.cs.meta


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/PixelGraph.cs.meta


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/TitleAttribute.cs.meta


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

97
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraph.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace UnityEngine.MaterialGraph
{
[Serializable]
public class MaterialGraph
{
[SerializeField]
private MaterialOptions m_MaterialOptions = new MaterialOptions();
[SerializeField]
private PixelGraph m_PixelGraph;
[SerializeField]
private string m_Name;
public string name
{
get { return m_Name; }
set { m_Name = value; }
}
public MaterialGraph()
{
m_PixelGraph = new PixelGraph();
}
public MaterialOptions materialOptions
{
get { return m_MaterialOptions; }
}
public AbstractMaterialGraph currentGraph
{
get { return m_PixelGraph; }
}
/*
public Material GetMaterial()
{
if (m_PixelGraph == null)
return null;
return m_PixelGraph.GetMaterial();
}
public void ExportShader(string path)
{
List<PropertyGenerator.TextureInfo> configuredTextures;
var shaderString = ShaderGenerator.GenerateSurfaceShader(this, name, false, out configuredTextures);
File.WriteAllText(path, shaderString);
AssetDatabase.Refresh(); // Investigate if this is optimal
var shader = AssetDatabase.LoadAssetAtPath(path, typeof(Shader)) as Shader;
if (shader == null)
return;
var shaderImporter = AssetImporter.GetAtPath(path) as ShaderImporter;
if (shaderImporter == null)
return;
var textureNames = new List<string>();
var textures = new List<Texture>();
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable))
{
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture;
if (texture == null)
continue;
textureNames.Add(textureInfo.name);
textures.Add(texture);
}
shaderImporter.SetDefaultTextures(textureNames.ToArray(), textures.ToArray());
textureNames.Clear();
textures.Clear();
foreach (var textureInfo in configuredTextures.Where(x => !x.modifiable))
{
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture;
if (texture == null)
continue;
textureNames.Add(textureInfo.name);
textures.Add(texture);
}
shaderImporter.SetNonModifiableTextures(textureNames.ToArray(), textures.ToArray());
shaderImporter.SaveAndReimport();
}*/
public void PostCreate()
{
m_PixelGraph.AddNode(new PixelShaderNode(m_PixelGraph));
}
}
}

36
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraphAsset.cs


using System.Linq;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
public class MaterialGraphAsset : ScriptableObject, IGraphAsset
{
[SerializeField]
private MaterialGraph m_MaterialGraph;
public IGraph graph
{
get { return m_MaterialGraph.currentGraph; }
}
public bool shouldRepaint
{
get { return graph.nodes.OfType<IRequiresTime>().Any(); }
}
public ScriptableObject GetScriptableObject()
{
return this;
}
public Material GetMaterial()
{
return null;
}
public void PostCreate()
{
m_MaterialGraph.PostCreate();
}
}
}

201
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialOptions.cs


using System;
using UnityEngine;
namespace UnityEngine.MaterialGraph
{
[Serializable]
public class MaterialOptions
{
public enum BlendMode
{
One,
Zero,
SrcColor,
SrcAlpha,
DstColor,
DstAlpha,
OneMinusSrcColor,
OneMinusSrcAlpha,
OneMinusDstColor,
OneMinusDstAlpha,
}
public enum CullMode
{
Back,
Front,
Off
}
public enum ZTest
{
Less,
Greater,
LEqual,
GEqual,
Equal,
NotEqual,
Always
}
public enum ZWrite
{
On,
Off
}
public enum RenderQueue
{
Background,
Geometry,
Transparent,
Overlay,
}
public enum RenderType
{
Opaque,
Transparent,
TransparentCutout,
Background,
Overlay
}
[SerializeField]
private BlendMode m_SrcBlend;
[SerializeField]
private BlendMode m_DstBlend;
[SerializeField]
private CullMode m_CullMode;
[SerializeField]
private ZTest m_ZTest;
[SerializeField]
private ZWrite m_ZWrite;
[SerializeField]
private RenderQueue m_RenderQueue;
[SerializeField]
private RenderType m_RenderType;
[SerializeField]
private bool m_ShadowPass;
[SerializeField]
private bool m_FullForwardShadows;
[SerializeField]
private bool m_NoAmbient;
[SerializeField]
private bool m_NoVertexLights;
[SerializeField]
private bool m_NoLightmaps;
[SerializeField]
private bool m_NoDirLightmap;
[SerializeField]
private bool m_NoForwardAdd;
[SerializeField]
private bool m_ApproxView;
[SerializeField]
private bool m_HalfAsView;
[SerializeField]
private bool m_Expanded;
public void Init()
{
srcBlend = BlendMode.One;
dstBlend = BlendMode.Zero;
cullMode = CullMode.Back;
zTest = ZTest.LEqual;
zWrite = ZWrite.On;
renderQueue = RenderQueue.Geometry;
renderType = RenderType.Opaque;
shadowPass = false;
fullForwardShadows = false;
noAmbient = false;
noVertexLights = false;
noLightmaps = false;
noDirLightmap = false;
noForwardAdd = false;
approxView = false;
halfAsView = false;
}
public void GetTags(ShaderGenerator visitor)
{
visitor.AddShaderChunk("Tags {", false);
visitor.Indent();
visitor.AddShaderChunk("\"RenderType\"=\"" + renderType + "\"", false);
visitor.AddShaderChunk("\"Queue\"=\"" + renderQueue + "\"", false);
visitor.Deindent();
visitor.AddShaderChunk("}", false);
}
public void GetBlend(ShaderGenerator visitor)
{
visitor.AddShaderChunk("Blend " + srcBlend + " " + dstBlend, false);
}
public void GetCull(ShaderGenerator visitor)
{
visitor.AddShaderChunk("Cull " + cullMode, false);
}
public void GetDepthWrite(ShaderGenerator visitor)
{
visitor.AddShaderChunk("ZWrite " + zWrite, false);
}
public void GetDepthTest(ShaderGenerator visitor)
{
visitor.AddShaderChunk("ZTest " + zTest, false);
}
/*private Vector2 m_ScrollPos;
public void DoGUI()
{
GUILayout.BeginVertical();
m_Expanded = MaterialGraphStyles.Header("Options", m_Expanded);
if (m_Expanded)
{
srcBlend = (BlendMode) EditorGUILayout.EnumPopup("Src Blend", srcBlend);
dstBlend = (BlendMode) EditorGUILayout.EnumPopup("Dst Blend", dstBlend);
cullMode = (CullMode) EditorGUILayout.EnumPopup("Cull Mode", cullMode);
zTest = (ZTest) EditorGUILayout.EnumPopup("Z Test", zTest);
zWrite = (ZWrite) EditorGUILayout.EnumPopup("Z Write", zWrite);
renderQueue = (RenderQueue) EditorGUILayout.EnumPopup("Render Queue", renderQueue);
renderType = (RenderType) EditorGUILayout.EnumPopup("Render Type", renderType);
}
GUILayout.EndVertical();
}*/
public BlendMode srcBlend { get { return m_SrcBlend; } set { m_SrcBlend = value; } }
public BlendMode dstBlend { get { return m_DstBlend; } set { m_DstBlend = value; } }
public CullMode cullMode { get { return m_CullMode; } set { m_CullMode = value; } }
public ZTest zTest { get { return m_ZTest; } set { m_ZTest = value; } }
public ZWrite zWrite { get { return m_ZWrite; } set { m_ZWrite = value; } }
public RenderQueue renderQueue { get { return m_RenderQueue; } set { m_RenderQueue = value; } }
public RenderType renderType { get { return m_RenderType; } set { m_RenderType = value; } }
public bool shadowPass { get { return m_ShadowPass; } set { m_ShadowPass = value; } }
public bool fullForwardShadows { get { return m_FullForwardShadows; } set { m_FullForwardShadows = value; } }
public bool noAmbient { get { return m_NoAmbient; } set { m_NoAmbient = value; } }
public bool noVertexLights { get { return m_NoVertexLights; } set { m_NoVertexLights = value; } }
public bool noLightmaps { get { return m_NoLightmaps; } set { m_NoLightmaps = value; } }
public bool noDirLightmap { get { return m_NoDirLightmap; } set { m_NoDirLightmap = value; } }
public bool noForwardAdd { get { return m_NoForwardAdd; } set { m_NoForwardAdd = value; } }
public bool approxView { get { return m_ApproxView; } set { m_ApproxView = value; } }
public bool halfAsView { get { return m_HalfAsView; } set { m_HalfAsView = value; } }
}
}

101
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/PixelGraph.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Serializable]
public class PixelGraph : AbstractMaterialGraph
{
[NonSerialized]
private PixelShaderNode m_PixelMasterNode;
public PixelShaderNode pixelMasterNode
{
get
{
// find existing node
if (m_PixelMasterNode == null)
m_PixelMasterNode = nodes.FirstOrDefault(x => x.GetType() == typeof(PixelShaderNode)) as PixelShaderNode;
return m_PixelMasterNode;
}
}
[NonSerialized]
private List<INode> m_ActiveNodes = new List<INode>();
public IEnumerable<AbstractMaterialNode> activeNodes
{
get
{
m_ActiveNodes.Clear();
NodeUtils.DepthFirstCollectNodesFromNode(m_ActiveNodes, pixelMasterNode);
return m_ActiveNodes.OfType<AbstractMaterialNode>();
}
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_PixelMasterNode = null;
}
public override void AddNode(INode node)
{
if (pixelMasterNode != null && node is PixelShaderNode)
{
Debug.LogWarning("Attempting to add second PixelShaderNode to PixelGraph. This is not allowed.");
return;
}
base.AddNode(node);
}
public static void GenerateSurfaceShader(
PixelShaderNode pixelNode,
ShaderGenerator shaderBody,
ShaderGenerator inputStruct,
ShaderGenerator lightFunction,
ShaderGenerator surfaceOutput,
ShaderGenerator nodeFunction,
PropertyGenerator shaderProperties,
ShaderGenerator propertyUsages,
ShaderGenerator vertexShader,
bool isPreview)
{
pixelNode.GenerateLightFunction(lightFunction);
pixelNode.GenerateSurfaceOutput(surfaceOutput);
var genMode = isPreview ? GenerationMode.Preview3D : GenerationMode.SurfaceShader;
var activeNodes = new List<INode>();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodes, pixelNode);
var activeMaterialNodes = activeNodes.OfType<AbstractMaterialNode>();
foreach (var node in activeMaterialNodes)
{
if (node is IGeneratesFunction) (node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, genMode);
if (node is IGeneratesVertexToFragmentBlock) (node as IGeneratesVertexToFragmentBlock).GenerateVertexToFragmentBlock(inputStruct, genMode);
if (node is IGeneratesVertexShaderBlock) (node as IGeneratesVertexShaderBlock).GenerateVertexShaderBlock(vertexShader, genMode);
if (node is IGenerateProperties)
{
(node as IGenerateProperties).GeneratePropertyBlock(shaderProperties, genMode);
(node as IGenerateProperties).GeneratePropertyUsages(propertyUsages, genMode, ConcreteSlotValueType.Vector4);
}
}
pixelNode.GenerateNodeCode(shaderBody, genMode);
}
/*
public Material GetMaterial()
{
if (pixelMasterNode == null)
return null;
var material = pixelMasterNode.previewMaterial;
AbstractMaterialNode.UpdateMaterialProperties(pixelMasterNode, material);
return material;
}*/
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/TitleAttribute.cs


using System;
namespace UnityEngine.MaterialGraph
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
public class TitleAttribute : Attribute
{
public string m_Title;
public TitleAttribute(string title) { m_Title = title; }
}
}

/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphIOBaseNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphIONode.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphIOBaseNode.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphIONode.cs

正在加载...
取消
保存