private void OnGUI()
    {
        GUILayout.Space(20);
        tagStr = EditorGUILayout.TagField("Select tag:", tagStr);


        if (tagStr != "")
        {
            GUILayout.Space(20);
            selectedMaterial = EditorGUILayout.ObjectField("Select material:", selectedMaterial, typeof(Material), false) as Material;
        }

        var material = new MaterialOptions(tagStr);

        if (selectedMaterial != null)
        {
            GUILayout.Space(20);
            if (GUILayout.Button("Apply Material"))
            {
                material.ApplyMaterial(selectedMaterial);
            }
        }
    }
Beispiel #2
0
        public Material(string vertexShaderMethod, string fragmentShaderMethod, RenderQueue renderQueue, MaterialOptions options = 0)
        {
            this.MaterialType     = MaterialType.Custom;
            this.RenderQueue      = renderQueue;
            this.ShadingTechnique = Graphics.GetCurrent(true).CurrentShadingTechnique;

            OpenGLShader shader;

            this._shader = shader = new OpenGLShader();
            shader.Code  = GetDefaultShaderCode();

            if (options.HasFlag(MaterialOptions.NoLighting) == false)
            {
                shader.Flags |= ShaderDefines.USE_LIGHTING;
            }

            if (string.IsNullOrWhiteSpace(vertexShaderMethod) == false)
            {
                shader.Flags |= ShaderDefines.CUSTOM_VERTEX;
                shader.Code  += string.Format("\n#if defined VERTEX_SHADER\n{0}\n#endif\n", vertexShaderMethod);
            }
            shader.Code += string.Format("\n#if defined FRAGMENT_SHADER\n{0}\n#endif\n", fragmentShaderMethod);
            InitShader();
        }
        public static void SetTexturedMaterial(MeshRenderer meshRenderer, String texturePath, Shader shader, MaterialOptions options)
        {
            // Load texture:
            var texture = LoadTexture(texturePath);

            SetTexturedMaterial(meshRenderer, texture, shader, options);
        }
        public static void SetTexturedMaterial(MeshRenderer meshRenderer, Texture texture, Shader shader, MaterialOptions options)
        {
            // Set textured material:
            var materials = meshRenderer.materials;

            var material = CreateTexturedMaterial(texture, shader);

            if (((uint)options & (uint)MaterialOptions.InvertX) != 0)
            {
                material.mainTextureScale = new Vector2(-1.0f, 1.0f);
            }

            materials[0]           = material;
            meshRenderer.materials = materials;
        }