PiNode.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. namespace AmplifyShaderEditor
  7. {
  8. [Serializable]
  9. [NodeAttributes( "PI", "Constants And Properties", "PI constant : 3.14159265359" )]
  10. public sealed class PiNode : ParentNode
  11. {
  12. public PiNode() : base() { }
  13. public PiNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
  14. protected override void CommonInit( int uniqueId )
  15. {
  16. base.CommonInit( uniqueId );
  17. AddInputPort( WirePortDataType.FLOAT, true, "Multiplier" );
  18. AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
  19. m_textLabelWidth = 70;
  20. InputPorts[ 0 ].FloatInternalData = 1;
  21. m_useInternalPortData = true;
  22. m_previewShaderGUID = "bf4a65726dab3d445a69fb1d0945c33e";
  23. }
  24. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  25. {
  26. base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
  27. string finalValue = string.Empty;
  28. string piString = dataCollector.IsSRP ? "PI" : "UNITY_PI";
  29. if( !InputPorts[ 0 ].IsConnected && InputPorts[ 0 ].FloatInternalData == 1 )
  30. {
  31. finalValue = piString;
  32. } else
  33. {
  34. string multiplier = InputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  35. finalValue = "( " + multiplier + " * " + piString + " )";
  36. }
  37. if ( finalValue.Equals( string.Empty ) )
  38. {
  39. UIUtils.ShowMessage( UniqueId, "PINode generating empty code", MessageSeverity.Warning );
  40. }
  41. return finalValue;
  42. }
  43. //public override void ReadFromString( ref string[] nodeParams )
  44. //{
  45. // base.ReadFromString( ref nodeParams );
  46. // Removed on version 5004
  47. //m_value = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
  48. //}
  49. //public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  50. //{
  51. // base.WriteToString( ref nodeInfo, ref connectionsInfo );
  52. //}
  53. }
  54. }