summaryrefslogtreecommitdiff
path: root/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/PiNode.cs
blob: 659a128ce85d1fdcf5ecaa029038dc2ff9bf432e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>

using UnityEngine;
using UnityEditor;
using System;

namespace AmplifyShaderEditor
{
	[Serializable]
	[NodeAttributes( "PI", "Constants And Properties", "PI constant : 3.14159265359" )]
	public sealed class PiNode : ParentNode
	{
		public PiNode() : base() { }
		public PiNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
		protected override void CommonInit( int uniqueId )
		{
			base.CommonInit( uniqueId );
			AddInputPort( WirePortDataType.FLOAT, true, "Multiplier" );
			AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
			m_textLabelWidth = 70;
			InputPorts[ 0 ].FloatInternalData = 1;
			m_useInternalPortData = true;
			m_previewShaderGUID = "bf4a65726dab3d445a69fb1d0945c33e";
		}

		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
			string finalValue = string.Empty;
			string piString = dataCollector.IsSRP ? "PI" : "UNITY_PI";
			if( !InputPorts[ 0 ].IsConnected && InputPorts[ 0 ].FloatInternalData == 1 )
			{
				finalValue = piString;
			} else
			{
				string multiplier = InputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
				finalValue = "( " + multiplier + " * " + piString + " )";
			}


			if ( finalValue.Equals( string.Empty ) )
			{
				UIUtils.ShowMessage( UniqueId, "PINode generating empty code", MessageSeverity.Warning );
			}
			return finalValue;
		}

		//public override void ReadFromString( ref string[] nodeParams )
		//{
		//	base.ReadFromString( ref nodeParams );

			// Removed on version 5004
			//m_value = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
		//}

		//public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
		//{
		//	base.WriteToString( ref nodeInfo, ref connectionsInfo );
		//}

	}
}