コード例 #1
0
        private void ConstructShaderList()
        {
            var serializedObject = new SerializedObject(this.variantCollection);
            var shaderProperties = serializedObject.FindProperty("m_Shaders");

            if (shaderProperties == null)
            {
                return;
            }
            for (int i = 0; i < shaderProperties.arraySize; ++i)
            {
                var            shaderProp   = shaderProperties.GetArrayElementAtIndex(i);
                Shader         shader       = shaderProp.FindPropertyRelative("first").objectReferenceValue as Shader;
                ShaderVariants variants     = new ShaderVariants();
                var            variantsProp = shaderProp.FindPropertyRelative("second.variants");

                for (int j = 0; j < variantsProp.arraySize; ++j)
                {
                    var variantProp = variantsProp.GetArrayElementAtIndex(j).FindPropertyRelative("keywords");
                    variants.keywordNames.Add(variantProp.stringValue);
                }
                shaderVariants.Add(shader, variants);
                shaders.Add(shader);
            }
        }
コード例 #2
0
        private void InitUI()
        {
            var mainFold = new Foldout();

            mainFold.text = variantCollection.name;

            ObjectField objectField = null;

#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
            objectField = new ObjectField("ShaderVaiantCollection");
#else
            objectField = new ObjectField();
#endif
            objectField.objectType = typeof(ShaderVariantCollection);
            objectField.value      = variantCollection;
            mainFold.Add(objectField);

            foreach (var shader in this.shaders)
            {
                var shaderFold = new Foldout();
                shaderFold.text = shader.name;
                shaderFold.style.paddingLeft = 10;


#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
                ObjectField shaderObject = new ObjectField("Shader");
#else
                ObjectField shaderObject = new ObjectField();
#endif
                shaderObject.objectType = typeof(Shader);
                shaderObject.value      = shader;
                shaderFold.Add(shaderObject);
                shaderFold.value = false;


                ShaderVariants variants = null;
                if (this.shaderVariants.TryGetValue(shader, out variants))
                {
                    Foldout keywordsFold = new Foldout();
                    keywordsFold.text = "keywords(" + variants.keywordNames.Count + ")";
#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
                    keywordsFold.style.left = 20;
#else
                    keywordsFold.style.positionLeft = 20;
#endif
                    keywordsFold.value = false;
                    foreach (var keyword in variants.keywordNames)
                    {
                        string str = keyword;
                        if (str == "")
                        {
                            str = "<none>";
                        }
                        var keywordLabel = new Label(str);
                        keywordsFold.Add(keywordLabel);
                    }
                    shaderFold.Add(keywordsFold);
                }
                mainFold.Add(shaderFold);
            }
            var dumpButton = new Button();
            dumpButton.text = "Dump To Json";
            dumpButton.clickable.clicked += () =>
            {
                this.DumpToJson();
                dumpButton.parent.Remove(dumpButton);
            };
            mainFold.Add(dumpButton);

            this.element = new VisualElement();
            this.element.Add(mainFold);
        }