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


C# Material.GetColorNames方法代码示例

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


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

示例1: DumpShaderMaterial

        private BabylonMaterial DumpShaderMaterial(Material material)
        {
            if (materialsDictionary.ContainsKey(material.name))
            {
                return materialsDictionary[material.name];
            }

            var babylonShaderMaterial = new BabylonShaderMaterial
            {
                name = material.name,
                id = Guid.NewGuid().ToString(),
            };

            ExporterWindow.ReportProgress(1, "Exporting glsl material: " + material.name);

            List<string> tnames = material.GetTextureNames();
            foreach (string tname in tnames)
            {
                BabylonTexture tdata = DumpTextureFromMaterial(material, tname);
                if (tdata != null)
                {
                    babylonShaderMaterial.textures.Add(tname, tdata);
                }
            }

            List<string> fnames = material.GetFloatNames();
            foreach (string fname in fnames)
            {
                float fdata = material.GetFloat(fname);
                babylonShaderMaterial.floats.Add(fname, fdata);
            }

            List<string> rnames = material.GetRangeNames();
            foreach (string rname in rnames)
            {
                float rdata = material.GetFloat(rname);
                babylonShaderMaterial.floats.Add(rname, rdata);
            }

            List<string> cnames = material.GetColorNames();
            foreach (string cname in cnames)
            {
                Color cdata = material.GetColor(cname);
                babylonShaderMaterial.vectors4.Add(cname, cdata.ToFloat());
            }

            List<string> vnames = material.GetVectorNames();
            foreach (string vname in vnames)
            {
                Vector4 vdata = material.GetVector(vname);
                babylonShaderMaterial.vectors4.Add(vname, vdata.ToFloat());
            }

            Shader shader = material.shader;
            string filename = AssetDatabase.GetAssetPath(shader);
            string program = Tools.LoadTextAsset(filename);
            string basename = shader.name.Replace("BabylonJS/", "").Replace("/", "_").Replace(" ", "");
            string outpath = (!String.IsNullOrEmpty(exportationOptions.DefaultShaderFolder)) ? exportationOptions.DefaultShaderFolder : OutputPath;

            var shaderpath = new Dictionary<string, string>();
            List<string> attributeList = new List<string>();
            List<string> uniformList = new List<string>();
            List<string> samplerList = new List<string>();
            List<string> defineList = new List<string>();
            string babylonOptions = GetShaderProgramSection(basename, program, BabylonProgramSection.Babylon);
            string[] babylonLines = babylonOptions.Split('\n');
            foreach (string babylonLine in babylonLines)
            {
                if (babylonLine.IndexOf("attributes", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    string[] attributes = babylonLine.Split(':');
                    if (attributes != null && attributes.Length > 1)
                    {
                        string abuffer = attributes[1].Replace("[", "").Replace("]", "");
                        if (!String.IsNullOrEmpty(abuffer))
                        {
                            abuffer = abuffer.Trim();
                            string[] adata = abuffer.Split(',');
                            if (adata != null && adata.Length > 0)
                            {
                                foreach (string aoption in adata)
                                {
                                    string aoption_buffer = aoption.Trim().Replace("\"", "").Trim();
                                    if (!String.IsNullOrEmpty(aoption_buffer))
                                    {
                                        attributeList.Add(aoption_buffer);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (babylonLine.IndexOf("uniforms", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    string[] uniforms = babylonLine.Split(':');
                    if (uniforms != null && uniforms.Length > 1)
                    {
                        string ubuffer = uniforms[1].Replace("[", "").Replace("]", "");
                        if (!String.IsNullOrEmpty(ubuffer))
                        {
//.........这里部分代码省略.........
开发者ID:Temechon,项目名称:Babylon.js,代码行数:101,代码来源:SceneBuilder.Materials.cs

示例2: DumpStandardMaterial

        private BabylonMaterial DumpStandardMaterial(Material material, int lightmapIndex = -1, Vector4 lightmapScaleOffset = default(Vector4), int lightmapCoordIndex = -1)
        {
            var materialNotSupported = false;
            if (!materialsDictionary.ContainsKey(material.name))
            {
                var bMat = new BabylonStandardMaterial
                {
                    name = material.name,
                    id = Guid.NewGuid().ToString(),
                    diffuse = new float[4],
                    specular = new float[4]
                };

                ExporterWindow.ReportProgress(1, "Exporting standard material: " + material.name);
                if (exportationOptions.DefaultLightmapMode == (int)BabylonLightmapMode.FullLightBaking)
                {
                    bMat.disableLighting = true;
                    bMat.useEmissiveAsIllumination = true;
                }

                // Default diffuse
                bMat.diffuse[0] = 1.0f;
                bMat.diffuse[1] = 1.0f;
                bMat.diffuse[2] = 1.0f;
                bMat.diffuse[3] = 1.0f;

                // Default specular
                bMat.specular[0] = 0.0f;
                bMat.specular[1] = 0.0f;
                bMat.specular[2] = 0.0f;
                bMat.specular[3] = 1.0f;

                if (material.mainTexture && material.mainTexture.GetType().FullName == "UnityEngine.ProceduralTexture")
                {
                    materialNotSupported = true;
                    Debug.LogWarning("ProceduralTexture: " + material.mainTexture.name + " not supported by Babylon.js");
                }

                if (material.HasProperty("_Shininess"))
                {
                    var specShininess = material.GetFloat("_Shininess");
                    bMat.specularPower = specShininess * 128;
                }
                if (material.HasProperty("_Color"))
                {
                    bMat.diffuse = material.color.ToFloat();
                }
                if (material.HasProperty("_SpecColor"))
                {
                    var specColor = material.GetColor("_SpecColor");
                    bMat.specular = specColor.ToFloat();
                }
                if (material.HasProperty("_Emission"))
                {
                    if (material.GetColorNames().IndexOf("_Emission") >= 0)
                    {
                        var emissiveColor = material.GetColor("_Emission");
                        bMat.emissive = emissiveColor.ToFloat();
                    }
                    else if (material.GetFloatNames().IndexOf("_Emission") >= 0)
                    {
                        // TODO: Convert Lightmapper Emission Color
                        UnityEngine.Debug.LogWarning("Material Emission Is Float Not Color: " + material.name);
                    }
                }
                if (material.mainTexture && !materialNotSupported)
                {
                    var mainTexture2D = material.mainTexture as Texture2D;
                    var mainTexturePath = AssetDatabase.GetAssetPath(mainTexture2D);
                    var alphaCuttOff = 0f;
                    if (material.HasProperty("_Cutoff"))
                    {
                        alphaCuttOff = material.GetFloat("_Cutoff");
                    }
                    bMat.diffuseTexture = new BabylonTexture
                    {
                        uScale = material.mainTextureScale.x,
                        vScale = material.mainTextureScale.y,
                        uOffset = material.mainTextureOffset.x,
                        vOffset = material.mainTextureOffset.y
                    };
                    CopyTexture(mainTexturePath, mainTexture2D, bMat.diffuseTexture);
                    if ((mainTexture2D && mainTexture2D.alphaIsTransparency) || alphaCuttOff > 0)
                    {
                        bMat.diffuseTexture.hasAlpha = true;
                        bMat.backFaceCulling = false;
                    }
                }

                // Normal map
                bMat.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
                if (bMat.bumpTexture != null && material.HasProperty("_BumpScale"))
                {
                    bMat.bumpTexture.level = material.GetFloat("_BumpScale");
                }

                bMat.emissiveTexture = DumpTextureFromMaterial(material, "_Illum");
                bMat.ambientTexture = DumpTextureFromMaterial(material, "_LightMap");
                bMat.reflectionTexture = DumpTextureFromMaterial(material, "_Cube");

//.........这里部分代码省略.........
开发者ID:Temechon,项目名称:Babylon.js,代码行数:101,代码来源:SceneBuilder.Materials.cs


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