using System; using System.Collections.Generic; using TNode.TNodeCore.Editor.Models; using TNodeCore.Editor.Models; using UnityEditor; using UnityEngine; 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 ; [SerializeReference] protected GraphViewData graphViewData; public List EditorModels{ get{ return editorModels ??= new List(); } set => editorModels = value; } public GraphViewData GraphViewData{ get{ return graphViewData ??= new GraphViewData(); } set => graphViewData = value; } #endif } }