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.

56 lines
1.5 KiB

  1. using UnityEngine;
  2. namespace AmplifyShaderEditor
  3. {
  4. public class NodeWireReferencesUtils
  5. {
  6. public WireReference InputPortReference = new WireReference();
  7. public WireReference SwitchPortReference = new WireReference();
  8. public WireReference OutputPortReference = new WireReference();
  9. public Vector2 SnapPosition = Vector2.zero;
  10. public bool SnapEnabled = false;
  11. public WireReference SnapPort = new WireReference();
  12. public bool ValidReferences()
  13. {
  14. return ( InputPortReference.IsValid || OutputPortReference.IsValid );
  15. }
  16. public void InvalidateReferences()
  17. {
  18. InputPortReference.Invalidate();
  19. OutputPortReference.Invalidate();
  20. SnapPort.Invalidate();
  21. SnapEnabled = false;
  22. }
  23. public void SetOutputReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked )
  24. {
  25. if( InputPortReference.IsValid )
  26. InputPortReference.Invalidate();
  27. OutputPortReference.SetReference( nodeId, portId, dataType, typeLocked );
  28. }
  29. public void SetInputReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked )
  30. {
  31. if( OutputPortReference.IsValid )
  32. OutputPortReference.Invalidate();
  33. InputPortReference.SetReference( nodeId, portId, dataType, typeLocked );
  34. }
  35. public void ActivateSnap( Vector2 position, WirePort port )
  36. {
  37. SnapPort.SetReference( port );
  38. SnapEnabled = true;
  39. SnapPosition = position;
  40. }
  41. public void DeactivateSnap()
  42. {
  43. SnapEnabled = false;
  44. SnapPort.Invalidate();
  45. }
  46. }
  47. }