本文整理汇总了C#中UnityEngine.MaterialPropertyBlock.GetTexture方法的典型用法代码示例。如果您正苦于以下问题:C# MaterialPropertyBlock.GetTexture方法的具体用法?C# MaterialPropertyBlock.GetTexture怎么用?C# MaterialPropertyBlock.GetTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.MaterialPropertyBlock
的用法示例。
在下文中一共展示了MaterialPropertyBlock.GetTexture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMaterial
static void CreateMaterial (GameObject go) {
// Create a simple material asset
if (go.GetComponent<Renderer>() != null)
{
Material material = new Material(go.GetComponent<Renderer>().sharedMaterial);
material.CopyPropertiesFromMaterial(go.GetComponent<Renderer>().sharedMaterial);
go.GetComponent<Renderer>().sharedMaterial = material;
MaterialPropertyBlock block = new MaterialPropertyBlock();
go.GetComponent<Renderer>().GetPropertyBlock(block);
#if UNITY_EDITOR
if(!Directory.Exists("Assets/Materials")) {
AssetDatabase.CreateFolder("Assets", "Materials");
AssetDatabase.Refresh();
}
string textureName = null;
if (block.GetTexture(0).name != null) {
textureName = block.GetTexture(0).name;
} else {
textureName = material.mainTexture.name;
}
AssetDatabase.CreateAsset(material, "Assets/Materials/" + textureName + ".mat");
Debug.Log("Created material " + textureName + " for " + go.name);
#endif
}
}
示例2: UpdateMaterial
void UpdateMaterial()
{
if (! initialised) {
// Parameters changed before Awake() has been run, do a full update when appropriate.
// (Can't rely on Awake() when the GameObject is disabled. It does a lousy job as a constructor.)
regenerateMesh = true;
return;
}
if ((renderer.sharedMaterials.Length != 1) || (renderer.sharedMaterials[0] != m_material)) {
// Update only when necessary to prevent false scene changes.
renderer.sharedMaterials = new Material[] {m_material};
}
MaterialPropertyBlock materialProperties = new MaterialPropertyBlock();
renderer.GetPropertyBlock(materialProperties);
if ((m_sprite != null) && (m_sprite.texture != null)) {
materialProperties.SetTexture("_MainTex", m_sprite.texture);
}
else if (m_material != null) {
if (materialProperties.GetTexture("_MainTex") != null) {
materialProperties.Clear();
}
m_material.SetTexture("_MainTex", null);
}
renderer.SetPropertyBlock(materialProperties);
}