예제 #1
0
 private void OnSelectionChange()
 {
     string[] selectedAssets = Selection.assetGUIDs;
     if (selectedAssets.Length == 1)
     {
         Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(selectedAssets[0]));
         if (obj.GetType() == typeof(Shader))
         {
             Shader   shader = (Shader)obj;
             Material m      = new Material(shader);
             if (m.HasProperty(Shader.PropertyToID("shader_eable_poi_settings_selection")))
             {
                 MaterialProperty[] props = MaterialEditor.GetMaterialProperties(new Material[] { m });
                 activeShader  = shader;
                 presetHandler = new PoiPresetHandler(props);
             }
         }
     }
     this.Repaint();
 }
예제 #2
0
    void OnGUI()
    {
        scrollPos = GUILayout.BeginScrollView(scrollPos);
        GUILayout.Label("Config", EditorStyles.boldLabel);
        config = PoiHelper.GetConfig();

        if (GUILayout.Toggle(config.bigTextures, "Big Texture Fields") != config.bigTextures)
        {
            config.bigTextures = !config.bigTextures;
            config.save();
            PoiHelper.RepaintAllMaterialEditors();
        }

        if (GUILayout.Toggle(config.useRenderQueueSelection, "Use Render Queue Selection") != config.useRenderQueueSelection)
        {
            config.useRenderQueueSelection = !config.useRenderQueueSelection;
            config.save();
            PoiHelper.RepaintAllMaterialEditors();
        }

        drawLine();


        if (poiShaders == null || reload)
        {
            string[]      shaderGuids = AssetDatabase.FindAssets("t:shader");
            List <string> poiShaders  = new List <string>();
            foreach (string g in shaderGuids)
            {
                Shader   shader = AssetDatabase.LoadAssetAtPath <Shader>(AssetDatabase.GUIDToAssetPath(g));
                Material m      = new Material(shader);
                if (m.HasProperty(Shader.PropertyToID("shader_eable_poi_settings_selection")))
                {
                    string defaultShaderName = PoiHelper.getDefaultShaderName(shader.name);
                    if (!poiShaders.Contains(defaultShaderName))
                    {
                        poiShaders.Add(defaultShaderName);
                    }
                }
            }
            this.poiShaders = new string[poiShaders.Count + 1];
            for (int i = 0; i < poiShaders.Count; i++)
            {
                this.poiShaders[i + 1] = poiShaders[i];
            }
        }

        if (GUILayout.Button("Backup Poi Materials", GUILayout.MaxWidth(150)))
        {
            PoiHelper.saveAllPoiMaterials();
        }
        if (GUILayout.Button("Restore Poi Materials", GUILayout.MaxWidth(150)))
        {
            PoiHelper.restorePoiMaterials();
        }
        drawLine();

        if (activeShader != null)
        {
            poiShaders[0] = PoiHelper.getDefaultShaderName(activeShader.name);
        }
        else
        {
            poiShaders[0] = "None";
        }
        int newSelectShader = EditorGUILayout.Popup(0, poiShaders, GUILayout.MaxWidth(200));

        if (newSelectShader != selectedShader)
        {
            selectedShader = newSelectShader;
            activeShader   = Shader.Find(poiShaders[newSelectShader]);
            presetHandler  = new PoiPresetHandler(activeShader);
        }

        if (reload)
        {
            presetHandler = new PoiPresetHandler(activeShader);
        }

        if (activeShader != null)
        {
            string defaultShaderName = PoiHelper.getDefaultShaderName(activeShader.name);;
            Shader defaultShader     = Shader.Find(defaultShaderName);

            GUIStyle style = new GUIStyle(GUI.skin.label);
            style.richText = true;
            EditorGUILayout.LabelField("<size=16>" + defaultShaderName + "</size>", style, GUILayout.MinHeight(18));

            GUILayout.Label("Generate Render Queue Shaders", EditorStyles.boldLabel);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Generate All Queues", GUILayout.MaxWidth(200)))
            {
                for (int i = createShadersFrom; i <= createShadersTo; i++)
                {
                    PoiHelper.createRenderQueueShaderIfNotExists(defaultShader, i, false);
                }
                AssetDatabase.Refresh();
            }
            GUILayout.Label("from", GUILayout.MaxWidth(30));
            createShadersFrom = EditorGUILayout.IntField(createShadersFrom, GUILayout.MaxWidth(50));
            GUILayout.Label("to", GUILayout.MaxWidth(15));
            createShadersTo = EditorGUILayout.IntField(createShadersTo, GUILayout.MaxWidth(50));
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Generate most common Queues", GUILayout.MaxWidth(200)))
            {
                foreach (int i in COMMON_QUEUES)
                {
                    PoiHelper.createRenderQueueShaderIfNotExists(defaultShader, i, false);
                }
                AssetDatabase.Refresh();
            }
            if (presetHandler != null)
            {
                presetHandler.drawPresetsSettings();
            }
        }
        GUILayout.EndScrollView();
        reload = false;
        if (GUILayout.Button("ReLoad"))
        {
            reload = true;
        }
    }
