예제 #1
0
        //Construct
        public GraphSerializationData(Graph graph)
        {
            this.version         = SerializationVersion;
            this.type            = graph.GetType();
            this.name            = graph.name;
            this.comments        = graph.graphComments;
            this.translation     = graph.translation;
            this.zoomFactor      = graph.zoomFactor;
            this.nodes           = graph.allNodes;
            this.canvasGroups    = graph.canvasGroups;
            this.localBlackboard = graph.localBlackboard;

            var structConnections = new List<Connection>();
            for (var i = 0; i < nodes.Count; i++){
                if (nodes[i] is ISerializationCallbackReceiver){
                    (nodes[i] as ISerializationCallbackReceiver).OnBeforeSerialize();
                }

                for (var j = 0; j < nodes[i].outConnections.Count; j++){
                    structConnections.Add(nodes[i].outConnections[j]);
                }
            }

            this.connections = structConnections;
            this.primeNode   = graph.primeNode;
        }
        ///Loads the GraphSerializationData
        bool LoadGraphData(GraphSerializationData data, bool validate)
        {
            if (data == null)
            {
                Logger.LogError("Can't Load graph, cause of null GraphSerializationData provided", "Serialization", this);
                return(false);
            }

            if (data.type != this.GetType())
            {
                Logger.LogError("Can't Load graph, cause of different Graph type serialized and required", "Serialization", this);
                return(false);
            }

            data.Reconstruct(this);

            //grab the final data and set fields directly
            this._category        = data.category;
            this._comments        = data.comments;
            this._translation     = data.translation;
            this._zoomFactor      = data.zoomFactor;
            this._nodes           = data.nodes;
            this._primeNode       = data.primeNode;
            this._canvasGroups    = data.canvasGroups;
            this._localBlackboard = data.localBlackboard;

            //IMPORTANT: Validate should be called in all deserialize cases outside of Unity's 'OnAfterDeserialize',
            //like for example when loading from json, or manualy calling this outside of OnAfterDeserialize.
            if (validate)
            {
                Validate();
            }

            return(true);
        }
예제 #3
0
 void SelfDeserialize()
 {
     _blackboard = JSONSerializer.Deserialize <BlackboardSource>(_serializedBlackboard, _objectReferences);
     if (_blackboard == null)
     {
         _blackboard = new BlackboardSource();
     }
 }
 //deserialize blackboard variables from json
 public void OnAfterDeserialize()
 {
     _blackboard = JSON.Deserialize <BlackboardSource>(_serializedBlackboard, _objectReferences);
     if (_blackboard == null)
     {
         _blackboard = new BlackboardSource();
     }
 }
예제 #5
0
 //deserialize blackboard variables from json
 public void OnAfterDeserialize()
 {
     if (hasDeserialized && JSONSerializer.applicationPlaying)
     {
         return;                                                                   //avoid double call that Unity does (bug?)
     }
     hasDeserialized = true;
     _blackboard     = JSONSerializer.Deserialize <BlackboardSource>(_serializedBlackboard, _objectReferences);
     if (_blackboard == null)
     {
         _blackboard = new BlackboardSource();
     }
 }
예제 #6
0
 //deserialize blackboard variables from json
 void ISerializationCallbackReceiver.OnAfterDeserialize()
 {
     if (hasDeserialized && JSONSerializer.applicationPlaying)
     {
         return;
     }
     hasDeserialized = true;
     _blackboard     = JSONSerializer.Deserialize <BlackboardSource>(_serializedBlackboard, _objectReferences);
     if (_blackboard == null)
     {
         _blackboard = new BlackboardSource();
     }
 }
        ///Loads back the Blackboard from PlayerPrefs of the provided saveKey. You can use this for a Save system
        public bool Load(string saveKey)
        {
            var dataString = PlayerPrefs.GetString(saveKey);

            if (string.IsNullOrEmpty(dataString))
            {
                Debug.Log("No data to load");
                return(false);
            }

            _blackboard = JSON.Deserialize <BlackboardSource>(dataString, _objectReferences);
            _blackboard.InitializePropertiesBinding(propertiesBindTarget, true);
            return(true);
        }
예제 #8
0
 //Deserialize the local blackboard of the graph
 public bool DeserializeLocalBlackboard(string json)
 {
     try
     {
         _localBlackboard = JSONSerializer.Deserialize <BlackboardSource>(json, _objectReferences);
         if (_localBlackboard == null)
         {
             _localBlackboard = new BlackboardSource();
         }
         return(true);
     }
     catch (System.Exception e)
     {
         Debug.LogError(string.Format("Deserialization Error: '{0}'\n'{1}'\n\n<b>Please report bug</b>", e.Message, e.StackTrace), this);
         return(false);
     }
 }
예제 #9
0
 ///Deserialize the local blackboard of the graph alone
 public bool DeserializeLocalBlackboard(string json)
 {
     try
     {
         _localBlackboard = JSONSerializer.Deserialize <BlackboardSource>(json, _objectReferences);
         if (_localBlackboard == null)
         {
             _localBlackboard = new BlackboardSource();
         }
         return(true);
     }
     catch (System.Exception e)
     {
         Debug.LogError(string.Format("<b>(Deserialization Error:)</b> {0}", e.ToString()), this);
         return(false);
     }
 }
예제 #10
0
 ///Deserialize the local blackboard of the graph alone
 public bool DeserializeLocalBlackboard(string json)
 {
     try
     {
         _localBlackboard = JSONSerializer.Deserialize <BlackboardSource>(json, _objectReferences);
         if (_localBlackboard == null)
         {
             _localBlackboard = new BlackboardSource();
         }
         return(true);
     }
     catch (System.Exception e)
     {
         ParadoxNotion.Services.Logger.LogException(e, "Serialization", this);
         return(false);
     }
 }
예제 #11
0
 //Deserialize the local blackboard of the graph
 public bool DeserializeLocalBlackboard(string json)
 {
     try
     {
         _localBlackboard = JSONSerializer.Deserialize <BlackboardSource>(json, _objectReferences);
         if (_localBlackboard == null)
         {
             _localBlackboard = new BlackboardSource();
         }
         if (useLocalBlackboard)
         {
             blackboard = _localBlackboard;
         }
         return(true);
     }
     catch { return(false); }
 }
예제 #12
0
        ///Self Deserialize blackboard
        public void SelfDeserialize()
        {
            _blackboard = new BlackboardSource();
            if (!string.IsNullOrEmpty(_serializedBlackboard) /*&& ( _serializedVariables == null || _serializedVariables.Length == 0 )*/)
            {
                JSONSerializer.TryDeserializeOverwrite <BlackboardSource>(_blackboard, _serializedBlackboard, _objectReferences);
            }

            //this is to handle prefab overrides
            if (_serializedVariables != null && _serializedVariables.Length > 0)
            {
                _blackboard.variables.Clear();
                for (var i = 0; i < _serializedVariables.Length; i++)
                {
                    var variable = JSONSerializer.Deserialize <Variable>(_serializedVariables[i]._json, _serializedVariables[i]._references);
                    _blackboard.variables[variable.name] = variable;
                }
            }
        }