//$ Copyright 2015-22, Code Respawn Technologies Pvt Ltd - All Rights Reserved $// using UnityEngine; namespace DungeonArchitect.Graphs { /// /// A graph link is a directional connection between two graph nodes /// [System.Serializable] public class GraphLink : ScriptableObject { [SerializeField] int id; /// /// The ID of the link /// public int Id { get { return id; } set { id = value; UpdateName(); } } [SerializeField] GraphPin input; /// /// The input pin this link originates from /// public GraphPin Input { get { return input; } set { input = value; } } [SerializeField] GraphPin output; /// /// The output pin this link points to /// public GraphPin Output { get { return output; } set { output = value; } } [SerializeField] Graph graph; /// /// The graph this link belongs to /// public Graph Graph { get { return graph; } set { graph = value; } } public void OnEnable() { hideFlags = HideFlags.HideInHierarchy; UpdateName(); } void UpdateName() { this.name = "Link_" + id; } /// /// Determines the spring strength of the link. /// It reduces as it gets smaller to draw good looking link at any distance /// /// public float GetTangentStrength() { var distance = (output.WorldPosition - input.WorldPosition).magnitude; var tangentStrength = Mathf.Min(output.TangentStrength, distance / 2.0f); return tangentStrength; } } }