Assignment for RMIT Mixed Reality in 2020
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.

117 lines
2.8 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 bool console;
  19. public GenericMessageData( string msg, MessageSeverity svrty, bool csle )
  20. {
  21. message = msg;
  22. severity = svrty;
  23. console = csle;
  24. }
  25. }
  26. class GenericMessageUI
  27. {
  28. public delegate void OnMessageDisplay( string message, MessageSeverity severity, bool console );
  29. public event OnMessageDisplay OnMessageDisplayEvent;
  30. private const double MESSAGE_TIME = 2;
  31. private double m_currentMessageStartTime;
  32. private Queue<GenericMessageData> m_messageQueue;
  33. private bool m_displayingMessage;
  34. public GenericMessageUI()
  35. {
  36. m_messageQueue = new Queue<GenericMessageData>();
  37. m_displayingMessage = false;
  38. m_currentMessageStartTime = EditorApplication.timeSinceStartup;
  39. }
  40. public void Destroy()
  41. {
  42. m_messageQueue.Clear();
  43. OnMessageDisplayEvent = null;
  44. }
  45. public void AddToQueue( string message, MessageSeverity severity, bool console )
  46. {
  47. m_messageQueue.Enqueue( new GenericMessageData( message, severity, console ) );
  48. }
  49. public void Log( string message )
  50. {
  51. m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Normal, true ) );
  52. Debug.Log( message );
  53. }
  54. public void LogError( string message )
  55. {
  56. m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Error, true ) );
  57. Debug.LogError( message );
  58. }
  59. public void LogWarning( string message )
  60. {
  61. m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Warning, true ) );
  62. Debug.LogWarning( message );
  63. }
  64. public void CheckForMessages()
  65. {
  66. if ( m_displayingMessage )
  67. {
  68. double timeLeft = EditorApplication.timeSinceStartup - m_currentMessageStartTime;
  69. if ( timeLeft > MESSAGE_TIME )
  70. {
  71. m_displayingMessage = false;
  72. }
  73. }
  74. if ( !m_displayingMessage )
  75. {
  76. if ( m_messageQueue.Count > 0 )
  77. {
  78. m_displayingMessage = true;
  79. GenericMessageData data = m_messageQueue.Dequeue();
  80. m_currentMessageStartTime = EditorApplication.timeSinceStartup;
  81. if ( OnMessageDisplayEvent != null )
  82. OnMessageDisplayEvent( data.message, data.severity, data.console );
  83. }
  84. }
  85. }
  86. public void CleanUpMessageStack()
  87. {
  88. m_displayingMessage = false;
  89. m_messageQueue.Clear();
  90. }
  91. public void StartMessageCounter()
  92. {
  93. m_displayingMessage = true;
  94. m_currentMessageStartTime = EditorApplication.timeSinceStartup;
  95. }
  96. public bool DisplayingMessage
  97. {
  98. get { return ( m_displayingMessage || m_messageQueue.Count > 0 ); }
  99. }
  100. }
  101. }