DebugConsoleWindow.cs 6.1 KB

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