关于Unity Shader编写程序纹理报错error CS0246: The type or namespace name ‘SetProperty‘ could not be found 问题

在阅读《unity shader入门精要》这本书学习程序纹理一章时,在实验书中示例代码时,报错error CS0246: The type or namespace name 'SetProperty' could not be found问题,问题代码段如下:

#region Material properties
	[SerializeField, SetProperty("textureWidth")]
	private int m_textureWidth = 512;
	public int textureWidth
	{
		get
		{
			return m_textureWidth;
		}
		set
		{
			m_textureWidth = value;
			_UpdateMaterial();
		}
	}

	[SerializeField, SetProperty("backgroundColor")]
	private Color m_backgroundColor = Color.white;
	public Color backgroundColor
	{
		get
		{
			return m_backgroundColor;
		}
		set
		{
			m_backgroundColor = value;
			_UpdateMaterial();
		}
	}

	[SerializeField, SetProperty("circleColor")]
	private Color m_circleColor = Color.yellow;
	public Color circleColor
	{
		get
		{
			return m_circleColor;
		}
		set
		{
			m_circleColor = value;
			_UpdateMaterial();
		}
	}

	[SerializeField, SetProperty("blurFactor")]
	private float m_blurFactor = 2.0f;
	public float blurFactor
	{
		get
		{
			return m_blurFactor;
		}
		set
		{
			m_blurFactor = value;
			_UpdateMaterial();
		}
	}
	#endregion

主要问题是该处使用了一个开源插件:SetProperty,该插件用于在Unity面板上修改材质属性,并通过_UpdateMaterial()函数来使用新的属性生成程序纹理。

该插件GitHub网址:https://github.com/LMNRY/SetProperty

从该开源网址下载该插件后

将解压缩后的文件全部拖到Unity项目文件下一个新建文件夹里

就能解决该问题。

猜你喜欢

转载自blog.csdn.net/a1601611709/article/details/113099701