Ejemplo n.º 1
0
        void OnEnable()
        {
            Shader shader   = base.target as Shader;
            string adbPath  = AssetDatabase.GetAssetPath(shader);
            string path     = SWCommon.AssetDBPath2Path(adbPath);
            string fullPath = SWCommon.Path2FullPath(path);

            isShaderWeaverShader = SWDataManager.IsSWShader(fullPath);

            // Reflect some things
            sipp = Type.GetType("UnityEditor.ShaderInspectorPlatformsPopup, UnityEditor");
            //newSipp = sipp.GetConstructor( new Type[] { typeof( string ) } );
            BindingFlags bfs        = BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty;
            BindingFlags privStatic = BindingFlags.NonPublic | BindingFlags.Static;

            sippCurrentMode             = sipp.GetProperty("currentMode", bfs);
            sippCurrentPlatformMask     = sipp.GetProperty("currentPlatformMask", bfs);
            sippCurrentVariantStripping = sipp.GetProperty("currentVariantStripping", bfs);

            shinsp = Type.GetType("UnityEditor.ShaderInspector, UnityEditor");
            shinspGetErrorListUI = shinsp.GetMethod("ShaderErrorListUI", privStatic);

            sutil = Type.GetType("UnityEditor.ShaderUtil, UnityEditor");
            sutilHasShadowCasterPass = sutil.GetMethod("HasShadowCasterPass", privStatic);
            sutilGetRenderQueue      = sutil.GetMethod("GetRenderQueue", privStatic);
            sutilGetLOD = sutil.GetMethod("GetLOD", privStatic);
            sutilDoesIgnoreProjector     = sutil.GetMethod("DoesIgnoreProjector", privStatic);
            sutilHasSurfaceShaders       = sutil.GetMethod("HasSurfaceShaders", privStatic);
            sutilHasShaderSnippets       = sutil.GetMethod("HasShaderSnippets", privStatic);
            sutilOpenParsedSurfaceShader = sutil.GetMethod("OpenParsedSurfaceShader", privStatic);
            sutilOpenCompiledShader      = sutil.GetMethod("OpenCompiledShader", privStatic);
            sutilGetShaderErrorCount     = sutil.GetMethod("GetShaderErrorCount", privStatic);
            sutilGetShaderErrors         = sutil.GetMethod("GetShaderErrors", privStatic);

            //BindingFlags priv = BindingFlags.NonPublic;
            shaderDisableBatching = typeof(Shader).GetProperty("disableBatching", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);

            //disableBatchingType = Type.GetType( "UnityEngine.DisableBatchingType, UnityEngine" );

            //editorGUIMouseButtonDown = typeof( EditorGUI ).GetMethod( "ButtonMouseDown", privStatic, null, new Type[]{typeof(Rect),typeof(GUIContent),typeof(FocusType),typeof(GUIStyle)}, null );

            //Type guilaGroup = Type.GetType( "UnityEngine.GUILayoutGroup, UnityEngine" );
            //guilayoutgroupGetLast = guilaGroup.GetMethod( "GetLast", BindingFlags.Instance | BindingFlags.Public );
            //guiLayoutUtilityTopLevel = typeof( GUILayoutUtility ).GetProperty( "topLevel", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetProperty );
            editorGuiUtilityLoadIcon    = typeof(EditorGUIUtility).GetMethod("LoadIcon", privStatic);
            editorGuiUtilityTextContent = typeof(EditorGUIUtility).GetMethod("TextContent", privStatic);
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();


            Material mat = (Material)target;

            if (shader != mat.shader)
            {
                shader = mat.shader;
                string adbPath  = AssetDatabase.GetAssetPath(shader);
                string path     = SWCommon.AssetDBPath2Path(adbPath);
                string fullPath = SWCommon.Path2FullPath(path);
                if (File.Exists(fullPath))
                {
                    isShaderWeaverShader = SWDataManager.IsSWShader(fullPath);
                }
                else
                {
                    isShaderWeaverShader = false;
                }
            }

            if (isShaderWeaverShader)
            {
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Open in Shader Weaver", GUILayout.Height(36)))
                {
                    SWWindowMain.OpenFromInspector(shader);
                }

                if (GUILayout.Button("Open in Text Editor", GUILayout.Height(36)))
                {
                    AssetDatabase.OpenAsset(shader, 1);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(20);
            }
        }