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.

126 lines
2.5 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. namespace AmplifyShaderEditor
  6. {
  7. public enum WireStatus
  8. {
  9. Default = 0,
  10. Highlighted,
  11. Selected
  12. }
  13. [Serializable]
  14. public sealed class WireReference
  15. {
  16. private WireStatus m_status = WireStatus.Default;
  17. [SerializeField]
  18. private int m_nodeId = -1;
  19. [SerializeField]
  20. private int m_portId = -1;
  21. [SerializeField]
  22. private WirePortDataType m_dataType = WirePortDataType.FLOAT;
  23. [SerializeField]
  24. private bool m_typeLocked = false;
  25. public WireReference()
  26. {
  27. m_nodeId = -1;
  28. m_portId = -1;
  29. m_dataType = WirePortDataType.FLOAT;
  30. m_typeLocked = false;
  31. m_status = WireStatus.Default;
  32. }
  33. public WireReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked )
  34. {
  35. m_portId = portId;
  36. m_nodeId = nodeId;
  37. m_dataType = dataType;
  38. m_typeLocked = typeLocked;
  39. m_status = WireStatus.Default;
  40. }
  41. public void Invalidate()
  42. {
  43. m_nodeId = -1;
  44. m_portId = -1;
  45. m_typeLocked = false;
  46. m_status = WireStatus.Default;
  47. }
  48. public void SetReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked )
  49. {
  50. m_nodeId = nodeId;
  51. m_portId = portId;
  52. m_dataType = dataType;
  53. m_typeLocked = typeLocked;
  54. }
  55. public void SetReference( WirePort port )
  56. {
  57. m_nodeId = port.NodeId;
  58. m_portId = port.PortId;
  59. m_dataType = port.DataType;
  60. }
  61. public bool IsValid
  62. {
  63. get { return ( m_nodeId != -1 && m_portId != -1 ); }
  64. }
  65. public int NodeId
  66. {
  67. get { return m_nodeId; }
  68. }
  69. public int PortId
  70. {
  71. get { return m_portId; }
  72. set { m_portId = value; }
  73. }
  74. public WirePortDataType DataType
  75. {
  76. get { return m_dataType; }
  77. set { m_dataType = value; }
  78. }
  79. public bool TypeLocked
  80. {
  81. get { return m_typeLocked; }
  82. }
  83. public WireStatus WireStatus
  84. {
  85. get { return m_status; }
  86. set { m_status = value; }
  87. }
  88. public override string ToString()
  89. {
  90. string dump = "";
  91. dump += "* Wire Reference *\n";
  92. dump += "NodeId : " + m_nodeId + "\n";
  93. dump += "PortId : " + m_portId + "\n";
  94. dump += "DataType " + m_dataType + "\n"; ;
  95. return dump;
  96. }
  97. public void WriteToString( ref string myString )
  98. {
  99. IOUtils.AddFieldToString( ref myString, "PortId", m_portId );
  100. IOUtils.AddFieldToString( ref myString, "NodeID", m_nodeId );
  101. IOUtils.AddFieldToString( ref myString, "DataType", m_dataType );
  102. IOUtils.AddFieldToString( ref myString, "TypeLocked", m_typeLocked );
  103. }
  104. }
  105. }