Пример #1
0
        protected virtual void FindProperties(MaterialProperty[] props)
        {
            baseColorMp          = null;
            shaderPropertyGroups = new List <ShaderGroupInstance>();
            hasDepency.Clear();
            for (int i = 0; i < AssetsConfig.GlobalAssetsConfig.ShaderGroupInfo.Count; ++i)
            {
                string groupName = AssetsConfig.GlobalAssetsConfig.ShaderGroupInfo[i];
                shaderPropertyGroups.Add(new ShaderGroupInstance()
                {
                    name = groupName
                });
            }

            Shader shader           = m_Material.shader;
            var    shaderFeatureMap = AssetsConfig.GetShaderFeatureList();

            for (int i = 0; i < AssetsConfig.GlobalAssetsConfig.ShaderInfos.Count; ++i)
            {
                var si = AssetsConfig.GlobalAssetsConfig.ShaderInfos[i];
                if (si.shader != null && si.shader.name == shader.name)
                {
                    for (int j = 0; j < si.shaderFeatures.Count; ++j)
                    {
                        string featurename = si.shaderFeatures[j];
                        AssetsConfig.ShaderFeature sf;
                        if (shaderFeatureMap.TryGetValue(featurename, out sf))
                        {
                            MaterialProperty mp = null;
                            if (!string.IsNullOrEmpty(sf.propertyName))
                            {
                                mp = FindProperty(sf.propertyName, props, false);
                            }
                            if (sf.type == AssetsConfig.ShaderPropertyType.CustomGroup)
                            {
                                for (int k = 0; k < sf.customProperty.Length; ++k)
                                {
                                    var cp = sf.customProperty[k];
                                    if (cp.valid && !string.IsNullOrEmpty(cp.desc))
                                    {
                                        ShaderGroupInstance sgi = null;
                                        if (string.IsNullOrEmpty(cp.subGroup))
                                        {
                                            sgi = shaderPropertyGroups[shaderPropertyGroups.Count - 1];
                                        }
                                        else
                                        {
                                            sgi = shaderPropertyGroups.Find((param) => { return(param.name == cp.subGroup); });
                                        }

                                        if (sgi == null)
                                        {
                                            sgi = new ShaderGroupInstance()
                                            {
                                                name = cp.subGroup
                                            };
                                            sgi.hasCustomGroup = true;
                                            shaderPropertyGroups.Add(sgi);
                                        }
                                        ShaderPropertyInstance spi = new ShaderPropertyInstance();
                                        spi.shaderFeature = sf;
                                        spi.property      = mp;
                                        spi.scp           = cp;
                                        spi.customIndex   = k;
                                        sgi.spiList.Add(spi);
                                    }
                                }
                            }
                            else
                            {
                                ShaderPropertyInstance spi = new ShaderPropertyInstance();
                                spi.shaderFeature = sf;
                                spi.property      = mp;
                                ShaderGroupInstance sgi = shaderPropertyGroups.Find((param) => { return(param.name == sf.shaderGroupName); });
                                if (sgi == null)
                                {
                                    sgi = shaderPropertyGroups[shaderPropertyGroups.Count - 1];
                                }
                                sgi.spiList.Add(spi);
                                if (sf.name == "Color")
                                {
                                    baseColorMp = spi.property;
                                }
                            }

                            if (sf.type == AssetsConfig.ShaderPropertyType.Keyword &&
                                !hasDepency.Contains(sf.name) &&
                                m_Material.IsKeywordEnabled(sf.propertyName))
                            {
                                hasDepency.Add(sf.name);
                            }
                        }
                    }
                    break;
                }
            }
            customFunc.Clear();
            customFunc.Add("BlendMode", BlendModePopup);
            customFunc.Add("Debug", DoDebugArea);
            AssetsConfig.RefreshShaderDebugNames();
            GameObject go = Selection.activeGameObject;

            if (go != null)
            {
                dd = go.GetComponent <DebugData>();
            }
            Update();
        }
Пример #2
0
 private void Update()
 {
     if (shaderPropertyGroups != null)
     {
         drawList.Clear();
         for (int i = 0; i < shaderPropertyGroups.Count; ++i)
         {
             ShaderGroupInstance sgi = shaderPropertyGroups[i];
             if (sgi.hasCustomGroup)
             {
                 sgi.spiList.Sort((x, y) =>
                 {
                     int idx = x.scp != null ? x.scp.indexInGroup : 0;
                     int idy = y.scp != null ? y.scp.indexInGroup : 0;
                     return(idx - idy);
                 });
             }
             bool hasBeginFun = false;
             for (int j = 0; j < sgi.spiList.Count; ++j)
             {
                 ShaderPropertyInstance spi = sgi.spiList[j];
                 var sf = spi.shaderFeature;
                 if (j == 0 && (sf.indexInGroup >= 0 || sf.type == AssetsConfig.ShaderPropertyType.CustomGroup))
                 {
                     DrawPropertyContext context = new DrawPropertyContext();
                     context.fun = drawGroupBegin;
                     context.sgi = sgi;
                     drawList.Add(context);
                     hasBeginFun = true;
                 }
                 if (sf.type == AssetsConfig.ShaderPropertyType.CustomFun)
                 {
                     DrawFun fun = null;
                     if (customFunc.TryGetValue(sf.name, out fun))
                     {
                         DrawPropertyContext context = new DrawPropertyContext();
                         context.fun            = fun;
                         context.material       = m_Material;
                         context.materialEditor = m_MaterialEditor;
                         context.hasDepency     = hasDepency;
                         context.spi            = spi;
                         context.dd             = dd;
                         drawList.Add(context);
                     }
                 }
                 else
                 {
                     bool show = true;
                     if (sf.dependencyPropertys != null && sf.dependencyPropertys.dependencyShaderProperty.Count > 0)
                     {
                         bool hasFeature = false;
                         for (int k = 0; k < sf.dependencyPropertys.dependencyShaderProperty.Count; ++k)
                         {
                             string featureName = sf.dependencyPropertys.dependencyShaderProperty[k];
                             if (sf.dependencyPropertys.dependencyType == AssetsConfig.DependencyType.Or)
                             {
                                 hasFeature |= hasDepency.Contains(featureName);
                                 if (hasFeature)
                                 {
                                     break;
                                 }
                             }
                             else if (sf.dependencyPropertys.dependencyType == AssetsConfig.DependencyType.And)
                             {
                                 hasFeature &= hasDepency.Contains(featureName);
                                 if (!hasFeature)
                                 {
                                     break;
                                 }
                             }
                         }
                         if (sf.dependencyPropertys.isNor)
                         {
                             hasFeature = !hasFeature;
                         }
                         show = hasFeature;
                     }
                     if (show && !sf.hide)
                     {
                         var drawFun = drawPropertyFun[(int)sf.type];
                         if (drawFun != null)
                         {
                             DrawPropertyContext context = new DrawPropertyContext();
                             context.fun            = drawFun;
                             context.material       = m_Material;
                             context.materialEditor = m_MaterialEditor;
                             context.hasDepency     = hasDepency;
                             context.spi            = spi;
                             context.dd             = dd;
                             context.sgi            = sgi;
                             drawList.Add(context);
                         }
                     }
                     if (j == sgi.spiList.Count - 1 && hasBeginFun)
                     {
                         DrawPropertyContext context = new DrawPropertyContext();
                         context.fun = drawGroupEnd;
                         context.sgi = sgi;
                         drawList.Add(context);
                     }
                 }
             }
         }
     }
 }