예제 #1
0
        protected virtual void CreateNewShader(VisualElement shaderCreationUI, ObjectField shaderField)
        {
            // TODO: create a popupwindow instead of a context menu
            var menu = new GenericMenu();
            var dim  = (OutputDimension)shaderNode.settings.GetResolvedTextureDimension(owner.graph);

#if MIXTURE_SHADERGRAPH
            GUIContent shaderGraphContent = EditorGUIUtility.TrTextContentWithIcon("Graph", Resources.Load <Texture2D>("sg_graph_icon@64"));
            menu.AddItem(shaderGraphContent, false, () => SetShader(MixtureEditorUtils.CreateNewShaderGraph(owner.graph, title, dim), shaderCreationUI, shaderField));
#endif
            GUIContent shaderTextContent = EditorGUIUtility.TrTextContentWithIcon("Text", "Shader Icon");
            menu.AddItem(shaderTextContent, false, () => SetShader(MixtureEditorUtils.CreateNewShaderText(owner.graph, title, dim), shaderCreationUI, shaderField));
            menu.ShowAsContext();
        }
예제 #2
0
        void UpdateShaderCreationUI()
        {
            shaderCreationUI.Clear();

            if (shaderNode.shader == null)
            {
                shaderCreationUI.Add(new Button(CreateNewShader)
                {
                    text = "New Shader"
                });
            }
            else
            {
                shaderCreationUI.Add(new Button(OpenCurrentShader)
                {
                    text = "Open"
                });
            }

            void CreateNewShader()
            {
                // TODO: create a popupwindow instead of a context menu
                var menu = new GenericMenu();
                var dim  = (OutputDimension)shaderNode.rtSettings.GetTextureDimension(owner.graph);

#if MIXTURE_SHADERGRAPH
                GUIContent shaderGraphContent = EditorGUIUtility.TrTextContentWithIcon("Graph", Resources.Load <Texture2D>("sg_graph_icon@64"));
                menu.AddItem(shaderGraphContent, false, () => SetShader(MixtureEditorUtils.CreateNewShaderGraph(title, dim)));
#endif
                GUIContent shaderTextContent = EditorGUIUtility.TrTextContentWithIcon("Text", "Shader Icon");
                menu.AddItem(shaderTextContent, false, () => SetShader(MixtureEditorUtils.CreateNewShaderText(title, dim)));
                menu.ShowAsContext();
            }

            void OpenCurrentShader()
            {
                AssetDatabase.OpenAsset(shaderNode.shader);
            }
        }