Exemple #1
0
    // this is the same as the ShaderProperty function, show here so
    // you can see how it works

    /*
     *  private void ShaderPropertyImpl(Shader shader, int propertyIndex)
     *  {
     *          int i = propertyIndex;
     *          string label = ShaderUtil.GetPropertyDescription(shader, i);
     *          string propertyName = ShaderUtil.GetPropertyName(shader, i);
     *
     *
     *
     *
     *          switch (ShaderUtil.GetPropertyType(shader, i))
     *          {
     *                  case ShaderUtil.ShaderPropertyType.Range: // float ranges
     *                  {
     *                          GUILayout.BeginHorizontal();
     *                          float v2 = ShaderUtil.GetRangeLimits(shader, i, 1);
     *                          float v3 = ShaderUtil.GetRangeLimits(shader, i, 2);
     *
     *
     *
     *                          RangeProperty(propertyName, label, v2, v3);
     *                          GUILayout.EndHorizontal();
     *
     *                          break;
     *                  }
     *                  case ShaderUtil.ShaderPropertyType.Float: // floats
     *                  {
     *                          FloatProperty(propertyName, label);
     *                          break;
     *                  }
     *                  case ShaderUtil.ShaderPropertyType.Color: // colors
     *                  {
     *                          ColorProperty(propertyName, label);
     *                          break;
     *                  }
     *                  case ShaderUtil.ShaderPropertyType.TexEnv: // textures
     *                  {
     *                          ShaderUtil.ShaderPropertyTexDim desiredTexdim = ShaderUtil.GetTexDim(shader, i);
     *                          TextureProperty(propertyName, label, desiredTexdim);
     *
     *                          GUILayout.Space(6);
     *                          break;
     *                  }
     *                  case ShaderUtil.ShaderPropertyType.Vector: // vectors
     *                  {
     *                          VectorProperty(propertyName, label);
     *                          break;
     *                  }
     *                  default:
     *                  {
     *                          GUILayout.Label("Unknown property " + label + " : " + ShaderUtil.GetPropertyType(shader, i));
     *                          break;
     *                  }
     *          }
     *  }*/



    public override void OnInspectorGUI()
    {
        base.serializedObject.Update();
        var theShader = serializedObject.FindProperty("m_Shader");


        if (isVisible && !theShader.hasMultipleDifferentValues && theShader.objectReferenceValue != null)
        {
            Shader shader = theShader.objectReferenceValue as Shader;
            if (ShaderForgeInspector.IgnoreList.Contains(shader.name))
            {
            }
            else
            {
                // SHADER FORGE BUTTONS
                if (GUILayout.Button("Open shader in Shader Forge"))
                {
                    SF_Editor.Init(shader);
                }
                if (SF_Tools.advancedInspector)
                {
                    GUILayout.BeginHorizontal();
                    {
                        GUIStyle btnStyle = "MiniButton";
                        if (GUILayout.Button("Open shader code", btnStyle))
                        {
                            UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(AssetDatabase.GetAssetPath(shader), 1);
                        }
                        //if( GUILayout.Button( "Open compiled shader", btnStyle ) ) {
                        //	ShaderForgeInspector.OpenCompiledShader( shader );
                        //}
                    }
                    GUILayout.EndHorizontal();
                }
            }

            Material mat = target as Material;


            mat.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)EditorGUILayout.EnumPopup("Emission GI", mat.globalIlluminationFlags);

            GUILayout.Space(6);



            if (this.PropertiesGUI())
            {
                this.PropertiesChanged();
            }
        }
    }
        public override void OnInspectorGUI()
        {
            GUI.enabled = true;
            Shader shader = base.target as Shader;


            if (!SF_Tools.CanRunShaderForge())
            {
                SF_Tools.UnityOutOfDateGUI();
                return;
            }

            //EditorGUILayout.InspectorTitlebar( false, base.target );


            if (hasShaderForgeData)
            {
                if (GUILayout.Button("Open in Shader Forge"))
                {
                    if (Event.current.rawType != EventType.MouseDown)
                    {
                        SF_Editor.Init(shader);
                    }
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                {
                    //GUILayout.Label(SF_Styles.IconWarningSmall,GUILayout.Width(18),GUILayout.Height(18));
                    GUI.color = Color.gray;
                    GUILayout.Label("No Shader Forge data found!", EditorStyles.miniLabel);
                    GUI.color = Color.white;
                }
                GUILayout.EndHorizontal();
                //GUILayout.Label( "Opening this will clear the shader", EditorStyles.miniLabel );
                //GUI.color = new Color( 1f, 0.8f, 0.8f );
                if (GUILayout.Button(new GUIContent("Replace with Shader Forge shader", SF_Styles.IconWarningSmall, "This will erase any existing shader code"), hasShaderForgeData ? "Button" : "MiniButton"))
                {
                    if (SF_GUI.AcceptedNewShaderReplaceDialog())
                    {
                        SF_Editor.Init(shader);
                        SF_Editor.instance.ps.fChecker.UpdateAvailability();
                        SF_Editor.instance.OnShaderModified(NodeUpdateType.Hard);
                    }
                }
                //GUI.color = Color.white;
            }



            if (SF_Tools.advancedInspector)
            {
                GUILayout.BeginHorizontal();
                {
                    GUIStyle btnStyle = hasShaderForgeData ? "MiniButton" : "Button";
                    if (GUILayout.Button("Open shader code", btnStyle))
                    {
                        UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(AssetDatabase.GetAssetPath(shader), 1);
                    }
                    //if( GUILayout.Button( "Open compiled", btnStyle ) ) {
                    //	OpenCompiledShader( shader );
                    //}
                }
                GUILayout.EndHorizontal();
            }

            DrawUnitysInspector();
        }