浏览代码

[Material graph]hax to serialize texture reference :/

/main
Tim Cooper 9 年前
当前提交
51558db2
共有 1 个文件被更改,包括 38 次插入7 次删除
  1. 45
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs

45
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


using System;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

protected const string kUVSlotName = "UV";
[SerializeField]
private Texture2D m_DefaultTexture;
private string m_TextureGuid;
[SerializeField]
private TextureType m_TextureType;

#if UNITY_EDITOR
get { return m_DefaultTexture; }
set { m_DefaultTexture = value; }
get
{
if (string.IsNullOrEmpty(m_TextureGuid))
return null;
var path = AssetDatabase.GUIDToAssetPath(m_TextureGuid);
if (string.IsNullOrEmpty(path))
return null;
return AssetDatabase.LoadAssetAtPath<Texture2D>(path);
}
set
{
var assetPath = AssetDatabase.GetAssetPath(value);
if (string.IsNullOrEmpty(assetPath))
return;
m_TextureGuid = AssetDatabase.AssetPathToGUID(assetPath);
}
#else
public Texture2D defaultTexture
{
get
{
return Texture2D.whiteTexture;
}
set
{}
}
#endif
public TextureType textureType
{

// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(new TexturePropertyChunk(propertyName, description, m_DefaultTexture, m_TextureType, false, exposed));
visitor.AddShaderProperty(new TexturePropertyChunk(propertyName, description, defaultTexture, m_TextureType, false, exposed));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType slotValueType)

{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_Texture = m_DefaultTexture
m_Texture = defaultTexture
}
正在加载...
取消
保存