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


C# Material.GetInstanceID方法代码示例

本文整理汇总了C#中Material.GetInstanceID方法的典型用法代码示例。如果您正苦于以下问题:C# Material.GetInstanceID方法的具体用法?C# Material.GetInstanceID怎么用?C# Material.GetInstanceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Material的用法示例。


在下文中一共展示了Material.GetInstanceID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMaterialNew

    string GenerateMaterialNew(ref System.Text.StringBuilder sbR,ref Material m)
    {
        string matName = m.name;
        if(matNameFromTextureName && m.HasProperty ("_MainTex")){
            Texture2D mT = m.GetTexture ("_MainTex") as Texture2D;
            if(mT != null){
                matName = m.GetTexture ("_MainTex").name;
            }else{
                Debug.Log ("Could not generate material from texture name (" + matName + "). No texture assigned");
            }
        }
        bool instance = matName.Contains ("Instance");
        if(instance && materialInstancePercautions) {

            matName += "_(" + m.GetInstanceID () + ")";
        }

        if(matNameCache.Contains (matName) == false){
            matNameCache.Add (matName);
        sbR.AppendLine ("newmtl " + matName);

            bool hasColor = m.HasProperty ("_Color");
            if(hasColor){
        Color matColor = m.color;
        sbR.AppendLine ("Kd " + matColor.r + " " + matColor.g + " " + matColor.b);
                float alpha = Mathf.Lerp (1,0,matColor.a);

                sbR.AppendLine ("d " + alpha);
            }

        bool hasSpecular = m.HasProperty ("_SpecColor");
        if (hasSpecular) {
            Color specColor = m.GetColor ("_SpecColor");
            sbR.AppendLine ("Ks " + specColor.r + " " + specColor.g + " " + specColor.b);
        }
        bool hasTexture = m.HasProperty ("_MainTex");
        if (hasTexture) {
                Texture2D mainTex = m.GetTexture ("_MainTex") as Texture2D;

                if(mainTex != null){
                    Vector2 mainTexScale = m.GetTextureScale ("_MainTex");
                    if(mainTex.wrapMode == TextureWrapMode.Clamp){
                        sbR.AppendLine("-clamp on");
                    }
                    sbR.AppendLine ("s " + mainTexScale.x + " " + mainTexScale.y);

                sbR.AppendLine ("map_Kd " + mainTex.name + ".png");

                    try{

                        if(exportTextures  ){
                            Texture2D nT = new Texture2D(mainTex.width,mainTex.height,TextureFormat.ARGB32,false);
                            Color[] pxls = mainTex.GetPixels ();
                            nT.SetPixels (pxls);

                            byte[] pngEx = nT.EncodeToPNG ();

                            if(System.IO.File.Exists (exportFolder + "/" + mainTex.name + ".png") == false){
                                System.IO.File.WriteAllBytes (exportFolder + "/" + mainTex.name + ".png",pngEx);
                            }

                        }
                    }catch(System.Exception ex){

                    }
                }

        }
        sbR.AppendLine ();
        }
        return matName;
    }
开发者ID:mroslander,项目名称:BoomBalls,代码行数:72,代码来源:UnityOBJExporter.cs

示例2: GetMaterialAssetName

 private string GetMaterialAssetName(Material material, MeshRenderer meshRenderer)
 {
     return GetMaterialName(material, meshRenderer) + "_" + material.GetInstanceID().ToString("X8");
 }
开发者ID:cbalderrama,项目名称:wire3d,代码行数:4,代码来源:Unity3DExporter.cs


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