public void OnAfterDeserialize()
 {
     if (!string.IsNullOrEmpty(_serializedGraph))
     {
         Graph = GraphSerializer.Deserialize(_serializedGraph);
     }
 }
 public void OnBeforeSerialize()
 {
     if (Graph != null)
     {
         _serializedGraph = GraphSerializer.Serialize(Graph);
     }
 }
        /// <summary>
        /// Loads graph from given asset guid
        /// </summary>
        /// <param name="graphAssetGuid">Guid of a <see cref="GraphAsset"/></param>
        public void LoadGraph(string graphAssetGuid)
        {
            _graphAssetGuid        = graphAssetGuid;
            _graph                 = GraphSerializer.DeserializeSGraphFromGuid(_graphAssetGuid);
            _graphEditorView.Graph = _graph;

            SetWindowTitle();
        }
        private string SerializeGraphElements(IEnumerable <GraphElement> elements)
        {
            var nodes       = elements.OfType <BaseNodeView>().ToDictionary(node => node.Node.Id, node => node);
            var connections = elements.OfType <BaseConnectionView>().Where(view => nodes.ContainsKey(view.Connection.FromNodeId) &&
                                                                           nodes.ContainsKey(view.Connection.ToNodeId));

            return(GraphSerializer.Serialize(CreateGraphToSerialize(nodes.Values, connections)));
        }
        private void LoadSerializedGraph()
        {
            _graph = GraphSerializer.DeserializeSGraph(_serializedGraph);
            _graphEditorView.Graph = _graph;
            _serializedGraph       = string.Empty;

            SetWindowTitle();
        }
Exemple #6
0
            public override void Action(int instanceId, string pathName, string resourceFile)
            {
                File.WriteAllText(pathName, GraphSerializer.Serialize(Graph));
                AssetDatabase.Refresh();

                UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <GraphAsset>(pathName);
                Selection.activeObject = obj;
            }
 private bool CanPasteSerializedData(string data)
 {
     try
     {
         return(GraphSerializer.DeserializeSGraph(data) != null);
     }
     catch
     {
         return(false);
     }
 }
Exemple #8
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var textGraph = File.ReadAllText(ctx.assetPath, Encoding.UTF8);

            var graph = GraphSerializer.Deserialize(textGraph);

            var graphAsset = GraphAsset.Create(graph);

            ctx.AddObjectToAsset("MainAsset", graphAsset);
            ctx.SetMainObject(graphAsset);
        }
        /// <summary>
        /// Saves current <see cref="GraphAsset"/>
        /// </summary>
        public void SaveGraph()
        {
            if (_graphAssetGuid != null && _graph != null)
            {
                var path = AssetDatabase.GUIDToAssetPath(_graphAssetGuid);

                if (!string.IsNullOrEmpty(path))
                {
                    File.WriteAllText(path, GraphSerializer.Serialize(_graph));
                }
            }
        }
        /// <summary>
        /// Executes graph given its asset guid. May be called only from editor.
        /// </summary>
        /// <typeparam name="TArgs">Additional arguments type</typeparam>
        /// <param name="assetGuid"><see cref="AssetDatabase"/> GUID of a graph to execute</param>
        /// <param name="args">Additional arguments for the executor</param>
        /// <returns>Execution result</returns>
        public static Task <IGraphExecutionResult> ExecuteGraphAssetAsync <TArgs>(string assetGuid, TArgs args)
        {
            if (assetGuid == null)
            {
                throw new ArgumentNullException(nameof(assetGuid));
            }

#if UNITY_EDITOR
            var graph = GraphSerializer.DeserializeFromGuid(assetGuid);
            return(ExecuteGraphAsync(graph, args));
#else
            throw new InvalidOperationException($"{nameof(ExecuteGraphAsset)} may be called only from editor");
#endif
        }
        private void PasteNewNodes(string rawData)
        {
            SGraph graph = GraphSerializer.DeserializeSGraph(rawData);

            GenerateNewNodeIds(graph);
            UpdateNodesPosition(graph);

            foreach (var node in graph.Nodes)
            {
                _graphView.Graph.AddNode(node);
            }

            foreach (var connection in graph.Connections)
            {
                _graphView.Graph.AddConnection(connection);
            }
        }