Material Texture#
Material / Material Texture
Can Read
Cannot Write
Description#
The Texture assigned to one of the texture properties of a Material
Parameters#
| Name | Description |
|---|---|
| Material | The Material the Texture is read from |
| Property | The name of the shader property. '_MainTex' by default |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Material Texture")]
[Category("Material/Material Texture")]
[Description("The Texture assigned to one of the texture properties of a Material")]
[Image(typeof(IconTexture), ColorTheme.Type.Blue, typeof(BadgeLink))]
[Parameter("Material", "The Material the Texture is read from")]
[Parameter("Property", "The name of the shader property. '_MainTex' by default")]
[Keywords("Shader", "Main", "Albedo", "Map", "Property", "Read")]
[Serializable]
public class TypeTextureMaterial : TypeTexture
{
private const string PROPERTY = "_MainTex";
[SerializeField] private GetMaterial m_Material = new GetMaterial();
[SerializeField] private GetString m_Property = new GetString(PROPERTY);
public override Texture Get(Args args)
{
Material material = this.m_Material.Get(args);
if (material == null) return null;
string property = this.m_Property.Get(args);
if (string.IsNullOrEmpty(property)) property = PROPERTY;
return material.HasProperty(property) ? material.GetTexture(property) : null;
}
public override string ToString()
{
return $"{this.m_Material} Texture";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}