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.

115 lines
2.7 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEditor;
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. namespace AmplifyShaderEditor
  7. {
  8. public enum MessageSeverity
  9. {
  10. Normal,
  11. Warning,
  12. Error
  13. }
  14. public class GenericMessageData
  15. {
  16. public string message;
  17. public MessageSeverity severity;
  18. public GenericMessageData( string msg, MessageSeverity svrty )
  19. {
  20. message = msg;
  21. severity = svrty;
  22. }
  23. }
  24. class GenericMessageUI
  25. {
  26. public delegate void OnMessageDisplay( string message, MessageSeverity severity );
  27. public event OnMessageDisplay OnMessageDisplayEvent;
  28. private const double MESSAGE_TIME = 2;
  29. private double m_currentMessageStartTime;
  30. private Queue<GenericMessageData> m_messageQueue;
  31. private bool m_displayingMessage;
  32. public GenericMessageUI()
  33. {
  34. m_messageQueue = new Queue<GenericMessageData>();
  35. m_displayingMessage = false;
  36. m_currentMessageStartTime = EditorApplication.timeSinceStartup;
  37. }
  38. public void Destroy()
  39. {
  40. m_messageQueue.Clear();
  41. OnMessageDisplayEvent = null;
  42. }
  43. public void AddToQueue( string message, MessageSeverity severity )
  44. {
  45. m_messageQueue.Enqueue( new GenericMessageData( message, severity ) );
  46. }
  47. public void Log( string message )
  48. {
  49. m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Normal ) );
  50. Debug.Log( message );
  51. }
  52. public void LogError( string message )
  53. {
  54. m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Error ) );
  55. Debug.LogError( message );
  56. }
  57. public void LogWarning( string message )
  58. {
  59. m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Warning ) );
  60. Debug.LogWarning( message );
  61. }
  62. public void CheckForMessages()
  63. {
  64. if ( m_displayingMessage )
  65. {
  66. double timeLeft = EditorApplication.timeSinceStartup - m_currentMessageStartTime;
  67. if ( timeLeft > MESSAGE_TIME )
  68. {
  69. m_displayingMessage = false;
  70. }
  71. }
  72. if ( !m_displayingMessage )
  73. {
  74. if ( m_messageQueue.Count > 0 )
  75. {
  76. m_displayingMessage = true;
  77. GenericMessageData data = m_messageQueue.Dequeue();
  78. m_currentMessageStartTime = EditorApplication.timeSinceStartup;
  79. if ( OnMessageDisplayEvent != null )
  80. OnMessageDisplayEvent( data.message, data.severity );
  81. }
  82. }
  83. }
  84. public void CleanUpMessageStack()
  85. {
  86. m_displayingMessage = false;
  87. m_messageQueue.Clear();
  88. }
  89. public void StartMessageCounter()
  90. {
  91. m_displayingMessage = true;
  92. m_currentMessageStartTime = EditorApplication.timeSinceStartup;
  93. }
  94. public bool DisplayingMessage
  95. {
  96. get { return ( m_displayingMessage || m_messageQueue.Count > 0 ); }
  97. }
  98. }
  99. }