Tim Cooper
7 年前
当前提交
2f0a0145
共有 19 个文件被更改,包括 2 次插入 和 662 次删除
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/MaterialGraphChange.cs
-
51MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateRemapGraph.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateLayeredShaderGraph.cs.meta
-
23MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateRemapGraph.cs
-
24MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateLayeredShaderGraph.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/LayerWeightsOutputNode.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/LayeredShaderGraph.cs.meta
-
34MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/LayerWeightsOutputNode.cs
-
381MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/LayeredShaderGraph.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Remapper.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderLayerview.cs.meta
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderLayerview.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporter.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporterEditor.cs.meta
-
23MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporter.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporterEditor.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 2870633e85d1cdd47b6b6d5e576187d1 |
|||
timeCreated: 1481188587 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0c11588a25854ed5bd03171503c84789 |
|||
timeCreated: 1507403047 |
|
|||
using System.IO; |
|||
using UnityEditor.ProjectWindowCallback; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class CreateRemapGraph : EndNameEditAction |
|||
{ |
|||
[MenuItem("Assets/Create/Shader Remap Graph", false, 209)] |
|||
public static void CreateMaterialRemapGraph() |
|||
{ |
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateRemapGraph>(), |
|||
"New Remap-Graph.ShaderRemapGraph", null, null); |
|||
} |
|||
|
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
var graph = new MasterRemapGraph(); |
|||
File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph)); |
|||
AssetDatabase.Refresh(); |
|||
} |
|||
} |
|||
} |
|
|||
using System.IO; |
|||
using UnityEditor.ProjectWindowCallback; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class CreateLayeredShaderGraph : EndNameEditAction |
|||
{ |
|||
[MenuItem("Assets/Create/Layered Shader Graph", false, 208)] |
|||
public static void CreateLayeredGraph() |
|||
{ |
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateLayeredShaderGraph>(), |
|||
"New Layerd Shader Graph.LayeredShaderGraph", null, null); |
|||
} |
|||
|
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
var graph = new LayeredShaderGraph(); |
|||
graph.AddNode(new LayerWeightsOutputNode()); |
|||
File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph)); |
|||
AssetDatabase.Refresh(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 789274d827ef4cb2a635638cb2a24718 |
|||
timeCreated: 1507401785 |
|
|||
fileFormatVersion: 2 |
|||
guid: 8ce99f0c764243ab9e2713566d4105af |
|||
timeCreated: 1507398692 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class LayerWeightsOutputNode : AbstractMaterialNode, IOnAssetEnabled |
|||
{ |
|||
public LayerWeightsOutputNode() |
|||
{ |
|||
name = "LayerWeights"; |
|||
} |
|||
|
|||
public override bool allowedInRemapGraph { get { return false; } } |
|||
public override bool allowedInSubGraph { get { return false; } } |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
var layeredGraph = owner as LayeredShaderGraph; |
|||
if (layeredGraph == null) |
|||
return; |
|||
|
|||
var goodSlots = new List<int>(); |
|||
foreach (var layer in layeredGraph.layers) |
|||
{ |
|||
AddSlot(new Vector1MaterialSlot(layer.guid.GetHashCode(), LayeredShaderGraph.LayerToFunctionName(layer.guid), LayeredShaderGraph.LayerToFunctionName(layer.guid), SlotType.Input, 0)); |
|||
goodSlots.Add(layer.guid.GetHashCode()); |
|||
} |
|||
|
|||
RemoveSlotsNameNotMatching(goodSlots); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class LayeredShaderGraph : AbstractMaterialGraph, IShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Layer |
|||
{ |
|||
[SerializeField] |
|||
private SerializableGuid m_Guid = new SerializableGuid(); |
|||
|
|||
[SerializeField] |
|||
private Shader m_Shader; |
|||
|
|||
public Layer() {} |
|||
|
|||
public Guid guid |
|||
{ |
|||
get { return m_Guid.guid; } |
|||
} |
|||
|
|||
public Shader shader |
|||
{ |
|||
get { return m_Shader; } |
|||
set { m_Shader = value; } |
|||
} |
|||
} |
|||
|
|||
[NonSerialized] |
|||
private List<Layer> m_Layers = new List<Layer>(); |
|||
|
|||
[NonSerialized] |
|||
List<Layer> m_AddedLayers = new List<Layer>(); |
|||
|
|||
[NonSerialized] |
|||
List<Guid> m_RemovedLayers = new List<Guid>(); |
|||
|
|||
[SerializeField] |
|||
List<SerializationHelper.JSONSerializedElement> m_SerializedLayers = new List<SerializationHelper.JSONSerializedElement>(); |
|||
|
|||
public IEnumerable<Layer> layers |
|||
{ |
|||
get { return m_Layers; } |
|||
} |
|||
|
|||
public List<Layer> addedLayers |
|||
{ |
|||
get { return m_AddedLayers; } |
|||
} |
|||
|
|||
public List<Guid> removedLayers |
|||
{ |
|||
get { return m_RemovedLayers; } |
|||
} |
|||
|
|||
[NonSerialized] |
|||
private LayerWeightsOutputNode m_OutputNode; |
|||
|
|||
public LayerWeightsOutputNode outputNode |
|||
{ |
|||
get |
|||
{ |
|||
// find existing node
|
|||
if (m_OutputNode == null) |
|||
m_OutputNode = GetNodes<LayerWeightsOutputNode>().FirstOrDefault(); |
|||
|
|||
return m_OutputNode; |
|||
} |
|||
} |
|||
|
|||
public override void ClearChanges() |
|||
{ |
|||
base.ClearChanges(); |
|||
m_AddedLayers.Clear(); |
|||
m_RemovedLayers.Clear(); |
|||
} |
|||
|
|||
public override void AddNode(INode node) |
|||
{ |
|||
if (outputNode != null && node is LayerWeightsOutputNode) |
|||
{ |
|||
Debug.LogWarning("Attempting to add second LayerWeightsOutputNode to LayeredShaderGraph. This is not allowed."); |
|||
return; |
|||
} |
|||
|
|||
base.AddNode(node); |
|||
} |
|||
|
|||
public void AddLayer() |
|||
{ |
|||
var layer = new Layer(); |
|||
m_Layers.Add(layer); |
|||
m_AddedLayers.Add(layer); |
|||
|
|||
if (outputNode != null) |
|||
outputNode.onModified(outputNode, ModificationScope.Graph); |
|||
} |
|||
|
|||
public bool SetLayer(Guid layerId, Shader newShader) |
|||
{ |
|||
try |
|||
{ |
|||
var path = AssetDatabase.GetAssetPath(newShader); |
|||
|
|||
if (!path.EndsWith("shaderGraph", StringComparison.InvariantCultureIgnoreCase)) |
|||
return false; |
|||
|
|||
var textGraph = File.ReadAllText(path, Encoding.UTF8); |
|||
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph); |
|||
if (graph == null) |
|||
return false; |
|||
|
|||
var layer = layers.FirstOrDefault(x => x.guid == layerId); |
|||
if (layer == null) |
|||
return false; |
|||
|
|||
layer.shader = newShader; |
|||
|
|||
if (outputNode != null) |
|||
{ |
|||
outputNode.OnEnable(); |
|||
outputNode.onModified(outputNode, ModificationScope.Graph); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
// ignored
|
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public void RemoveLayer(Guid id) |
|||
{ |
|||
var num = m_Layers.RemoveAll(x => x.guid == id); |
|||
|
|||
if (num > 0) |
|||
{ |
|||
m_RemovedLayers.Add(id); |
|||
|
|||
if (outputNode != null) |
|||
outputNode.onModified(outputNode, ModificationScope.Graph); |
|||
} |
|||
} |
|||
|
|||
public override void OnBeforeSerialize() |
|||
{ |
|||
base.OnBeforeSerialize(); |
|||
m_SerializedLayers = SerializationHelper.Serialize<Layer>(m_Layers); |
|||
} |
|||
|
|||
public override void OnAfterDeserialize() |
|||
{ |
|||
m_OutputNode = null; |
|||
m_Layers = SerializationHelper.Deserialize<Layer>(m_SerializedLayers, null); |
|||
m_SerializedLayers = null; |
|||
base.OnAfterDeserialize(); |
|||
} |
|||
|
|||
public static string LayerToFunctionName(Guid id) |
|||
{ |
|||
return string.Format("Layer_{0}", GuidEncoder.Encode(id)); |
|||
} |
|||
|
|||
public string GetShader(string name, GenerationMode mode, out List<PropertyCollector.TextureInfo> configuredTextures) |
|||
{ |
|||
if (outputNode == null) |
|||
throw new InvalidOperationException(); |
|||
|
|||
var layerMap = new Dictionary<Guid, MaterialGraph>(); |
|||
|
|||
foreach (var layer in layers) |
|||
{ |
|||
var path = AssetDatabase.GetAssetPath(layer.shader); |
|||
|
|||
if (!path.EndsWith("shaderGraph", StringComparison.InvariantCultureIgnoreCase)) |
|||
continue; |
|||
|
|||
var textGraph = File.ReadAllText(path, Encoding.UTF8); |
|||
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph); |
|||
if (graph == null) |
|||
continue; |
|||
|
|||
layerMap[layer.guid] = graph; |
|||
} |
|||
|
|||
if (layerMap.Count == 0) |
|||
{ |
|||
configuredTextures = new List<PropertyCollector.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
var vertexShader = new ShaderGenerator(); |
|||
var layerShaders = new ShaderGenerator(); |
|||
var surfaceDescriptionFunction = new ShaderGenerator(); |
|||
var surfaceDescriptionStruct = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var surfaceInputs = new ShaderGenerator(); |
|||
|
|||
var graphVertexInput = @"
|
|||
struct GraphVertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
float4 tangent : TANGENT; |
|||
float4 texcoord0 : TEXCOORD0; |
|||
float4 lightmapUV : TEXCOORD1; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
};";
|
|||
|
|||
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false); |
|||
surfaceInputs.Indent(); |
|||
|
|||
using (var activeNodesDisposable = ListPool<INode>.GetDisposable()) |
|||
{ |
|||
var activeNodes = activeNodesDisposable.value; |
|||
foreach (var layer in layerMap) |
|||
{ |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodes, layer.Value.masterNode as AbstractMaterialNode); |
|||
} |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodes, outputNode); |
|||
var requirements = GetRequirements(activeNodes); |
|||
|
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresViewDir, InterpolatorType.ViewDirection, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresPosition, InterpolatorType.Position, surfaceInputs); |
|||
|
|||
if (requirements.requiresVertexColor) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.VertexColor), false); |
|||
|
|||
if (requirements.requiresScreenPosition) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.ScreenPosition), false); |
|||
|
|||
foreach (var channel in requirements.requiresMeshUVs.Distinct()) |
|||
surfaceInputs.AddShaderChunk(string.Format("half4 {0};", channel.GetUVName()), false); |
|||
|
|||
surfaceInputs.Deindent(); |
|||
surfaceInputs.AddShaderChunk("};", false); |
|||
|
|||
vertexShader.AddShaderChunk("GraphVertexInput PopulateVertexData(GraphVertexInput v){", false); |
|||
vertexShader.Indent(); |
|||
vertexShader.AddShaderChunk("return v;", false); |
|||
vertexShader.Deindent(); |
|||
vertexShader.AddShaderChunk("}", false); |
|||
|
|||
var shaderProperties = new PropertyCollector(); |
|||
|
|||
var baseGraph = layerMap.Values.FirstOrDefault(); |
|||
if (baseGraph == null) |
|||
{ |
|||
configuredTextures = new List<PropertyCollector.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
var masterNode = baseGraph.masterNode; |
|||
GenerateSurfaceDescriptionStruct(surfaceDescriptionStruct, ((AbstractMaterialNode)masterNode).GetInputSlots<MaterialSlot>().ToList(), true); |
|||
|
|||
/* foreach (var layer in layerMap) |
|||
{ |
|||
activeNodes.Clear(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodes, layer.Value.masterNode as AbstractMaterialNode); |
|||
GenerateSurfaceDescription( |
|||
activeNodes, |
|||
layer.Value.masterNode as AbstractMaterialNode, |
|||
this, |
|||
surfaceDescriptionFunction, |
|||
shaderFunctionVisitor, |
|||
shaderProperties, |
|||
requirements, |
|||
mode, |
|||
LayerToFunctionName(layer.Key)); |
|||
}*/ |
|||
|
|||
surfaceDescriptionStruct.AddShaderChunk("struct WeightsSurfaceDescription{", false); |
|||
surfaceDescriptionStruct.Indent(); |
|||
|
|||
foreach (var slot in outputNode.GetInputSlots<MaterialSlot>()) |
|||
surfaceDescriptionStruct.AddShaderChunk(AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType) + " " + slot.shaderOutputName + ";", false); |
|||
|
|||
surfaceDescriptionStruct.Deindent(); |
|||
surfaceDescriptionStruct.AddShaderChunk("};", false); |
|||
|
|||
activeNodes.Clear(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodes, outputNode); |
|||
/*GenerateSurfaceDescription( |
|||
activeNodes, |
|||
outputNode, |
|||
this, |
|||
surfaceDescriptionFunction, |
|||
shaderFunctionVisitor, |
|||
shaderProperties, |
|||
requirements, |
|||
mode, |
|||
"PopulateWeightsGraph", |
|||
"WeightsSurfaceDescription"); |
|||
*/ |
|||
|
|||
string functionName = "PopulateSurfaceData"; |
|||
string surfaceDescriptionName = "SurfaceDescription"; |
|||
layerShaders.AddShaderChunk(string.Format("{0} {1}(SurfaceInputs IN) {{", surfaceDescriptionName, functionName), false); |
|||
layerShaders.Indent(); |
|||
|
|||
layerShaders.AddShaderChunk("WeightsSurfaceDescription weights = PopulateWeightsGraph(IN);", false); |
|||
layerShaders.AddShaderChunk("SurfaceDescription result = (SurfaceDescription)0;", false); |
|||
|
|||
foreach (var layer in layerMap) |
|||
{ |
|||
layerShaders.AddShaderChunk( |
|||
string.Format( |
|||
"{0} {1} = {2}({3});", |
|||
surfaceDescriptionName, |
|||
LayerToFunctionName(layer.Key) + "_surface", |
|||
LayerToFunctionName(layer.Key), |
|||
"IN"), false); |
|||
|
|||
layerShaders.AddShaderChunk( |
|||
string.Format("ScaleSurfaceDescription({0}_surface, weights.{0});", LayerToFunctionName(layer.Key)), false); |
|||
|
|||
layerShaders.AddShaderChunk(string.Format("AddSurfaceDescription(result, {0}_surface);", LayerToFunctionName(layer.Key)), false); |
|||
} |
|||
layerShaders.AddShaderChunk("return result;", false); |
|||
|
|||
layerShaders.Deindent(); |
|||
layerShaders.AddShaderChunk("}", false); |
|||
|
|||
var finalShader = new ShaderGenerator(); |
|||
finalShader.AddShaderChunk(string.Format(@"Shader ""{0}""", name), false); |
|||
finalShader.AddShaderChunk("{", false); |
|||
finalShader.Indent(); |
|||
|
|||
finalShader.AddShaderChunk("Properties", false); |
|||
finalShader.AddShaderChunk("{", false); |
|||
finalShader.Indent(); |
|||
finalShader.AddShaderChunk(shaderProperties.GetPropertiesBlock(2), false); |
|||
finalShader.Deindent(); |
|||
finalShader.AddShaderChunk("}", false); |
|||
|
|||
finalShader.AddShaderChunk("CGINCLUDE", false); |
|||
finalShader.AddShaderChunk("#include \"UnityCG.cginc\"", false); |
|||
finalShader.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false); |
|||
finalShader.AddShaderChunk(graphVertexInput, false); |
|||
finalShader.AddShaderChunk(surfaceInputs.GetShaderString(2), false); |
|||
finalShader.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false); |
|||
finalShader.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false); |
|||
finalShader.AddShaderChunk(vertexShader.GetShaderString(2), false); |
|||
finalShader.AddShaderChunk(surfaceDescriptionFunction.GetShaderString(2), false); |
|||
finalShader.AddShaderChunk(layerShaders.GetShaderString(2), false); |
|||
finalShader.AddShaderChunk("ENDCG", false); |
|||
|
|||
if (masterNode != null) |
|||
{ |
|||
//var subShaders = masterNode.GetSubshader(requirements, null);
|
|||
// foreach (var ss in subShaders)
|
|||
// finalShader.AddShaderChunk(ss, false);
|
|||
} |
|||
|
|||
finalShader.Deindent(); |
|||
finalShader.AddShaderChunk("}", false); |
|||
configuredTextures = shaderProperties.GetConfiguredTexutres(); |
|||
return finalShader.GetShaderString(0); |
|||
} |
|||
} |
|||
|
|||
public void LoadedFromDisk() |
|||
{ |
|||
OnEnable(); |
|||
ValidateGraph(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5f3c6a912dd29fb459196f8efdda853f |
|||
folderAsset: yes |
|||
timeCreated: 1481188026 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e1839e94c8024ee6a36ff3aa05cef37b |
|||
timeCreated: 1507451136 |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Inspector |
|||
{ |
|||
public class ShaderLayerView : VisualElement |
|||
{ |
|||
public LayeredShaderGraph graph { get; private set; } |
|||
public LayeredShaderGraph.Layer layer { get; private set; } |
|||
|
|||
public ShaderLayerView(LayeredShaderGraph graph, LayeredShaderGraph.Layer layer) |
|||
{ |
|||
this.graph = graph; |
|||
this.layer = layer; |
|||
|
|||
Add(new IMGUIContainer(ValueField) { name = "value" }); |
|||
Add(new Button(OnClickRemove) { name = "remove", text = "Remove" }); |
|||
} |
|||
|
|||
void OnClickRemove() |
|||
{ |
|||
graph.RemoveLayer(layer.guid); |
|||
NotifyNodes(); |
|||
} |
|||
|
|||
void ValueField() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
var newShader = EditorGUILayout.ObjectField("Shader", layer.shader, typeof(Shader), false) as Shader; |
|||
if (newShader != layer.shader) |
|||
{ |
|||
if (graph.SetLayer(layer.guid, newShader)) |
|||
NotifyNodes(); |
|||
} |
|||
} |
|||
|
|||
void NotifyNodes() |
|||
{ |
|||
foreach (var node in graph.GetNodes<PropertyNode>()) |
|||
node.onModified(node, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 47e38a0256e24cec8792d9cfae7023b2 |
|||
timeCreated: 1506845544 |
|
|||
fileFormatVersion: 2 |
|||
guid: 4dd321ee05034e7a967503617a02c1f4 |
|||
timeCreated: 1506845783 |
|
|||
using System.IO; |
|||
using System.Text; |
|||
using UnityEditor.Experimental.AssetImporters; |
|||
using UnityEngine; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
[ScriptedImporter(1, "ShaderRemapGraph")] |
|||
public class MasterRemapGraphImporter : ScriptedImporter |
|||
{ |
|||
public override void OnImportAsset(AssetImportContext ctx) |
|||
{ |
|||
var textGraph = File.ReadAllText(ctx.assetPath, Encoding.UTF8); |
|||
var graph = JsonUtility.FromJson<MasterRemapGraph>(textGraph); |
|||
|
|||
if (graph == null) |
|||
return; |
|||
|
|||
var graphAsset = ScriptableObject.CreateInstance<MasterRemapGraphAsset>(); |
|||
graphAsset.remapGraph = graph; |
|||
ctx.AddObjectToAsset("MainAsset", graphAsset); |
|||
ctx.SetMainObject(graphAsset); |
|||
} |
|||
} |
|
|||
using UnityEditor; |
|||
using UnityEditor.Callbacks; |
|||
using UnityEditor.Experimental.AssetImporters; |
|||
using UnityEditor.ShaderGraph.Drawing; |
|||
using UnityEngine; |
|||
using UnityEditor.ShaderGraph; |
|||
using Debug = System.Diagnostics.Debug; |
|||
|
|||
[CustomEditor(typeof(MasterRemapGraphImporter))] |
|||
public class MasterRemapGraphImporterEditor : ScriptedImporterEditor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
if (GUILayout.Button("Open Shader Editor")) |
|||
{ |
|||
AssetImporter importer = target as AssetImporter; |
|||
Debug.Assert(importer != null, "importer != null"); |
|||
ShaderGraphImporterEditor.ShowGraphEditWindow(importer.assetPath); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue