Esempio n. 1
0
        ///----------------------------------------------------------------------------------------------

        ///Self Serialize blackboard
        public void SelfSerialize()
        {
            if (haltForUndo /*|| ParadoxNotion.Services.Threader.applicationIsPlaying || Application.isPlaying*/)
            {
                return;
            }

            var newReferences    = new List <UnityEngine.Object>();
            var newSerialization = JSONSerializer.Serialize(typeof(BlackboardSource), _blackboard, newReferences);

            if (newSerialization != _serializedBlackboard || !newReferences.SequenceEqual(_objectReferences) || (_serializedVariables == null || _serializedVariables.Length != _blackboard.variables.Count))
            {
                haltForUndo = true;
                UndoUtility.RecordObjectComplete(this, UndoUtility.GetLastOperationNameOr("Blackboard Change"));
                haltForUndo = false;

                _serializedVariables = new SerializationPair[_blackboard.variables.Count];
                for (var i = 0; i < _blackboard.variables.Count; i++)
                {
                    var serializedVariable = new SerializationPair();
                    serializedVariable._json = JSONSerializer.Serialize(typeof(Variable), _blackboard.variables.ElementAt(i).Value, serializedVariable._references);
                    _serializedVariables[i]  = serializedVariable;
                }

                _serializedBlackboard = newSerialization;
                _objectReferences     = newReferences;
            }
        }
Esempio n. 2
0
 public KnownSerializers(IEventSerializer eventSerializer, IEventDeserializer eventDeserializer,
                         ISnapshotSerializer snapshotSerializer, ISnapshotDeserializer snapshotDeserializer)
 {
     Events    = new SerializationPair <IEventSerializer, IEventDeserializer>(eventSerializer, eventDeserializer);
     Snapshots = new SerializationPair <ISnapshotSerializer, ISnapshotDeserializer>(snapshotSerializer,
                                                                                    snapshotDeserializer);
 }
Esempio n. 3
0
 public T Deserialize <T>(JsonValue json, JsonSerializer serializer)
 {
     if (json.Type == JsonValueType.Object)
     {
         var jsonObj = json.Object;
         SerializationPair pair;
         if (jsonObj.ContainsKey(Constants.DefKey))
         {
             var guid = new Guid(jsonObj[Constants.DefKey].String);
             jsonObj.Remove(Constants.DefKey);
             pair = new SerializationPair {
                 Json = json
             };
             serializer.SerializationMap.Add(guid, pair);
             serializer.SerializationMap.Update(pair, _innerSerializer.Deserialize <T>(json, serializer));
             pair.DeserializationIsComplete = true;
             pair.Reconcile();
             return((T)pair.Object);
         }
         if (jsonObj.ContainsKey(Constants.RefKey))
         {
             var guid = new Guid(jsonObj[Constants.RefKey].String);
             pair = serializer.SerializationMap[guid];
             return((T)pair.Object);
         }
     }
     return(_innerSerializer.Deserialize <T>(json, serializer));
 }
 public JsonValue Serialize <T>(T obj, JsonSerializer serializer)
 {
     if (serializer.SerializationMap.TryGetPair(obj, out var guid, out var pair))
     {
         pair.UsageCount++;
         return(new JsonObject {
             { Constants.RefKey, guid.ToString() }
         });
     }
     if (_innerSerializer.ShouldMaintainReferences)
     {
         guid = Guid.NewGuid();
         pair = new SerializationPair {
             Object = obj
         };
         serializer.SerializationMap.Add(guid, pair);
         pair.Json = _innerSerializer.Serialize(obj, serializer);
         if (pair.UsageCount != 0)
         {
             pair.Json.Object.Add(Constants.DefKey, guid.ToString());
         }
         return(pair.Json);
     }
     return(_innerSerializer.Serialize(obj, serializer));
 }
Esempio n. 5
0
 //serialize exposed parameters
 void ISerializationCallbackReceiver.OnBeforeSerialize()
 {
     if (exposedParameters == null || exposedParameters.Count == 0)
     {
         _serializedExposedParameters = null;
         return;
     }
     _serializedExposedParameters = new SerializationPair[exposedParameters.Count];
     for (var i = 0; i < _serializedExposedParameters.Length; i++)
     {
         var serializedParam = new SerializationPair();
         serializedParam._json           = JSONSerializer.Serialize(typeof(ExposedParameter), exposedParameters[i], serializedParam._references);
         _serializedExposedParameters[i] = serializedParam;
     }
 }