using System.Collections.Generic; using UnityEngine; namespace FIMSpace.Graph { [System.Serializable] /// Connection between whole nodes, NOT between node ports! public class FGraph_TriggerNodeConnection /*: ScriptableObject*/ { /// Node ID public int ConnectionFromID = -1; /// Node ID public int ConnectionToID = -1; /// Can be used to support multiple connections public int ConnectionFrom_AlternativeID = -1; public int ConnectionTo_AlternativeID = -1; /// Can be used for displaying debugging progress on node from 0 to 1 for example public float DebuggingProgress { get; set; } = -1f; /// Assigning nodes references basing on the IDs public void RefreshReferences(List allNodes) where T : FGraph_NodeBase { if (allNodes == null) return; From = null; To = null; for (int i = allNodes.Count - 1; i >= 0; i--) { if (allNodes[i].IndividualID == ConnectionFromID) { if (allNodes[i].IndividualID != -1) From = allNodes[i]; } else if (allNodes[i].IndividualID == ConnectionToID) { if (allNodes[i].IndividualID != -1) To = allNodes[i]; } } } private FGraph_NodeBase ifrom = null; public FGraph_NodeBase From { get { if (ifrom == null) return null; else return ifrom; } set { ifrom = value; if (ifrom != null) { ConnectionFromID = ifrom.IndividualID; } } } private FGraph_NodeBase ito = null; public FGraph_NodeBase To { get { if (ito == null) return null; else return ito; } set { ito = value; if (ito != null) ConnectionToID = ito.IndividualID; } } /// Can be used to compute graph execution flow public bool Computing { get; set; } = false; public bool Launched { get; set; } = false; public FGraph_NodeBase GetOther(FGraph_NodeBase otherThan) { if (From == otherThan) return To; else return From; } public bool IsConnectedWith(FGraph_NodeBase otherNode) { if (From == otherNode) return true; if (To == otherNode) return true; return false; } } }