|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
} |