浏览代码
[Improvements]Change workflow to work with new montreal importer work (scriptable importer)
/main
[Improvements]Change workflow to work with new montreal importer work (scriptable importer)
/main
Tim Cooper
8 年前
当前提交
1896e42f
共有 13 个文件被更改,包括 319 次插入 和 126 次删除
-
100MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
-
8MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
-
86MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarPresenter.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
67MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs
-
58MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers.meta
-
85MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs.meta
|
|||
Shader "Unlit/NewUnlitShader" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", 2D) = "white" {} |
|||
} |
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" } |
|||
LOD 100 |
|||
|
|||
Pass |
|||
{ |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
// make fog work |
|||
#pragma multi_compile_fog |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
UNITY_FOG_COORDS(1) |
|||
float4 vertex : SV_POSITION; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
float4 _MainTex_ST; |
|||
|
|||
v2f vert (appdata v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.uv = TRANSFORM_TEX(v.uv, _MainTex); |
|||
UNITY_TRANSFER_FOG(o,o.vertex); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
// sample the texture |
|||
fixed4 col = tex2D(_MainTex, i.uv); |
|||
// apply fog |
|||
UNITY_APPLY_FOG(i.fogCoord, col); |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9ab5e16c2083a4fe689209a8c1ae425e |
|||
timeCreated: 1495403711 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a1485bce8acd0428fae1525629b9ed8b |
|||
folderAsset: yes |
|||
timeCreated: 1495357309 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Experimental.AssetImporters; |
|||
using UnityEngine.MaterialGraph; |
|||
using UnityEngine; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using System.Reflection; |
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
using System.Text; |
|||
|
|||
[ScriptedImporter(1, "ShaderGraph")] |
|||
public class ShaderGraphImporter : ScriptedImporter |
|||
{ |
|||
public override void OnImportAsset(AssetImportContext ctx) |
|||
{ |
|||
var textGraph = File.ReadAllText(ctx.assetPath, Encoding.UTF8); |
|||
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph); |
|||
|
|||
if (graph == null) |
|||
return; |
|||
|
|||
var graphAsset = ScriptableObject.CreateInstance<MaterialGraphAsset> (); |
|||
graphAsset.materialGraph = graph; |
|||
ctx.SetMainAsset("MainAsset", graphAsset); |
|||
|
|||
var shader = RegenerateShader (graphAsset); |
|||
if (shader == null) |
|||
return; |
|||
|
|||
ctx.AddSubAsset("Shader", shader); |
|||
} |
|||
|
|||
public Shader RegenerateShader(MaterialGraphAsset asset) |
|||
{ |
|||
IMasterNode masterNode = asset.materialGraph.masterNode; |
|||
if (masterNode == null) |
|||
return null; |
|||
|
|||
var path = "Assets/UnityShaderEditor/Editor/HelperShader.shader"; |
|||
List<PropertyGenerator.TextureInfo> configuredTextures; |
|||
var shaderString = masterNode.GetFullShader(GenerationMode.ForReals, out configuredTextures); |
|||
|
|||
var shader = AssetDatabase.LoadAssetAtPath(path, typeof(Shader)) as Shader; |
|||
if (shader == null) |
|||
return null; |
|||
|
|||
ShaderUtil.UpdateShaderAsset (shader, shaderString); |
|||
|
|||
var shaderImporter = AssetImporter.GetAtPath(path) as ShaderImporter; |
|||
if (shaderImporter == null) |
|||
return null; |
|||
|
|||
var textureNames = new List<string>(); |
|||
var textures = new List<Texture>(); |
|||
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.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 == TexturePropertyChunk.ModifiableState.NonModifiable)) |
|||
{ |
|||
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(); |
|||
|
|||
var imported = shaderImporter.GetShader(); |
|||
return imported; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 625f186215c104763be7675aa2d941aa |
|||
timeCreated: 1495357324 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue