当前位置: 首页>>代码示例>>C#>>正文


C# MaterialPropertyBlock.GetTexture方法代码示例

本文整理汇总了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
		}
	}
开发者ID:MJ-meo-dmt,项目名称:UnitySpritesAndBones,代码行数:26,代码来源:SortLayerMaterialEditor.cs

示例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);
    }
开发者ID:ChubbRck,项目名称:SFB,代码行数:29,代码来源:TiledSpriteRenderer.cs


注:本文中的UnityEngine.MaterialPropertyBlock.GetTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。