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.

120 lines
3.1 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. namespace AmplifyShaderEditor
  6. {
  7. public class ConfirmationWindow
  8. {
  9. public delegate ShaderLoadResult OnConfirmationSelected( bool value, Shader shader, Material material );
  10. public event OnConfirmationSelected OnConfirmationSelectedEvt;
  11. private const string m_yesStr = "Yes";
  12. private const string m_noStr = "No";
  13. private bool m_isActive = false;
  14. private string m_currentMessage;
  15. private GUIStyle m_areaStyle;
  16. private GUIContent m_content;
  17. private GUIStyle m_buttonStyle;
  18. private GUIStyle m_labelStyle;
  19. private Shader m_shader;
  20. private Material m_material;
  21. private Rect m_area;
  22. private bool m_autoDeactivate = true;
  23. public ConfirmationWindow( float x, float y, float width, float height )
  24. {
  25. m_content = new GUIContent( GUIContent.none );
  26. m_area = new Rect( x, y, width, height );
  27. }
  28. public void Destroy()
  29. {
  30. m_shader = null;
  31. OnConfirmationSelectedEvt = null;
  32. }
  33. public void ActivateConfirmation( Shader shader, Material material, string message, OnConfirmationSelected evt, bool autoDeactivate = true )
  34. {
  35. OnConfirmationSelectedEvt = evt;
  36. m_currentMessage = message;
  37. m_shader = shader;
  38. m_material = material;
  39. m_autoDeactivate = autoDeactivate;
  40. m_isActive = true;
  41. }
  42. public void OnGUI()
  43. {
  44. if ( m_areaStyle == null )
  45. {
  46. m_areaStyle = new GUIStyle( UIUtils.TextArea );
  47. m_areaStyle.stretchHeight = true;
  48. m_areaStyle.stretchWidth = true;
  49. m_areaStyle.fontSize = ( int ) Constants.DefaultTitleFontSize;
  50. }
  51. if ( m_buttonStyle == null )
  52. {
  53. m_buttonStyle = UIUtils.Button;
  54. }
  55. if ( m_labelStyle == null )
  56. {
  57. m_labelStyle = new GUIStyle( UIUtils.Label );
  58. m_labelStyle.alignment = TextAnchor.MiddleCenter;
  59. m_labelStyle.wordWrap = true;
  60. }
  61. m_area.x = ( int ) ( 0.5f * UIUtils.CurrentWindow.CameraInfo.width );
  62. m_area.y = ( int ) ( 0.5f * UIUtils.CurrentWindow.CameraInfo.height );
  63. GUILayout.BeginArea( m_area, m_content, m_areaStyle );
  64. {
  65. EditorGUILayout.BeginVertical();
  66. {
  67. EditorGUILayout.Separator();
  68. EditorGUILayout.LabelField( m_currentMessage, m_labelStyle );
  69. EditorGUILayout.Separator();
  70. EditorGUILayout.Separator();
  71. EditorGUILayout.BeginHorizontal();
  72. {
  73. if ( GUILayout.Button( m_yesStr, m_buttonStyle ) )
  74. {
  75. if ( OnConfirmationSelectedEvt != null )
  76. OnConfirmationSelectedEvt( true, m_shader, m_material );
  77. if ( m_autoDeactivate )
  78. Deactivate();
  79. }
  80. if ( GUILayout.Button( m_noStr, m_buttonStyle ) )
  81. {
  82. if ( OnConfirmationSelectedEvt != null )
  83. OnConfirmationSelectedEvt( false, m_shader, m_material );
  84. if ( m_autoDeactivate )
  85. Deactivate();
  86. }
  87. }
  88. EditorGUILayout.EndHorizontal();
  89. }
  90. EditorGUILayout.EndVertical();
  91. }
  92. GUILayout.EndArea();
  93. }
  94. public void Deactivate()
  95. {
  96. m_isActive = false;
  97. OnConfirmationSelectedEvt = null;
  98. }
  99. public bool IsActive { get { return m_isActive; } }
  100. }
  101. }