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.

191 lines
5.5 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. //#define ASE_CONSOLE_WINDOW
  4. using UnityEngine;
  5. using UnityEditor;
  6. using System.Collections.Generic;
  7. namespace AmplifyShaderEditor
  8. {
  9. public sealed class DebugConsoleWindow : EditorWindow
  10. {
  11. private const float WindowSizeX = 250;
  12. private const float WindowSizeY = 250;
  13. private const float WindowPosX = 5;
  14. private const float WindowPosY = 5;
  15. private Rect m_availableArea;
  16. private bool m_wikiAreaFoldout = true;
  17. private bool m_miscAreaFoldout = true;
  18. private Vector2 m_currentScrollPos;
  19. #if ASE_CONSOLE_WINDOW
  20. public readonly static bool DeveloperMode = true;
  21. public static bool UseShaderPanelsInfo = true;
  22. [MenuItem( "Window/Amplify Shader Editor/Open Debug Console" )]
  23. static void OpenMainShaderGraph()
  24. {
  25. OpenWindow();
  26. }
  27. [MenuItem( "Window/Amplify Shader Editor/Create Template Menu Items" )]
  28. public static void CreateTemplateMenuItems()
  29. {
  30. UIUtils.CurrentWindow.TemplatesManagerInstance.CreateTemplateMenuItems();
  31. }
  32. #else
  33. public readonly static bool DeveloperMode = false;
  34. public static bool UseShaderPanelsInfo = false;
  35. #endif
  36. public static DebugConsoleWindow OpenWindow()
  37. {
  38. if ( DeveloperMode )
  39. {
  40. DebugConsoleWindow currentWindow = ( DebugConsoleWindow ) DebugConsoleWindow.GetWindow( typeof( DebugConsoleWindow ), false, "ASE Debug Console" );
  41. currentWindow.titleContent.tooltip = "Debug Options for ASE. Intented only for ASE development team";
  42. currentWindow.minSize = new Vector2( WindowSizeX, WindowSizeY );
  43. currentWindow.maxSize = new Vector2( WindowSizeX, 2 * WindowSizeY ); ;
  44. currentWindow.wantsMouseMove = true;
  45. return currentWindow;
  46. }
  47. return null;
  48. }
  49. void OnGUI()
  50. {
  51. m_availableArea = new Rect( WindowPosX, WindowPosY, position.width - 2 * WindowPosX, position.height - 2 * WindowPosY );
  52. GUILayout.BeginArea( m_availableArea );
  53. {
  54. m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos, GUILayout.Width( 0 ), GUILayout.Height( 0 ) );
  55. {
  56. EditorGUILayout.BeginVertical();
  57. {
  58. AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
  59. if ( window != null )
  60. {
  61. EditorGUILayout.Separator();
  62. NodeUtils.DrawPropertyGroup( ref m_wikiAreaFoldout, "Wiki Helper", ShowWikiHelperFunctions );
  63. EditorGUILayout.Separator();
  64. NodeUtils.DrawPropertyGroup( ref m_miscAreaFoldout, "Misc", ShowMiscFuntions );
  65. EditorGUILayout.Separator();
  66. }
  67. else
  68. {
  69. EditorGUILayout.LabelField( "Please open an ASE window to access debug options" );
  70. }
  71. }
  72. EditorGUILayout.EndVertical();
  73. }
  74. EditorGUILayout.EndScrollView();
  75. }
  76. GUILayout.EndArea();
  77. }
  78. void ShowWikiHelperFunctions()
  79. {
  80. AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
  81. EditorGUILayout.Separator();
  82. if ( GUILayout.Button( "Nodes Screen Shots" ) )
  83. {
  84. window.CurrentNodeExporterUtils.ActivateAutoScreenShot( Application.dataPath + "/../NodesInfo/Shots/" );
  85. }
  86. EditorGUILayout.Separator();
  87. if( GUILayout.Button( "Nodes Undo Test" ) )
  88. {
  89. window.CurrentNodeExporterUtils.ActivateAutoUndo();
  90. }
  91. EditorGUILayout.Separator();
  92. if ( GUILayout.Button( "Nodes Info" ) )
  93. {
  94. window.CurrentPaletteWindow.DumpAvailableNodes( false, Application.dataPath + "/../NodesInfo/" );
  95. window.CurrentPaletteWindow.DumpAvailableNodes( true, Application.dataPath + "/../NodesInfo/" );
  96. }
  97. EditorGUILayout.Separator();
  98. if ( GUILayout.Button( "Shortcuts Info" ) )
  99. {
  100. window.ShortcutManagerInstance.DumpShortcutsToDisk( Application.dataPath + "/../NodesInfo/" );
  101. }
  102. }
  103. void ShowMiscFuntions()
  104. {
  105. AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
  106. if ( GUILayout.Button( "Force Example Shader Compilation" ) )
  107. {
  108. UIUtils.ForceExampleShaderCompilation();
  109. }
  110. EditorGUILayout.Separator();
  111. if ( GUILayout.Button( "Refresh Available Nodes" ) )
  112. {
  113. window.RefreshAvaibleNodes();
  114. }
  115. EditorGUILayout.Separator();
  116. if ( GUILayout.Button( "Dump Uniform Names" ) )
  117. {
  118. //window.CurrentPaletteWindow.NewList()
  119. window.DuplicatePrevBufferInstance.DumpUniformNames();
  120. }
  121. EditorGUILayout.Separator();
  122. if ( GUILayout.Button( "Force Palette Update" ) )
  123. {
  124. Debug.Log( UIUtils.CurrentWindow.IsShaderFunctionWindow );
  125. window.CurrentPaletteWindow.ForceUpdate = true;
  126. }
  127. EditorGUILayout.Separator();
  128. if( GUILayout.Button( "Detect Infinite Loops" ) )
  129. {
  130. if( window.IsShaderFunctionWindow )
  131. {
  132. Debug.Log( "Starting infinite loop detection over shader functions" );
  133. List<FunctionOutput> nodes = window.OutsideGraph.FunctionOutputNodes.NodesList;
  134. for( int i = 0; i < nodes.Count; i++ )
  135. {
  136. UIUtils.DetectNodeLoopsFrom( nodes[ i ], new Dictionary<int, int>() );
  137. }
  138. }
  139. else
  140. {
  141. if( window.OutsideGraph.MultiPassMasterNodes.Count > 0 )
  142. {
  143. Debug.Log( "Starting infinite loop detection over shader from template" );
  144. List<TemplateMultiPassMasterNode> nodes = window.OutsideGraph.MultiPassMasterNodes.NodesList;
  145. for( int i = 0; i < nodes.Count; i++ )
  146. {
  147. UIUtils.DetectNodeLoopsFrom( nodes[ i ], new Dictionary<int, int>() );
  148. }
  149. }
  150. else
  151. {
  152. Debug.Log( "Starting infinite loop detection over standard shader" );
  153. UIUtils.DetectNodeLoopsFrom( window.OutsideGraph.CurrentMasterNode, new Dictionary<int, int>() );
  154. }
  155. }
  156. Debug.Log( "End infinite loop detection" );
  157. }
  158. }
  159. }
  160. }