You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.5 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace AmplifyShaderEditor
  7. {
  8. public class ConsoleLogItem
  9. {
  10. public NodeMessageType ItemType;
  11. public string ItemMessage;
  12. public ConsoleLogItem( NodeMessageType itemType, string itemMessage )
  13. {
  14. ItemType = itemType;
  15. ItemMessage = itemMessage;
  16. }
  17. }
  18. public sealed class ConsoleLogWindow : MenuParent
  19. {
  20. const float ToolbarHeight = 32;
  21. private List<ConsoleLogItem> m_messages = new List<ConsoleLogItem>();
  22. public ConsoleLogWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 0, 128, string.Empty, MenuAnchor.BOTTOM_LEFT, MenuAutoSize.NONE )
  23. {
  24. m_isActive = false;
  25. }
  26. public void AddMessage( NodeMessageType itemType, string itemMessage )
  27. {
  28. //m_messages.Insert( 0, new ConsoleLogItem( itemType, itemMessage ) );
  29. }
  30. public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
  31. {
  32. base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
  33. Rect toolbarArea = m_transformedArea;
  34. toolbarArea.height = ToolbarHeight;
  35. GUILayout.BeginArea( toolbarArea, m_content, m_style );
  36. EditorGUILayout.BeginHorizontal();
  37. {
  38. if( GUILayout.Button( "Clear", GUILayout.MaxWidth( 50 ) ) )
  39. {
  40. m_messages.Clear();
  41. }
  42. }
  43. EditorGUILayout.EndHorizontal();
  44. GUILayout.EndArea();
  45. m_transformedArea.y += ToolbarHeight;
  46. m_transformedArea.height -= ToolbarHeight;
  47. GUILayout.BeginArea( m_transformedArea, m_content, m_style );
  48. {
  49. EditorGUILayout.BeginVertical();
  50. {
  51. m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos, GUILayout.Width( 0 ), GUILayout.Height( 0 ) );
  52. {
  53. int count = m_messages.Count;
  54. for( int i = 0; i < count; i++ )
  55. {
  56. EditorGUILayout.LabelField( i + ": " + m_messages[ i ].ItemMessage );
  57. }
  58. }
  59. EditorGUILayout.EndScrollView();
  60. }
  61. EditorGUILayout.EndVertical();
  62. }
  63. GUILayout.EndArea();
  64. //if( Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.Alpha1 )
  65. //{
  66. // UIUtils.ShowMessage( "Test Message " + m_messages.Count );
  67. //}
  68. }
  69. public void ClearMessages()
  70. {
  71. m_messages.Clear();
  72. }
  73. public void Toggle()
  74. {
  75. //m_isActive = !m_isActive;
  76. }
  77. public override void Destroy()
  78. {
  79. base.Destroy();
  80. m_messages.Clear();
  81. m_messages = null;
  82. }
  83. }
  84. }