using System; using System.Collections.Generic; using TNode.TNodeCore.Editor.Models; using UnityEditor; using UnityEngine; using UnityEngine.Serialization; namespace TNodeCore.Runtime.Models{ [Serializable] public class GraphData:ScriptableObject,ISerializationCallbackReceiver{ [NonSerialized] public Dictionary NodeDictionary = new Dictionary(); [SerializeReference] public List nodeList = new List(); [SerializeField] protected List nodeLinks; [SerializeReference] public BlackboardData blackboardData; [HideInInspector] public string sceneReference; public List NodeLinks{ get{ return nodeLinks ??= new List(); } set => nodeLinks = value; } public void OnBeforeSerialize(){ nodeList.Clear(); foreach(var node in NodeDictionary.Values){ nodeList.Add(node); } } public void OnAfterDeserialize(){ NodeDictionary.Clear(); foreach(var node in nodeList){ NodeDictionary.Add(node.id,node); } } #if UNITY_EDITOR [SerializeReference] protected List editorModels ; [FormerlySerializedAs("graphViewData")] [SerializeReference] protected GraphViewModel graphViewModel; public List EditorModels{ get{ return editorModels ??= new List(); } set => editorModels = value; } public GraphViewModel GraphViewModel{ get{ return graphViewModel ??= new GraphViewModel(); } set => graphViewModel = value; } #endif } }