Esempio n. 1
0
        private void ShowShaderErrors(Shader s)
        {
            int errorCount = ShaderUtil.GetErrorCount(s);

            if (errorCount < 1)
            {
                return;
            }
            GUILayout.Space(5f);
            GUILayout.Label("Errors:", EditorStyles.boldLabel, new GUILayoutOption[0]);
            int   controlID = GUIUtility.GetControlID(ShaderInspector.kErrorViewHash, FocusType.Native);
            float minHeight = Mathf.Min((float)errorCount * 20f + 40f, 150f);

            this.m_ScrollPosition = GUILayout.BeginScrollView(this.m_ScrollPosition, GUISkin.current.box, new GUILayoutOption[]
            {
                GUILayout.MinHeight(minHeight)
            });
            EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
            float height  = ShaderInspector.Styles.messageStyle.CalcHeight(EditorGUIUtility.TempContent(ShaderInspector.Styles.errorIcon), 100f);
            Event current = Event.current;

            for (int i = 0; i < errorCount; i++)
            {
                Rect   controlRect         = EditorGUILayout.GetControlRect(false, height, new GUILayoutOption[0]);
                string shaderErrorMessage  = ShaderUtil.GetShaderErrorMessage(s, i, false);
                string shaderErrorPlatform = ShaderUtil.GetShaderErrorPlatform(s, i);
                bool   shaderErrorWarning  = ShaderUtil.GetShaderErrorWarning(s, i);
                string shaderErrorFile     = ShaderUtil.GetShaderErrorFile(s, i, true);
                int    shaderErrorLine     = ShaderUtil.GetShaderErrorLine(s, i);
                if (current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains(current.mousePosition))
                {
                    GUIUtility.keyboardControl = controlID;
                    if (current.clickCount == 2)
                    {
                        string             shaderErrorFile2 = ShaderUtil.GetShaderErrorFile(s, i, false);
                        UnityEngine.Object @object          = (!string.IsNullOrEmpty(shaderErrorFile2)) ? AssetDatabase.LoadMainAssetAtPath(shaderErrorFile2) : null;
                        AssetDatabase.OpenAsset(@object ?? s, shaderErrorLine);
                        GUIUtility.ExitGUI();
                    }
                    current.Use();
                }
                if (current.type == EventType.ContextClick && controlRect.Contains(current.mousePosition))
                {
                    current.Use();
                    GenericMenu genericMenu = new GenericMenu();
                    int         errorIndex  = i;
                    genericMenu.AddItem(new GUIContent("Copy error text"), false, delegate
                    {
                        string shaderErrorMessage2        = ShaderUtil.GetShaderErrorMessage(s, errorIndex, true);
                        EditorGUIUtility.systemCopyBuffer = shaderErrorMessage2;
                    });
                    genericMenu.ShowAsContext();
                }
                if (current.type == EventType.Repaint && (i & 1) == 0)
                {
                    GUIStyle evenBackground = ShaderInspector.Styles.evenBackground;
                    evenBackground.Draw(controlRect, false, false, false, false);
                }
                Rect rect = controlRect;
                rect.xMin = rect.xMax;
                if (shaderErrorLine > 0)
                {
                    GUIContent content;
                    if (string.IsNullOrEmpty(shaderErrorFile))
                    {
                        content = EditorGUIUtility.TempContent(shaderErrorLine.ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        content = EditorGUIUtility.TempContent(shaderErrorFile + ":" + shaderErrorLine.ToString(CultureInfo.InvariantCulture));
                    }
                    Vector2 vector = EditorStyles.miniLabel.CalcSize(content);
                    rect.xMin -= vector.x;
                    GUI.Label(rect, content, EditorStyles.miniLabel);
                    rect.xMin -= 2f;
                    if (rect.width < 30f)
                    {
                        rect.xMin = rect.xMax - 30f;
                    }
                }
                Rect position = rect;
                position.width = 0f;
                if (shaderErrorPlatform.Length > 0)
                {
                    GUIContent content2 = EditorGUIUtility.TempContent(shaderErrorPlatform);
                    Vector2    vector2  = EditorStyles.miniLabel.CalcSize(content2);
                    position.xMin -= vector2.x;
                    Color contentColor = GUI.contentColor;
                    GUI.contentColor = new Color(1f, 1f, 1f, 0.5f);
                    GUI.Label(position, content2, EditorStyles.miniLabel);
                    GUI.contentColor = contentColor;
                    position.xMin   -= 2f;
                }
                Rect position2 = controlRect;
                position2.xMax = position.xMin;
                GUI.Label(position2, EditorGUIUtility.TempContent(shaderErrorMessage, (!shaderErrorWarning) ? ShaderInspector.Styles.errorIcon : ShaderInspector.Styles.warningIcon), ShaderInspector.Styles.messageStyle);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
        }