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.

80 lines
2.0 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace AmplifyShaderEditor
  6. {
  7. [System.Serializable]
  8. [NodeAttributes( "Log", "Master", "Debug node to dump output to log", null, KeyCode.None, false )]
  9. public sealed class LogNode : MasterNode
  10. {
  11. private const string InputAmountStr = "Input amount";
  12. [SerializeField]
  13. private int m_inputCount = 1;
  14. [SerializeField]
  15. private int m_lastInputCount = 1;
  16. public LogNode() : base() { }
  17. public LogNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
  18. protected override void CommonInit( int uniqueId )
  19. {
  20. base.CommonInit( uniqueId );
  21. AddMasterPorts();
  22. }
  23. public override void AddMasterPorts()
  24. {
  25. DeleteAllInputConnections( true );
  26. base.AddMasterPorts();
  27. for ( int i = 0; i < m_inputCount; i++ )
  28. {
  29. AddInputPort( WirePortDataType.OBJECT, false, i.ToString() );
  30. }
  31. m_sizeIsDirty = true;
  32. }
  33. public override void DrawProperties()
  34. {
  35. base.DrawProperties();
  36. EditorGUILayout.BeginVertical();
  37. {
  38. EditorGUILayout.LabelField( InputAmountStr );
  39. m_inputCount = EditorGUILayoutIntField( m_inputCount );
  40. }
  41. EditorGUILayout.EndVertical();
  42. if ( m_inputCount != m_lastInputCount )
  43. {
  44. m_lastInputCount = Mathf.Max( m_inputCount, 1 );
  45. AddMasterPorts();
  46. }
  47. }
  48. public override void Execute( Shader currentSelected )
  49. {
  50. string valueDump = "";
  51. string valueInstructions = "";
  52. MasterNodeDataCollector dataCollector = new MasterNodeDataCollector( this );
  53. foreach ( InputPort port in InputPorts )
  54. {
  55. if ( port.IsConnected )
  56. {
  57. valueInstructions += "Port: " + port.PortId + " Value: " + port.GenerateShaderForOutput( ref dataCollector, port.DataType, false );
  58. }
  59. }
  60. Debug.Log( "Value: " + valueDump );
  61. Debug.Log( "Instructions: " + valueInstructions );
  62. }
  63. public override void ReadFromString( ref string[] nodeParams )
  64. {
  65. base.ReadFromString( ref nodeParams );
  66. }
  67. }
  68. }