예제 #3
0
    //-------------Main Function--------------
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
    {
        PoiHelper.updateQueueShadersIfNessecary();
        Object[]   targets   = materialEditor.targets;
        Material[] materials = new Material[targets.Length];
        for (int i = 0; i < targets.Length; i++)
        {
            materials[i] = targets[i] as Material;
        }

        config = PoiHelper.GetConfig();
        if (presetHandler == null)
        {
            presetHandler = new PoiPresetHandler(props);
        }
        else
        {
            presetHandler.testPresetsChanged(props);
        }

        SetupStyle();

        CollectAllProperties(props, materialEditor);

        // load default toggle values
        LoadDefaults(materials[0]);

        //shader name + presets
        EditorGUILayout.BeginHorizontal();
        byte[]    fileData = File.ReadAllBytes(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("poiSettigsIcon")[0]));
        Texture2D tex      = new Texture2D(2, 2);

        tex.LoadImage(fileData);
        if (GUILayout.Button(tex, new GUILayoutOption[] { GUILayout.MaxWidth(24), GUILayout.MaxHeight(18) }))
        {
            sendActiveShader = true;
            PoiSettings window = PoiSettings.getInstance();
            window.Show();
            window.Focus();
        }
        MaterialProperty shader_master_label = FindProperty(props, "shader_master_label");

        if (shader_master_label != null)
        {
            DrawMasterLabel(shader_master_label.displayName);
        }
        presetHandler.drawPresets(props, materials);
        EditorGUILayout.EndHorizontal();

        //shader properties
        foreach (ShaderPart part in shaderparts.parts)
        {
            drawShaderPart(part, materialEditor);
        }

        Shader shader            = materials[0].shader;
        string defaultShaderName = materials[0].shader.name.Split(new string[] { "-queue" }, System.StringSplitOptions.None)[0].Replace(".differentQueues/", "");
        Shader defaultShader     = Shader.Find(defaultShaderName);

        //Render Queue
        if (config.useRenderQueueSelection)
        {
            drawRenderQueueSelector(materials[0], defaultShader);
            EditorGUILayout.LabelField("Default: " + defaultShaderName);
            EditorGUILayout.LabelField("Shader: " + shader.name);
        }

        ToggleDefines(materials[0]);

        //big/small texture toggle

        /*if (textureFieldsCount > 0) {
         *  if(EditorGUILayout.Toggle("Big Texture Fields", config.bigTextures) != config.bigTextures)
         *  {
         *      config.bigTextures = !config.bigTextures;
         *      config.save();
         *  }
         * }*/

        //footer
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Space(2);
        foreach (string footNote in footer)
        {
            string[] splitNote = footNote.TrimEnd(')').Split("(".ToCharArray(), 2);
            string   value     = splitNote[1];
            string   type      = splitNote[0];
            if (type == "linkButton")
            {
                string[] values = value.Split(",".ToCharArray());
                drawLinkButton(70, 20, values[0], values[1]);
            }
            GUILayout.Space(2);
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (!config.useRenderQueueSelection)
        {
            materials[0].renderQueue = defaultShader.renderQueue;
        }
        UpdateRenderQueue(materials[0], defaultShader);
        if (sendActiveShader)
        {
            PoiSettings.activeShader  = defaultShader;
            PoiSettings.presetHandler = presetHandler;
            EditorWindow win = PoiHelper.FindEditorWindow(typeof(PoiSettings));
            if (win != null)
            {
                win.Repaint();
            }
            sendActiveShader = false;
        }
    }