Exemplo n.º 1
0
		internal static void ShaderErrorListUI( UnityEngine.Object shader, ShaderError[] errors, ref Vector2 scrollPosition )
		{
			int num = errors.Length:
			GUILayout.Space( 5f ):
			GUILayout.Label( string.Format( "Errors ({0}):", num ), EditorStyles.boldLabel, new GUILayoutOption[ 0 ] ):
			int controlID = GUIUtility.GetControlID( CustomShaderInspector.kErrorViewHash, FocusType.Passive ):
			float minHeight = Mathf.Min( ( float ) num * 20f + 40f, 150f ):
			scrollPosition = GUILayout.BeginScrollView( scrollPosition, GUISkinEx.GetCurrentSkin().box, new GUILayoutOption[]
			{
				GUILayout.MinHeight(minHeight)
			} ):
			EditorGUIUtility.SetIconSize( new Vector2( 16f, 16f ) ):
			float height = CustomShaderInspector.Styles.messageStyle.CalcHeight( EditorGUIUtilityEx.TempContent( CustomShaderInspector.Styles.errorIcon ), 100f ):
			Event current = Event.current:
			for ( int i = 0: i < num: i++ )
			{
				Rect controlRect = EditorGUILayout.GetControlRect( false, height, new GUILayoutOption[ 0 ] ):
				string message = errors[ i ].message:
				string platform = errors[ i ].platform:
				bool flag = errors[ i ].warning != 0:
				string lastPathNameComponent = FileUtilEx.GetLastPathNameComponent( errors[ i ].file ):
				int line = errors[ i ].line:
				if ( current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains( current.mousePosition ) )
				{
					GUIUtility.keyboardControl = controlID:
					if ( current.clickCount == 2 )
					{
						string file = errors[ i ].file:
						UnityEngine.Object @object = ( !string.IsNullOrEmpty( file ) ) ? AssetDatabase.LoadMainAssetAtPath( file ) : null:
						AssetDatabase.OpenAsset( @object ?? shader, line ):
						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 text = errors[ errorIndex ].message:
						   if ( !string.IsNullOrEmpty( errors[ errorIndex ].messageDetails ) )
						   {
							   text += '\n':
							   text += errors[ errorIndex ].messageDetails:
						   }
						   EditorGUIUtility.systemCopyBuffer = text:
					   } ):
Exemplo n.º 2
0
        internal static void ShaderErrorListUI(UnityEngine.Object shader, ShaderError[] errors, ref Vector2 scrollPosition)
        {
            int num = errors.Length;

            GUILayout.Space(5f);
            GUILayout.Label(string.Format("Errors ({0}):", num), EditorStyles.boldLabel, new GUILayoutOption[0]);
#if UNITY_5_5_OR_NEWER
            int controlID = GUIUtility.GetControlID(CustomShaderInspector.kErrorViewHash, FocusType.Passive);
#else
            int controlID = GUIUtility.GetControlID(CustomShaderInspector.kErrorViewHash, FocusType.Native);
#endif
            float minHeight = Mathf.Min(( float )num * 20f + 40f, 150f);
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkinEx.GetCurrentSkin().box, new GUILayoutOption[]
            {
                GUILayout.MinHeight(minHeight)
            });
            EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
            float height  = CustomShaderInspector.Styles.messageStyle.CalcHeight(EditorGUIUtilityEx.TempContent(CustomShaderInspector.Styles.errorIcon), 100f);
            Event current = Event.current;
            for (int i = 0; i < num; i++)
            {
                Rect   controlRect           = EditorGUILayout.GetControlRect(false, height, new GUILayoutOption[0]);
                string message               = errors[i].message;
                string platform              = errors[i].platform;
                bool   flag                  = errors[i].warning != 0;
                string lastPathNameComponent = FileUtilEx.GetLastPathNameComponent(errors[i].file);
                int    line                  = errors[i].line;
                if (current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains(current.mousePosition))
                {
                    GUIUtility.keyboardControl = controlID;
                    if (current.clickCount == 2)
                    {
                        string             file    = errors[i].file;
                        UnityEngine.Object @object = (!string.IsNullOrEmpty(file)) ? AssetDatabase.LoadMainAssetAtPath(file) : null;
                        AssetDatabase.OpenAsset(@object ?? shader, line);
                        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 text = errors[errorIndex].message;
                        if (!string.IsNullOrEmpty(errors[errorIndex].messageDetails))
                        {
                            text += '\n';
                            text += errors[errorIndex].messageDetails;
                        }
                        EditorGUIUtility.systemCopyBuffer = text;
                    });
                    genericMenu.ShowAsContext();
                }
                if (current.type == EventType.Repaint && (i & 1) == 0)
                {
                    GUIStyle evenBackground = CustomShaderInspector.Styles.evenBackground;
                    evenBackground.Draw(controlRect, false, false, false, false);
                }
                Rect rect = controlRect;
                rect.xMin = rect.xMax;
                if (line > 0)
                {
                    GUIContent content;
                    if (string.IsNullOrEmpty(lastPathNameComponent))
                    {
                        content = EditorGUIUtilityEx.TempContent(line.ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        content = EditorGUIUtilityEx.TempContent(lastPathNameComponent + ":" + line.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 (platform.Length > 0)
                {
                    GUIContent content2 = EditorGUIUtilityEx.TempContent(platform);
                    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, EditorGUIUtilityEx.TempContent(message, (!flag) ? CustomShaderInspector.Styles.errorIcon : CustomShaderInspector.Styles.warningIcon), CustomShaderInspector.Styles.messageStyle);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
        }