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.

76 lines
1.9 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. using System;
  6. namespace AmplifyShaderEditor
  7. {
  8. public class VariablePortTypeOpNode : ParentNode
  9. {
  10. private const string InputTypeStr = "Input type";
  11. [SerializeField]
  12. protected WirePortDataType m_selectedType = WirePortDataType.FLOAT;
  13. [SerializeField]
  14. protected WirePortDataType m_lastSelectedType = WirePortDataType.FLOAT;
  15. [SerializeField]
  16. protected int _inputAmount = 1;
  17. protected override void CommonInit( int uniqueId )
  18. {
  19. base.CommonInit( uniqueId );
  20. AddPorts();
  21. }
  22. void AddPorts()
  23. {
  24. for ( int i = 0; i < _inputAmount; i++ )
  25. {
  26. AddInputPort( m_selectedType, true, i.ToString() );
  27. }
  28. AddOutputPort( m_selectedType, Constants.EmptyPortValue );
  29. m_sizeIsDirty = true;
  30. }
  31. public override void DrawProperties()
  32. {
  33. base.DrawProperties();
  34. EditorGUILayout.BeginVertical();
  35. {
  36. EditorGUILayout.LabelField( InputTypeStr );
  37. m_selectedType = ( WirePortDataType ) EditorGUILayoutEnumPopup( m_selectedType );
  38. }
  39. EditorGUILayout.EndVertical();
  40. if ( m_selectedType != m_lastSelectedType )
  41. {
  42. m_lastSelectedType = m_selectedType;
  43. DeleteAllInputConnections( true );
  44. DeleteAllOutputConnections( true );
  45. AddPorts();
  46. }
  47. }
  48. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  49. {
  50. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  51. IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType );
  52. }
  53. public override void ReadFromString( ref string[] nodeParams )
  54. {
  55. base.ReadFromString( ref nodeParams );
  56. m_selectedType = ( WirePortDataType ) Enum.Parse( typeof( WirePortDataType ), GetCurrentParam( ref nodeParams ) );
  57. m_lastSelectedType = m_selectedType;
  58. DeleteAllInputConnections( true );
  59. DeleteAllOutputConnections( true );
  60. AddPorts();
  61. }
  62. }
  63. }