first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5164d470a6e38764b8d45186ceffdd52
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,261 @@
|
||||
//Adapted from Robert Penner equations
|
||||
|
||||
namespace ParadoxNotion.Animation
|
||||
{
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public enum EaseType
|
||||
{
|
||||
Linear,
|
||||
QuadraticIn,
|
||||
QuadraticOut,
|
||||
QuadraticInOut,
|
||||
QuarticIn,
|
||||
QuarticOut,
|
||||
QuarticInOut,
|
||||
QuinticIn,
|
||||
QuinticOut,
|
||||
QuinticInOut,
|
||||
CubicIn,
|
||||
CubicOut,
|
||||
CubicInOut,
|
||||
ExponentialIn,
|
||||
ExponentialOut,
|
||||
ExponentialInOut,
|
||||
CircularIn,
|
||||
CircularOut,
|
||||
CircularInOut,
|
||||
SinusoidalIn,
|
||||
SinusoidalOut,
|
||||
SinusoidalInOut,
|
||||
ElasticIn,
|
||||
ElasticOut,
|
||||
ElasticInOut,
|
||||
BounceIn,
|
||||
BounceOut,
|
||||
BounceInOut,
|
||||
BackIn,
|
||||
BackOut,
|
||||
BackInOut
|
||||
}
|
||||
|
||||
///<summary>Easing functions to be used for interpolation</summary>
|
||||
public static class Easing
|
||||
{
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
public static float Ease(EaseType type, float from, float to, float t) {
|
||||
if ( t <= 0 ) { return from; }
|
||||
if ( t >= 1 ) { return to; }
|
||||
return Mathf.LerpUnclamped(from, to, Function(type)(t));
|
||||
}
|
||||
|
||||
public static Vector3 Ease(EaseType type, Vector3 from, Vector3 to, float t) {
|
||||
if ( t <= 0 ) { return from; }
|
||||
if ( t >= 1 ) { return to; }
|
||||
return Vector3.LerpUnclamped(from, to, Function(type)(t));
|
||||
}
|
||||
|
||||
public static Quaternion Ease(EaseType type, Quaternion from, Quaternion to, float t) {
|
||||
if ( t <= 0 ) { return from; }
|
||||
if ( t >= 1 ) { return to; }
|
||||
return Quaternion.LerpUnclamped(from, to, Function(type)(t));
|
||||
}
|
||||
|
||||
public static Color Ease(EaseType type, Color from, Color to, float t) {
|
||||
if ( t <= 0 ) { return from; }
|
||||
if ( t >= 1 ) { return to; }
|
||||
return Color.LerpUnclamped(from, to, Function(type)(t));
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
public static Func<float, float> Function(EaseType type) {
|
||||
switch ( type ) {
|
||||
case EaseType.Linear: return Linear;
|
||||
case EaseType.QuadraticIn: return QuadraticIn;
|
||||
case EaseType.QuadraticOut: return QuadraticOut;
|
||||
case EaseType.QuadraticInOut: return QuadraticInOut;
|
||||
case EaseType.QuarticIn: return QuarticIn;
|
||||
case EaseType.QuarticOut: return QuarticOut;
|
||||
case EaseType.QuarticInOut: return QuarticInOut;
|
||||
case EaseType.QuinticIn: return QuinticIn;
|
||||
case EaseType.QuinticOut: return QuinticOut;
|
||||
case EaseType.QuinticInOut: return QuinticInOut;
|
||||
case EaseType.CubicIn: return CubicIn;
|
||||
case EaseType.CubicOut: return CubicOut;
|
||||
case EaseType.CubicInOut: return CubicInOut;
|
||||
case EaseType.ExponentialIn: return ExponentialIn;
|
||||
case EaseType.ExponentialOut: return ExponentialOut;
|
||||
case EaseType.ExponentialInOut: return ExponentialInOut;
|
||||
case EaseType.CircularIn: return CircularIn;
|
||||
case EaseType.CircularOut: return CircularOut;
|
||||
case EaseType.CircularInOut: return CircularInOut;
|
||||
case EaseType.SinusoidalIn: return SinusoidalIn;
|
||||
case EaseType.SinusoidalOut: return SinusoidalOut;
|
||||
case EaseType.SinusoidalInOut: return SinusoidalInOut;
|
||||
case EaseType.ElasticIn: return ElasticIn;
|
||||
case EaseType.ElasticOut: return ElasticOut;
|
||||
case EaseType.ElasticInOut: return ElasticInOut;
|
||||
case EaseType.BounceIn: return BounceIn;
|
||||
case EaseType.BounceOut: return BounceOut;
|
||||
case EaseType.BounceInOut: return BounceInOut;
|
||||
case EaseType.BackIn: return BackIn;
|
||||
case EaseType.BackOut: return BackOut;
|
||||
case EaseType.BackInOut: return BackInOut;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
public static float Linear(float t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
public static float QuadraticIn(float t) {
|
||||
return t * t;
|
||||
}
|
||||
|
||||
public static float QuadraticOut(float t) {
|
||||
return 1f - ( 1f - t ) * ( 1f - t );
|
||||
}
|
||||
|
||||
public static float QuadraticInOut(float t) {
|
||||
return t < 0.5f ? 2f * t * t : 1f - Mathf.Pow(-2f * t + 2f, 2f) / 2f;
|
||||
}
|
||||
|
||||
public static float QuarticIn(float t) {
|
||||
return t * t * t * t;
|
||||
}
|
||||
|
||||
public static float QuarticOut(float t) {
|
||||
return 1f - ( --t * t * t * t );
|
||||
}
|
||||
|
||||
public static float QuarticInOut(float t) {
|
||||
if ( ( t *= 2f ) < 1f )
|
||||
return 0.5f * t * t * t * t;
|
||||
return -0.5f * ( ( t -= 2f ) * t * t * t - 2f );
|
||||
}
|
||||
|
||||
public static float QuinticIn(float t) {
|
||||
return t * t * t * t * t;
|
||||
}
|
||||
|
||||
public static float QuinticOut(float t) {
|
||||
return --t * t * t * t * t + 1f;
|
||||
}
|
||||
|
||||
public static float QuinticInOut(float t) {
|
||||
if ( ( t *= 2f ) < 1 )
|
||||
return 0.5f * t * t * t * t * t;
|
||||
return 0.5f * ( ( t -= 2f ) * t * t * t * t + 2f );
|
||||
}
|
||||
|
||||
public static float CubicIn(float t) {
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
public static float CubicOut(float t) {
|
||||
return --t * t * t + 1f;
|
||||
}
|
||||
|
||||
public static float CubicInOut(float t) {
|
||||
return t < 0.5 ? 4f * t * t * t : 1f - Mathf.Pow(-2f * t + 2f, 3f) / 2f;
|
||||
}
|
||||
|
||||
public static float SinusoidalIn(float t) {
|
||||
return 1f - Mathf.Cos(t * Mathf.PI / 2f);
|
||||
}
|
||||
|
||||
public static float SinusoidalOut(float t) {
|
||||
return Mathf.Sin(t * Mathf.PI / 2f);
|
||||
}
|
||||
|
||||
public static float SinusoidalInOut(float t) {
|
||||
return 0.5f * ( 1f - Mathf.Cos(Mathf.PI * t) );
|
||||
}
|
||||
|
||||
public static float ExponentialIn(float t) {
|
||||
return t == 0f ? 0f : Mathf.Pow(2f, 10f * t - 10f);
|
||||
}
|
||||
|
||||
public static float ExponentialOut(float t) {
|
||||
return t == 1f ? 1f : 1f - Mathf.Pow(2f, -10f * t);
|
||||
}
|
||||
|
||||
public static float ExponentialInOut(float t) {
|
||||
return t < 0.5f ? Mathf.Pow(2f, 20f * t - 10f) / 2f : ( 2f - Mathf.Pow(2f, -20f * t + 10f) ) / 2f;
|
||||
}
|
||||
|
||||
public static float CircularIn(float t) {
|
||||
return 1f - Mathf.Sqrt(1f - t * t);
|
||||
}
|
||||
|
||||
public static float CircularOut(float t) {
|
||||
return Mathf.Sqrt(1f - ( --t * t ));
|
||||
}
|
||||
|
||||
public static float CircularInOut(float t) {
|
||||
return t < 0.5f ? ( Mathf.Sqrt(1f - t * t) - 1f ) / 2 : ( Mathf.Sqrt(1f - ( t -= 2f ) * t) + 1f ) / 2;
|
||||
}
|
||||
|
||||
public static float ElasticIn(float t) {
|
||||
float x = ( 2f * Mathf.PI ) / 3f;
|
||||
return -Mathf.Pow(2f, 10f * t - 10f) * Mathf.Sin(( t * 10f - 10.75f ) * x);
|
||||
}
|
||||
|
||||
public static float ElasticOut(float t) {
|
||||
float x = ( 2f * Mathf.PI ) / 3f;
|
||||
return Mathf.Pow(2f, -10f * t) * Mathf.Sin(( t * 10f - 0.75f ) * x) + 1f;
|
||||
}
|
||||
|
||||
public static float ElasticInOut(float t) {
|
||||
float x = ( 2f * Mathf.PI ) / 4.5f;
|
||||
if ( t < 0.5f )
|
||||
return -( Mathf.Pow(2f, 20f * t - 10f) * Mathf.Sin(( 20f * t - 11.125f ) * x) ) / 2f;
|
||||
return ( Mathf.Pow(2f, -20f * t + 10f) * Mathf.Sin(( 20f * t - 11.125f ) * x) ) / 2f + 1f;
|
||||
}
|
||||
|
||||
public static float BounceIn(float t) {
|
||||
return 1f - BounceOut(1f - t);
|
||||
}
|
||||
|
||||
public static float BounceOut(float t) {
|
||||
if ( t < ( 1f / 2.75f ) ) {
|
||||
return 7.5625f * t * t;
|
||||
} else if ( t < ( 2f / 2.75f ) ) {
|
||||
return 7.5625f * ( t -= ( 1.5f / 2.75f ) ) * t + 0.75f;
|
||||
} else if ( t < ( 2.5f / 2.75f ) ) {
|
||||
return 7.5625f * ( t -= ( 2.25f / 2.75f ) ) * t + 0.9375f;
|
||||
} else {
|
||||
return 7.5625f * ( t -= ( 2.625f / 2.75f ) ) * t + 0.984375f;
|
||||
}
|
||||
}
|
||||
|
||||
public static float BounceInOut(float t) {
|
||||
return t < 0.5f ? BounceIn(t * 2f) * 0.5f : BounceOut(t * 2f - 1f) * 0.5f + 0.5f;
|
||||
}
|
||||
|
||||
public static float BackIn(float t) {
|
||||
float s = 1.70158f;
|
||||
return t * t * ( ( s + 1f ) * t - s );
|
||||
}
|
||||
|
||||
public static float BackOut(float t) {
|
||||
float s = 1.70158f;
|
||||
return --t * t * ( ( s + 1f ) * t + s ) + 1f;
|
||||
}
|
||||
|
||||
public static float BackInOut(float t) {
|
||||
float s = 1.70158f * 1.525f;
|
||||
if ( ( t *= 2f ) < 1f )
|
||||
return 0.5f * ( t * t * ( ( s + 1 ) * t - s ) );
|
||||
return 0.5f * ( ( t -= 2f ) * t * ( ( s + 1f ) * t + s ) + 2f );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb2ca6ca572280149964596d794ec706
|
||||
timeCreated: 1537185035
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Animation/Easing.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,24 @@
|
||||
//common generic delegates
|
||||
|
||||
namespace ParadoxNotion
|
||||
{
|
||||
public delegate void ActionCall();
|
||||
public delegate void ActionCall<T1>(T1 a);
|
||||
public delegate void ActionCall<T1, T2>(T1 a, T2 b);
|
||||
public delegate void ActionCall<T1, T2, T3>(T1 a, T2 b, T3 c);
|
||||
public delegate void ActionCall<T1, T2, T3, T4>(T1 a, T2 b, T3 c, T4 d);
|
||||
public delegate void ActionCall<T1, T2, T3, T4, T5>(T1 a, T2 b, T3 c, T4 d, T5 e);
|
||||
public delegate void ActionCall<T1, T2, T3, T4, T5, T6>(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f);
|
||||
public delegate void ActionCall<T1, T2, T3, T4, T5, T6, T7>(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g);
|
||||
public delegate void ActionCall<T1, T2, T3, T4, T5, T6, T7, T8>(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g, T8 h);
|
||||
|
||||
public delegate TResult FunctionCall<TResult>();
|
||||
public delegate TResult FunctionCall<T1, TResult>(T1 a);
|
||||
public delegate TResult FunctionCall<T1, T2, TResult>(T1 a, T2 b);
|
||||
public delegate TResult FunctionCall<T1, T2, T3, TResult>(T1 a, T2 b, T3 c);
|
||||
public delegate TResult FunctionCall<T1, T2, T3, T4, TResult>(T1 a, T2 b, T3 c, T4 d);
|
||||
public delegate TResult FunctionCall<T1, T2, T3, T4, T5, TResult>(T1 a, T2 b, T3 c, T4 d, T5 e);
|
||||
public delegate TResult FunctionCall<T1, T2, T3, T4, T5, T6, TResult>(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f);
|
||||
public delegate TResult FunctionCall<T1, T2, T3, T4, T5, T6, T7, TResult>(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g);
|
||||
public delegate TResult FunctionCall<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f, T7 g, T8 h);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea94db230ea657945a86990788542830
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Delegates.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion
|
||||
{
|
||||
|
||||
///<summary>Defines a dynamic (type-wise) parameter.</summary>
|
||||
[Serializable]
|
||||
sealed public class DynamicParameterDefinition : ISerializationCallbackReceiver
|
||||
{
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize() {
|
||||
if ( type != null ) { _type = type.FullName; }
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize() {
|
||||
type = ReflectionTools.GetType(_type, /*fallback?*/ true);
|
||||
}
|
||||
|
||||
[SerializeField] private string _ID;
|
||||
[SerializeField] private string _name;
|
||||
[SerializeField] private string _type;
|
||||
|
||||
//The ID of the definition
|
||||
public string ID {
|
||||
get
|
||||
{
|
||||
//for correct update prior versions
|
||||
if ( string.IsNullOrEmpty(_ID) ) { _ID = name; }
|
||||
return _ID;
|
||||
}
|
||||
private set { _ID = value; }
|
||||
}
|
||||
|
||||
//The name of the definition
|
||||
public string name {
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
///<summary>The Type of the definition</summary>
|
||||
public Type type { get; set; }
|
||||
|
||||
public DynamicParameterDefinition() { }
|
||||
public DynamicParameterDefinition(string name, Type type) {
|
||||
this.ID = Guid.NewGuid().ToString();
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f17f63b2bb18a3149a3e07f5f86b5f02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/DynamicParameterDefinition.cs
|
||||
uploadId: 704937
|
||||
117
Assets/Plugins/ParadoxNotion/CanvasCore/Common/Runtime/Enums.cs
Normal file
117
Assets/Plugins/ParadoxNotion/CanvasCore/Common/Runtime/Enums.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
namespace ParadoxNotion
|
||||
{
|
||||
|
||||
///<summary> Enumeration for comparisons</summary>
|
||||
public enum CompareMethod
|
||||
{
|
||||
EqualTo,
|
||||
GreaterThan,
|
||||
LessThan,
|
||||
GreaterOrEqualTo,
|
||||
LessOrEqualTo
|
||||
}
|
||||
|
||||
///<summary> Enumeration for Operations (Add, Subtract, Equality etc)</summary>
|
||||
public enum OperationMethod
|
||||
{
|
||||
Set,
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide
|
||||
}
|
||||
|
||||
///<summary> Enumeration for mouse button keys</summary>
|
||||
public enum ButtonKeys
|
||||
{
|
||||
Left = 0,
|
||||
Right = 1,
|
||||
Middle = 2
|
||||
}
|
||||
|
||||
///<summary> Enumeration for press types for inputs</summary>
|
||||
public enum PressTypes
|
||||
{
|
||||
Down,
|
||||
Up,
|
||||
Pressed
|
||||
}
|
||||
|
||||
///<summary> Enumeration for mouse press</summary>
|
||||
public enum MouseClickEvent
|
||||
{
|
||||
MouseDown = 0,
|
||||
MouseUp = 1
|
||||
}
|
||||
|
||||
///<summary> Enumeration for trigger unity events</summary>
|
||||
public enum TriggerTypes
|
||||
{
|
||||
TriggerEnter = 0,
|
||||
TriggerExit = 1,
|
||||
TriggerStay = 2
|
||||
}
|
||||
|
||||
///<summary> Enumeration for collision unity events</summary>
|
||||
public enum CollisionTypes
|
||||
{
|
||||
CollisionEnter = 0,
|
||||
CollisionExit = 1,
|
||||
CollisionStay = 2
|
||||
}
|
||||
|
||||
///<summary> Enumeration for mouse unity events</summary>
|
||||
public enum MouseInteractionTypes
|
||||
{
|
||||
MouseEnter = 0,
|
||||
MouseExit = 1,
|
||||
MouseOver = 2
|
||||
}
|
||||
|
||||
///<summary> Enumeration for boolean status result</summary>
|
||||
public enum CompactStatus
|
||||
{
|
||||
Failure = 0,
|
||||
Success = 1
|
||||
}
|
||||
|
||||
///<summary> Enumeration for Animation playing direction</summary>
|
||||
public enum PlayDirections
|
||||
{
|
||||
Forward,
|
||||
Backward,
|
||||
Toggle
|
||||
}
|
||||
|
||||
///<summary> Enumeration for planar direction</summary>
|
||||
public enum PlanarDirection
|
||||
{
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Auto
|
||||
}
|
||||
|
||||
///<summary> Enumeration Alignment 2x2</summary>
|
||||
public enum Alignment2x2
|
||||
{
|
||||
Default,
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom
|
||||
}
|
||||
|
||||
///<summary> Enumeration Alignment 3x3</summary>
|
||||
public enum Alignment3x3
|
||||
{
|
||||
TopLeft,
|
||||
TopCenter,
|
||||
TopRight,
|
||||
MiddleLeft,
|
||||
MiddleCenter,
|
||||
MiddleRight,
|
||||
BottomLeft,
|
||||
BottomCenter,
|
||||
BottomRight
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8edf60b49210fca4b84c66f4cdec0fc7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Enums.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,85 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ParadoxNotion
|
||||
{
|
||||
|
||||
///<summary>A simple general purpose hierarchical tree.</summary>
|
||||
public class HierarchyTree
|
||||
{
|
||||
//..with nothing inside right now
|
||||
|
||||
///<summary>A simple general purpose hierarchical tree element.</summary>
|
||||
public class Element
|
||||
{
|
||||
|
||||
private object _reference;
|
||||
private Element _parent;
|
||||
private List<Element> _children;
|
||||
|
||||
public object reference => _reference;
|
||||
public Element parent => _parent;
|
||||
public IEnumerable<Element> children => _children;
|
||||
|
||||
public Element(object reference) {
|
||||
this._reference = reference;
|
||||
}
|
||||
|
||||
///<summary>Add a child element</summary>
|
||||
public Element AddChild(Element child) {
|
||||
if ( _children == null ) { _children = new List<Element>(); }
|
||||
child._parent = this;
|
||||
_children.Add(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
///<summary>Remove a child element</summary>
|
||||
public void RemoveChild(Element child) {
|
||||
if ( _children != null ) {
|
||||
_children.Remove(child);
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Get root element</summary>
|
||||
public Element GetRoot() {
|
||||
var current = _parent;
|
||||
while ( current != null ) {
|
||||
current = current._parent;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
///<summary>Returns the first found Element that references target object</summary>
|
||||
public Element FindReferenceElement(object target) {
|
||||
if ( this._reference == target ) { return this; }
|
||||
if ( _children == null ) { return null; }
|
||||
for ( var i = 0; i < _children.Count; i++ ) {
|
||||
var sub = _children[i].FindReferenceElement(target);
|
||||
if ( sub != null ) {
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
///<summary>Get first parent reference of type T, including self element</summary>
|
||||
public T GetFirstParentReferenceOfType<T>() {
|
||||
if ( this._reference is T ) { return (T)_reference; }
|
||||
return _parent != null ? _parent.GetFirstParentReferenceOfType<T>() : default(T);
|
||||
}
|
||||
|
||||
///<summary>Get all children references of type T recursively</summary>
|
||||
public IEnumerable<T> GetAllChildrenReferencesOfType<T>() {
|
||||
if ( _children == null ) { yield break; }
|
||||
for ( var i = 0; i < _children.Count; i++ ) {
|
||||
var element = _children[i];
|
||||
if ( element._reference is T ) {
|
||||
yield return (T)element._reference;
|
||||
}
|
||||
foreach ( var deep in element.GetAllChildrenReferencesOfType<T>() ) {
|
||||
yield return deep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ce798a6776e2444ab1be31bb0fd9703
|
||||
timeCreated: 1537847297
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/HierarchyTree.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion
|
||||
{
|
||||
///<summary>Common interface between EventData and EventData<T></summary>
|
||||
public interface IEventData
|
||||
{
|
||||
GameObject receiver { get; }
|
||||
object sender { get; }
|
||||
object valueBoxed { get; }
|
||||
}
|
||||
|
||||
///<summary>Dispatched within EventRouter and contains data about the event</summary>
|
||||
public struct EventData : IEventData
|
||||
{
|
||||
public GameObject receiver { get; private set; }
|
||||
public object sender { get; private set; }
|
||||
public object value { get; private set; }
|
||||
public object valueBoxed => value;
|
||||
public EventData(object value, GameObject receiver, object sender) {
|
||||
this.value = value;
|
||||
this.receiver = receiver;
|
||||
this.sender = sender;
|
||||
}
|
||||
public EventData(GameObject receiver, object sender) {
|
||||
this.value = null;
|
||||
this.receiver = receiver;
|
||||
this.sender = sender;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Dispatched within EventRouter and contains data about the event</summary>
|
||||
public struct EventData<T> : IEventData
|
||||
{
|
||||
public GameObject receiver { get; private set; }
|
||||
public object sender { get; private set; }
|
||||
public T value { get; private set; }
|
||||
public object valueBoxed => value;
|
||||
public EventData(T value, GameObject receiver, object sender) {
|
||||
this.receiver = receiver;
|
||||
this.sender = sender;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4afd82dfa72065b448ec4d012da280f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/IEventData.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace ParadoxNotion
|
||||
{
|
||||
|
||||
///<summary> Has some prety common operations amongst values.</summary>
|
||||
public static class OperationTools
|
||||
{
|
||||
|
||||
|
||||
public static string GetOperationString(OperationMethod om) {
|
||||
|
||||
if ( om == OperationMethod.Set )
|
||||
return " = ";
|
||||
|
||||
if ( om == OperationMethod.Add )
|
||||
return " += ";
|
||||
|
||||
if ( om == OperationMethod.Subtract )
|
||||
return " -= ";
|
||||
|
||||
if ( om == OperationMethod.Multiply )
|
||||
return " *= ";
|
||||
|
||||
if ( om == OperationMethod.Divide )
|
||||
return " /= ";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static float Operate(float a, float b, OperationMethod om, float delta = 1f) {
|
||||
if ( om == OperationMethod.Set )
|
||||
return b;
|
||||
if ( om == OperationMethod.Add )
|
||||
return a + ( b * delta );
|
||||
if ( om == OperationMethod.Subtract )
|
||||
return a - ( b * delta );
|
||||
if ( om == OperationMethod.Multiply )
|
||||
return a * ( b * delta );
|
||||
if ( om == OperationMethod.Divide )
|
||||
return a / ( b * delta );
|
||||
return a;
|
||||
}
|
||||
|
||||
public static int Operate(int a, int b, OperationMethod om) {
|
||||
if ( om == OperationMethod.Set )
|
||||
return b;
|
||||
if ( om == OperationMethod.Add )
|
||||
return a + b;
|
||||
if ( om == OperationMethod.Subtract )
|
||||
return a - b;
|
||||
if ( om == OperationMethod.Multiply )
|
||||
return a * b;
|
||||
if ( om == OperationMethod.Divide )
|
||||
return a / b;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
public static Vector3 Operate(Vector3 a, Vector3 b, OperationMethod om, float delta = 1f) {
|
||||
if ( om == OperationMethod.Set )
|
||||
return b;
|
||||
if ( om == OperationMethod.Add )
|
||||
return a + ( b * delta );
|
||||
if ( om == OperationMethod.Subtract )
|
||||
return a - ( b * delta );
|
||||
if ( om == OperationMethod.Multiply )
|
||||
return Vector3.Scale(a, ( b * delta ));
|
||||
if ( om == OperationMethod.Divide ) {
|
||||
b *= delta;
|
||||
return new Vector3(( a ).x / ( b ).x, ( a ).y / ( b ).y, ( a ).z / ( b ).z);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public static string GetCompareString(CompareMethod cm) {
|
||||
|
||||
if ( cm == CompareMethod.EqualTo )
|
||||
return " == ";
|
||||
|
||||
if ( cm == CompareMethod.GreaterThan )
|
||||
return " > ";
|
||||
|
||||
if ( cm == CompareMethod.LessThan )
|
||||
return " < ";
|
||||
|
||||
if ( cm == CompareMethod.GreaterOrEqualTo )
|
||||
return " >= ";
|
||||
|
||||
if ( cm == CompareMethod.LessOrEqualTo )
|
||||
return " <= ";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static bool Compare(float a, float b, CompareMethod cm, float floatingPoint) {
|
||||
if ( cm == CompareMethod.EqualTo )
|
||||
return Mathf.Abs(a - b) <= floatingPoint;
|
||||
if ( cm == CompareMethod.GreaterThan )
|
||||
return a > b;
|
||||
if ( cm == CompareMethod.LessThan )
|
||||
return a < b;
|
||||
if ( cm == CompareMethod.GreaterOrEqualTo )
|
||||
return a >= b;
|
||||
if ( cm == CompareMethod.LessOrEqualTo )
|
||||
return a <= b;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Compare(int a, int b, CompareMethod cm) {
|
||||
if ( cm == CompareMethod.EqualTo )
|
||||
return a == b;
|
||||
if ( cm == CompareMethod.GreaterThan )
|
||||
return a > b;
|
||||
if ( cm == CompareMethod.LessThan )
|
||||
return a < b;
|
||||
if ( cm == CompareMethod.GreaterOrEqualTo )
|
||||
return a >= b;
|
||||
if ( cm == CompareMethod.LessOrEqualTo )
|
||||
return a <= b;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78f36360dab60254f9e297cfd18b7bf7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/OperationTools.cs
|
||||
uploadId: 704937
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b784f41bdb7345499543912922c873d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/ReflectionTools.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98e4103193f629f4188bc1831efae51b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization
|
||||
{
|
||||
public class DeserializeFromAttribute : Attribute
|
||||
{
|
||||
readonly public string previousTypeFullName;
|
||||
public DeserializeFromAttribute(string previousTypeFullName) {
|
||||
this.previousTypeFullName = previousTypeFullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08b3b1be3dd9c7b46b83e8993a8d969e
|
||||
timeCreated: 1438645389
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/DeserializeFromAttribute.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c9c2848912bd304a9e017cc2c70823c
|
||||
folderAsset: yes
|
||||
timeCreated: 1458918182
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c3453edd5a095d4a8d2ad6271ace429
|
||||
folderAsset: yes
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edb4a1e97c2095c49a690e92967ac921
|
||||
folderAsset: yes
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class AnimationCurve_DirectConverter : fsDirectConverter<AnimationCurve>
|
||||
{
|
||||
protected override fsResult DoSerialize(AnimationCurve model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "keys", model.keys);
|
||||
result += SerializeMember(serialized, null, "preWrapMode", model.preWrapMode);
|
||||
result += SerializeMember(serialized, null, "postWrapMode", model.postWrapMode);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref AnimationCurve model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.keys;
|
||||
result += DeserializeMember(data, null, "keys", out t0);
|
||||
model.keys = t0;
|
||||
|
||||
var t1 = model.preWrapMode;
|
||||
result += DeserializeMember(data, null, "preWrapMode", out t1);
|
||||
model.preWrapMode = t1;
|
||||
|
||||
var t2 = model.postWrapMode;
|
||||
result += DeserializeMember(data, null, "postWrapMode", out t2);
|
||||
model.postWrapMode = t2;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new AnimationCurve();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 884587fd81d5241449463b0aa2772803
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/AnimationCurve_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,38 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Bounds_DirectConverter : fsDirectConverter<Bounds>
|
||||
{
|
||||
protected override fsResult DoSerialize(Bounds model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "center", model.center);
|
||||
result += SerializeMember(serialized, null, "size", model.size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Bounds model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.center;
|
||||
result += DeserializeMember(data, null, "center", out t0);
|
||||
model.center = t0;
|
||||
|
||||
var t1 = model.size;
|
||||
result += DeserializeMember(data, null, "size", out t1);
|
||||
model.size = t1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Bounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a89e61419fe2a174cbc04e2fdfb7378c
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Bounds_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,38 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class GUIStyleState_DirectConverter : fsDirectConverter<GUIStyleState>
|
||||
{
|
||||
protected override fsResult DoSerialize(GUIStyleState model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "background", model.background);
|
||||
result += SerializeMember(serialized, null, "textColor", model.textColor);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref GUIStyleState model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.background;
|
||||
result += DeserializeMember(data, null, "background", out t0);
|
||||
model.background = t0;
|
||||
|
||||
var t2 = model.textColor;
|
||||
result += DeserializeMember(data, null, "textColor", out t2);
|
||||
model.textColor = t2;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new GUIStyleState();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 323d7ae8ade7f9140adadd06c728dc76
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/GUIStyleState_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,158 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class GUIStyle_DirectConverter : fsDirectConverter<GUIStyle>
|
||||
{
|
||||
protected override fsResult DoSerialize(GUIStyle model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "active", model.active);
|
||||
result += SerializeMember(serialized, null, "alignment", model.alignment);
|
||||
result += SerializeMember(serialized, null, "border", model.border);
|
||||
result += SerializeMember(serialized, null, "clipping", model.clipping);
|
||||
result += SerializeMember(serialized, null, "contentOffset", model.contentOffset);
|
||||
result += SerializeMember(serialized, null, "fixedHeight", model.fixedHeight);
|
||||
result += SerializeMember(serialized, null, "fixedWidth", model.fixedWidth);
|
||||
result += SerializeMember(serialized, null, "focused", model.focused);
|
||||
result += SerializeMember(serialized, null, "font", model.font);
|
||||
result += SerializeMember(serialized, null, "fontSize", model.fontSize);
|
||||
result += SerializeMember(serialized, null, "fontStyle", model.fontStyle);
|
||||
result += SerializeMember(serialized, null, "hover", model.hover);
|
||||
result += SerializeMember(serialized, null, "imagePosition", model.imagePosition);
|
||||
result += SerializeMember(serialized, null, "margin", model.margin);
|
||||
result += SerializeMember(serialized, null, "name", model.name);
|
||||
result += SerializeMember(serialized, null, "normal", model.normal);
|
||||
result += SerializeMember(serialized, null, "onActive", model.onActive);
|
||||
result += SerializeMember(serialized, null, "onFocused", model.onFocused);
|
||||
result += SerializeMember(serialized, null, "onHover", model.onHover);
|
||||
result += SerializeMember(serialized, null, "onNormal", model.onNormal);
|
||||
result += SerializeMember(serialized, null, "overflow", model.overflow);
|
||||
result += SerializeMember(serialized, null, "padding", model.padding);
|
||||
result += SerializeMember(serialized, null, "richText", model.richText);
|
||||
result += SerializeMember(serialized, null, "stretchHeight", model.stretchHeight);
|
||||
result += SerializeMember(serialized, null, "stretchWidth", model.stretchWidth);
|
||||
result += SerializeMember(serialized, null, "wordWrap", model.wordWrap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref GUIStyle model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.active;
|
||||
result += DeserializeMember(data, null, "active", out t0);
|
||||
model.active = t0;
|
||||
|
||||
var t2 = model.alignment;
|
||||
result += DeserializeMember(data, null, "alignment", out t2);
|
||||
model.alignment = t2;
|
||||
|
||||
var t3 = model.border;
|
||||
result += DeserializeMember(data, null, "border", out t3);
|
||||
model.border = t3;
|
||||
|
||||
var t4 = model.clipping;
|
||||
result += DeserializeMember(data, null, "clipping", out t4);
|
||||
model.clipping = t4;
|
||||
|
||||
var t5 = model.contentOffset;
|
||||
result += DeserializeMember(data, null, "contentOffset", out t5);
|
||||
model.contentOffset = t5;
|
||||
|
||||
var t6 = model.fixedHeight;
|
||||
result += DeserializeMember(data, null, "fixedHeight", out t6);
|
||||
model.fixedHeight = t6;
|
||||
|
||||
var t7 = model.fixedWidth;
|
||||
result += DeserializeMember(data, null, "fixedWidth", out t7);
|
||||
model.fixedWidth = t7;
|
||||
|
||||
var t8 = model.focused;
|
||||
result += DeserializeMember(data, null, "focused", out t8);
|
||||
model.focused = t8;
|
||||
|
||||
var t9 = model.font;
|
||||
result += DeserializeMember(data, null, "font", out t9);
|
||||
model.font = t9;
|
||||
|
||||
var t10 = model.fontSize;
|
||||
result += DeserializeMember(data, null, "fontSize", out t10);
|
||||
model.fontSize = t10;
|
||||
|
||||
var t11 = model.fontStyle;
|
||||
result += DeserializeMember(data, null, "fontStyle", out t11);
|
||||
model.fontStyle = t11;
|
||||
|
||||
var t12 = model.hover;
|
||||
result += DeserializeMember(data, null, "hover", out t12);
|
||||
model.hover = t12;
|
||||
|
||||
var t13 = model.imagePosition;
|
||||
result += DeserializeMember(data, null, "imagePosition", out t13);
|
||||
model.imagePosition = t13;
|
||||
|
||||
var t16 = model.margin;
|
||||
result += DeserializeMember(data, null, "margin", out t16);
|
||||
model.margin = t16;
|
||||
|
||||
var t17 = model.name;
|
||||
result += DeserializeMember(data, null, "name", out t17);
|
||||
model.name = t17;
|
||||
|
||||
var t18 = model.normal;
|
||||
result += DeserializeMember(data, null, "normal", out t18);
|
||||
model.normal = t18;
|
||||
|
||||
var t19 = model.onActive;
|
||||
result += DeserializeMember(data, null, "onActive", out t19);
|
||||
model.onActive = t19;
|
||||
|
||||
var t20 = model.onFocused;
|
||||
result += DeserializeMember(data, null, "onFocused", out t20);
|
||||
model.onFocused = t20;
|
||||
|
||||
var t21 = model.onHover;
|
||||
result += DeserializeMember(data, null, "onHover", out t21);
|
||||
model.onHover = t21;
|
||||
|
||||
var t22 = model.onNormal;
|
||||
result += DeserializeMember(data, null, "onNormal", out t22);
|
||||
model.onNormal = t22;
|
||||
|
||||
var t23 = model.overflow;
|
||||
result += DeserializeMember(data, null, "overflow", out t23);
|
||||
model.overflow = t23;
|
||||
|
||||
var t24 = model.padding;
|
||||
result += DeserializeMember(data, null, "padding", out t24);
|
||||
model.padding = t24;
|
||||
|
||||
var t25 = model.richText;
|
||||
result += DeserializeMember(data, null, "richText", out t25);
|
||||
model.richText = t25;
|
||||
|
||||
var t26 = model.stretchHeight;
|
||||
result += DeserializeMember(data, null, "stretchHeight", out t26);
|
||||
model.stretchHeight = t26;
|
||||
|
||||
var t27 = model.stretchWidth;
|
||||
result += DeserializeMember(data, null, "stretchWidth", out t27);
|
||||
model.stretchWidth = t27;
|
||||
|
||||
var t28 = model.wordWrap;
|
||||
result += DeserializeMember(data, null, "wordWrap", out t28);
|
||||
model.wordWrap = t28;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new GUIStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47dbcbf22e1d9234d95418fca447f2a8
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/GUIStyle_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,38 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Gradient_DirectConverter : fsDirectConverter<Gradient>
|
||||
{
|
||||
protected override fsResult DoSerialize(Gradient model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "alphaKeys", model.alphaKeys);
|
||||
result += SerializeMember(serialized, null, "colorKeys", model.colorKeys);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Gradient model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.alphaKeys;
|
||||
result += DeserializeMember(data, null, "alphaKeys", out t0);
|
||||
model.alphaKeys = t0;
|
||||
|
||||
var t1 = model.colorKeys;
|
||||
result += DeserializeMember(data, null, "colorKeys", out t1);
|
||||
model.colorKeys = t1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Gradient();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2db0c1839217344db6beac8c2eded04
|
||||
timeCreated: 1458897574
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Gradient_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma warning disable 612, 618
|
||||
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Keyframe_DirectConverter : fsDirectConverter<Keyframe>
|
||||
{
|
||||
protected override fsResult DoSerialize(Keyframe model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "time", model.time);
|
||||
result += SerializeMember(serialized, null, "value", model.value);
|
||||
result += SerializeMember(serialized, null, "tangentMode", model.tangentMode);
|
||||
result += SerializeMember(serialized, null, "inTangent", model.inTangent);
|
||||
result += SerializeMember(serialized, null, "outTangent", model.outTangent);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Keyframe model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.time;
|
||||
result += DeserializeMember(data, null, "time", out t0);
|
||||
model.time = t0;
|
||||
|
||||
var t1 = model.value;
|
||||
result += DeserializeMember(data, null, "value", out t1);
|
||||
model.value = t1;
|
||||
|
||||
var t2 = model.tangentMode;
|
||||
result += DeserializeMember(data, null, "tangentMode", out t2);
|
||||
model.tangentMode = t2;
|
||||
|
||||
var t3 = model.inTangent;
|
||||
result += DeserializeMember(data, null, "inTangent", out t3);
|
||||
model.inTangent = t3;
|
||||
|
||||
var t4 = model.outTangent;
|
||||
result += DeserializeMember(data, null, "outTangent", out t4);
|
||||
model.outTangent = t4;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Keyframe();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma warning restore 612, 618
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cc188d77995f2442a7e180f6788dd3a
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Keyframe_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,33 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class LayerMask_DirectConverter : fsDirectConverter<LayerMask>
|
||||
{
|
||||
protected override fsResult DoSerialize(LayerMask model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "value", model.value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref LayerMask model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.value;
|
||||
result += DeserializeMember(data, null, "value", out t0);
|
||||
model.value = t0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new LayerMask();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 798703a1e8c6a394fa11ea20d551c34a
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/LayerMask_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,48 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class RectOffset_DirectConverter : fsDirectConverter<RectOffset>
|
||||
{
|
||||
protected override fsResult DoSerialize(RectOffset model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "bottom", model.bottom);
|
||||
result += SerializeMember(serialized, null, "left", model.left);
|
||||
result += SerializeMember(serialized, null, "right", model.right);
|
||||
result += SerializeMember(serialized, null, "top", model.top);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref RectOffset model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.bottom;
|
||||
result += DeserializeMember(data, null, "bottom", out t0);
|
||||
model.bottom = t0;
|
||||
|
||||
var t2 = model.left;
|
||||
result += DeserializeMember(data, null, "left", out t2);
|
||||
model.left = t2;
|
||||
|
||||
var t3 = model.right;
|
||||
result += DeserializeMember(data, null, "right", out t3);
|
||||
model.right = t3;
|
||||
|
||||
var t4 = model.top;
|
||||
result += DeserializeMember(data, null, "top", out t4);
|
||||
model.top = t4;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new RectOffset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eec86a1441c2ed34a8921a1881e1a09d
|
||||
timeCreated: 1458897574
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/RectOffset_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,48 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Rect_DirectConverter : fsDirectConverter<Rect>
|
||||
{
|
||||
protected override fsResult DoSerialize(Rect model, Dictionary<string, fsData> serialized) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
result += SerializeMember(serialized, null, "xMin", model.xMin);
|
||||
result += SerializeMember(serialized, null, "yMin", model.yMin);
|
||||
result += SerializeMember(serialized, null, "xMax", model.xMax);
|
||||
result += SerializeMember(serialized, null, "yMax", model.yMax);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Rect model) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
var t0 = model.xMin;
|
||||
result += DeserializeMember(data, null, "xMin", out t0);
|
||||
model.xMin = t0;
|
||||
|
||||
var t1 = model.yMin;
|
||||
result += DeserializeMember(data, null, "yMin", out t1);
|
||||
model.yMin = t1;
|
||||
|
||||
var t2 = model.xMax;
|
||||
result += DeserializeMember(data, null, "xMax", out t2);
|
||||
model.xMax = t2;
|
||||
|
||||
var t3 = model.yMax;
|
||||
result += DeserializeMember(data, null, "yMax", out t3);
|
||||
model.yMax = t3;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Rect();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d8a097ac85e4ea40a93043962b9c75f
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Rect_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,33 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Vector2Int_DirectConverter : fsDirectConverter<Vector2Int>
|
||||
{
|
||||
protected override fsResult DoSerialize(Vector2Int model, Dictionary<string, fsData> serialized) {
|
||||
SerializeMember(serialized, null, "x", model.x);
|
||||
SerializeMember(serialized, null, "y", model.y);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Vector2Int model) {
|
||||
var t0 = model.x;
|
||||
DeserializeMember(data, null, "x", out t0);
|
||||
model.x = t0;
|
||||
|
||||
var t1 = model.y;
|
||||
DeserializeMember(data, null, "y", out t1);
|
||||
model.y = t1;
|
||||
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Vector2Int();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be6032e4c16bac44d9f70aa66f3974c6
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Vector2Int_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,33 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Vector2_DirectConverter : fsDirectConverter<Vector2>
|
||||
{
|
||||
protected override fsResult DoSerialize(Vector2 model, Dictionary<string, fsData> serialized) {
|
||||
SerializeMember(serialized, null, "x", model.x);
|
||||
SerializeMember(serialized, null, "y", model.y);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Vector2 model) {
|
||||
var t0 = model.x;
|
||||
DeserializeMember(data, null, "x", out t0);
|
||||
model.x = t0;
|
||||
|
||||
var t1 = model.y;
|
||||
DeserializeMember(data, null, "y", out t1);
|
||||
model.y = t1;
|
||||
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Vector2();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a26911f65c1b5348b30660780642c5f
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Vector2_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,38 @@
|
||||
#if !NO_UNITY
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters
|
||||
{
|
||||
public class Vector3Int_DirectConverter : fsDirectConverter<Vector3Int>
|
||||
{
|
||||
protected override fsResult DoSerialize(Vector3Int model, Dictionary<string, fsData> serialized) {
|
||||
SerializeMember(serialized, null, "x", model.x);
|
||||
SerializeMember(serialized, null, "y", model.y);
|
||||
SerializeMember(serialized, null, "z", model.z);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Vector3Int model) {
|
||||
var t0 = model.x;
|
||||
DeserializeMember(data, null, "x", out t0);
|
||||
model.x = t0;
|
||||
|
||||
var t1 = model.y;
|
||||
DeserializeMember(data, null, "y", out t1);
|
||||
model.y = t1;
|
||||
|
||||
var t2 = model.z;
|
||||
DeserializeMember(data, null, "z", out t2);
|
||||
model.z = t2;
|
||||
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return new Vector3Int();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5568041b7ef3e4247bea3608589c2805
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/Unity/Vector3Int_DirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
public class fsArrayConverter : fsConverter
|
||||
{
|
||||
public override bool CanProcess(Type type) {
|
||||
return type.IsArray;
|
||||
}
|
||||
|
||||
public override bool RequestCycleSupport(Type storageType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool RequestInheritanceSupport(Type storageType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
// note: IList[index] is **significantly** faster than Array.Get, so make sure we use
|
||||
// that instead.
|
||||
|
||||
IList arr = (Array)instance;
|
||||
Type elementType = storageType.GetElementType();
|
||||
|
||||
var result = fsResult.Success;
|
||||
|
||||
serialized = fsData.CreateList(arr.Count);
|
||||
var serializedList = serialized.AsList;
|
||||
|
||||
for ( int i = 0; i < arr.Count; ++i ) {
|
||||
object item = arr[i];
|
||||
|
||||
fsData serializedItem;
|
||||
|
||||
var itemResult = Serializer.TrySerialize(elementType, item, out serializedItem);
|
||||
result.AddMessages(itemResult);
|
||||
if ( itemResult.Failed ) continue;
|
||||
|
||||
serializedList.Add(serializedItem);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
// Verify that we actually have an List
|
||||
if ( ( result += CheckType(data, fsDataType.Array) ).Failed ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Type elementType = storageType.GetElementType();
|
||||
|
||||
var serializedList = data.AsList;
|
||||
var list = new ArrayList(serializedList.Count);
|
||||
int existingCount = list.Count;
|
||||
|
||||
for ( int i = 0; i < serializedList.Count; ++i ) {
|
||||
var serializedItem = serializedList[i];
|
||||
object deserialized = null;
|
||||
if ( i < existingCount ) deserialized = list[i];
|
||||
|
||||
var itemResult = Serializer.TryDeserialize(serializedItem, elementType, ref deserialized);
|
||||
result.AddMessages(itemResult);
|
||||
if ( itemResult.Failed ) continue;
|
||||
|
||||
if ( i < existingCount ) list[i] = deserialized;
|
||||
else list.Add(deserialized);
|
||||
}
|
||||
|
||||
instance = list.ToArray(elementType);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return fsMetaType.Get(storageType).CreateInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fd95ce87e49ad9408a03e4e9c0121fe
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsArrayConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
// While the generic IEnumerable converter can handle dictionaries, we process them separately here because
|
||||
// we support a few more advanced use-cases with dictionaries, such as inline strings. Further, dictionary
|
||||
// processing in general is a bit more advanced because a few of the collection implementations are buggy.
|
||||
public class fsDictionaryConverter : fsConverter
|
||||
{
|
||||
public override bool CanProcess(Type type) {
|
||||
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>);
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return fsMetaType.Get(storageType).CreateInstance();
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance_, out fsData serialized, Type storageType) {
|
||||
serialized = fsData.Null;
|
||||
var result = fsResult.Success;
|
||||
var instance = (IDictionary)instance_;
|
||||
|
||||
var args = instance.GetType().RTGetGenericArguments();
|
||||
var keyStorageType = args[0];
|
||||
var valueStorageType = args[1];
|
||||
|
||||
bool allStringKeys = true;
|
||||
var serializedKeys = new List<fsData>(instance.Count);
|
||||
var serializedValues = new List<fsData>(instance.Count);
|
||||
|
||||
// No other way to iterate dictionaries and still have access to the key/value info
|
||||
IDictionaryEnumerator enumerator = instance.GetEnumerator();
|
||||
|
||||
while ( enumerator.MoveNext() ) {
|
||||
fsData keyData, valueData;
|
||||
if ( ( result += Serializer.TrySerialize(keyStorageType, enumerator.Key, out keyData) ).Failed ) return result;
|
||||
if ( ( result += Serializer.TrySerialize(valueStorageType, enumerator.Value, out valueData) ).Failed ) return result;
|
||||
|
||||
serializedKeys.Add(keyData);
|
||||
serializedValues.Add(valueData);
|
||||
|
||||
allStringKeys &= keyData.IsString;
|
||||
}
|
||||
|
||||
if ( allStringKeys ) {
|
||||
|
||||
serialized = fsData.CreateDictionary();
|
||||
var serializedDictionary = serialized.AsDictionary;
|
||||
|
||||
for ( int i = 0; i < serializedKeys.Count; ++i ) {
|
||||
fsData key = serializedKeys[i];
|
||||
fsData value = serializedValues[i];
|
||||
serializedDictionary[key.AsString] = value;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
serialized = fsData.CreateList(serializedKeys.Count);
|
||||
var serializedList = serialized.AsList;
|
||||
|
||||
for ( int i = 0; i < serializedKeys.Count; ++i ) {
|
||||
fsData key = serializedKeys[i];
|
||||
fsData value = serializedValues[i];
|
||||
|
||||
var container = new Dictionary<string, fsData>();
|
||||
container["Key"] = key;
|
||||
container["Value"] = value;
|
||||
serializedList.Add(new fsData(container));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance_, Type storageType) {
|
||||
var instance = (IDictionary)instance_;
|
||||
var result = fsResult.Success;
|
||||
|
||||
var args = instance.GetType().RTGetGenericArguments();
|
||||
var keyStorageType = args[0];
|
||||
var valueStorageType = args[1];
|
||||
|
||||
instance.Clear();
|
||||
|
||||
//(string, T)
|
||||
if ( data.IsDictionary ) {
|
||||
foreach ( var entry in data.AsDictionary ) {
|
||||
if ( fsSerializer.IsReservedKeyword(entry.Key) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fsData keyData = new fsData(entry.Key);
|
||||
fsData valueData = entry.Value;
|
||||
object keyInstance = null;
|
||||
object valueInstance = null;
|
||||
|
||||
if ( ( result += Serializer.TryDeserialize(keyData, keyStorageType, ref keyInstance) ).Failed ) return result;
|
||||
if ( ( result += Serializer.TryDeserialize(valueData, valueStorageType, ref valueInstance) ).Failed ) return result;
|
||||
|
||||
instance.Add(keyInstance, valueInstance);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//(T, T)
|
||||
if ( data.IsList ) {
|
||||
var list = data.AsList;
|
||||
for ( int i = 0; i < list.Count; ++i ) {
|
||||
var item = list[i];
|
||||
fsData keyData;
|
||||
fsData valueData;
|
||||
if ( ( result += CheckType(item, fsDataType.Object) ).Failed ) return result;
|
||||
if ( ( result += CheckKey(item, "Key", out keyData) ).Failed ) return result;
|
||||
if ( ( result += CheckKey(item, "Value", out valueData) ).Failed ) return result;
|
||||
|
||||
object keyInstance = null;
|
||||
object valueInstance = null;
|
||||
if ( ( result += Serializer.TryDeserialize(keyData, keyStorageType, ref keyInstance) ).Failed ) return result;
|
||||
if ( ( result += Serializer.TryDeserialize(valueData, valueStorageType, ref valueInstance) ).Failed ) return result;
|
||||
|
||||
instance.Add(keyInstance, valueInstance);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return FailExpectedType(data, fsDataType.Array, fsDataType.Object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08eebbb7f611f0549b447ac739f0d39e
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsDictionaryConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
///<summary> Serializes and deserializes enums by their current name.</summary>
|
||||
public class fsEnumConverter : fsConverter
|
||||
{
|
||||
public override bool CanProcess(Type type) {
|
||||
return type.IsEnum;
|
||||
}
|
||||
|
||||
public override bool RequestCycleSupport(Type storageType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool RequestInheritanceSupport(Type storageType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
// In .NET compact, Enum.ToObject(Type, Object) is defined but the overloads like
|
||||
// Enum.ToObject(Type, int) are not -- so we get around this by boxing the value.
|
||||
return Enum.ToObject(storageType, (object)0);
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
if ( fsGlobalConfig.SerializeEnumsAsInteger ) {
|
||||
serialized = new fsData(Convert.ToInt64(instance));
|
||||
} else if ( storageType.RTIsDefined<FlagsAttribute>(false) ) {
|
||||
long instanceValue = Convert.ToInt64(instance);
|
||||
var result = new StringBuilder();
|
||||
|
||||
bool first = true;
|
||||
foreach ( var value in Enum.GetValues(storageType) ) {
|
||||
long integralValue = Convert.ToInt64(value);
|
||||
bool isSet = ( instanceValue & integralValue ) == integralValue;
|
||||
|
||||
if ( isSet ) {
|
||||
if ( first == false ) result.Append(",");
|
||||
first = false;
|
||||
result.Append(value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
serialized = new fsData(result.ToString());
|
||||
} else {
|
||||
serialized = new fsData(Enum.GetName(storageType, instance));
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
|
||||
if ( data.IsString ) {
|
||||
string[] enumValues = data.AsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
long instanceValue = 0;
|
||||
for ( int i = 0; i < enumValues.Length; ++i ) {
|
||||
string enumValue = enumValues[i];
|
||||
|
||||
// Verify that the enum name exists; Enum.TryParse is only available in .NET 4.0
|
||||
// and above :(.
|
||||
if ( ArrayContains(Enum.GetNames(storageType), enumValue) == false ) {
|
||||
return fsResult.Fail("Cannot find enum name " + enumValue + " on type " + storageType);
|
||||
}
|
||||
|
||||
long flagValue = (long)Convert.ChangeType(Enum.Parse(storageType, enumValue), typeof(long));
|
||||
instanceValue |= flagValue;
|
||||
}
|
||||
|
||||
instance = Enum.ToObject(storageType, (object)instanceValue);
|
||||
return fsResult.Success;
|
||||
|
||||
} else if ( data.IsInt64 ) {
|
||||
|
||||
int enumValue = (int)data.AsInt64;
|
||||
|
||||
// In .NET compact, Enum.ToObject(Type, Object) is defined but the overloads like
|
||||
// Enum.ToObject(Type, int) are not -- so we get around this by boxing the value.
|
||||
instance = Enum.ToObject(storageType, (object)enumValue);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
return fsResult.Fail("EnumConverter encountered an unknown JSON data type");
|
||||
}
|
||||
|
||||
///<summary> Returns true if the given value is contained within the specified array.</summary>
|
||||
private static bool ArrayContains<T>(T[] values, T value) {
|
||||
for ( int i = 0; i < values.Length; ++i ) {
|
||||
if ( EqualityComparer<T>.Default.Equals(values[i], value) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c928d500b6162c4a870b0f8fd0803fc
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsEnumConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
///<summary> This allows you to forward serialization of an object to one of its members.</summary>
|
||||
// [fsForward("Values")]
|
||||
// struct Wrapper {
|
||||
// public int[] Values;
|
||||
// }
|
||||
// Then `Wrapper` will be serialized into a JSON array of integers. It will be as if `Wrapper` doesn't exist.
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct)]
|
||||
public sealed class fsForwardAttribute : Attribute
|
||||
{
|
||||
///<summary> The name of the member we should serialize as.</summary>
|
||||
public string MemberName;
|
||||
|
||||
///<summary> Forward object serialization to an instance member. See class comment.</summary>
|
||||
public fsForwardAttribute(string memberName) {
|
||||
MemberName = memberName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
public class fsForwardConverter : fsConverter
|
||||
{
|
||||
private string _memberName;
|
||||
|
||||
public fsForwardConverter(fsForwardAttribute attribute) {
|
||||
_memberName = attribute.MemberName;
|
||||
}
|
||||
|
||||
public override bool CanProcess(Type type) {
|
||||
throw new NotSupportedException("Please use the [fsForward(...)] attribute.");
|
||||
}
|
||||
|
||||
private fsResult GetProperty(object instance, out fsMetaProperty property) {
|
||||
var properties = fsMetaType.Get(instance.GetType()).Properties;
|
||||
for ( int i = 0; i < properties.Length; ++i ) {
|
||||
if ( properties[i].MemberName == _memberName ) {
|
||||
property = properties[i];
|
||||
return fsResult.Success;
|
||||
}
|
||||
}
|
||||
|
||||
property = default(fsMetaProperty);
|
||||
return fsResult.Fail("No property named \"" + _memberName + "\" on " + instance.GetType().FriendlyName());
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
serialized = fsData.Null;
|
||||
var result = fsResult.Success;
|
||||
|
||||
fsMetaProperty property;
|
||||
if ( ( result += GetProperty(instance, out property) ).Failed ) return result;
|
||||
|
||||
var actualInstance = property.Read(instance);
|
||||
return Serializer.TrySerialize(property.StorageType, actualInstance, out serialized);
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
fsMetaProperty property;
|
||||
if ( ( result += GetProperty(instance, out property) ).Failed ) return result;
|
||||
|
||||
object actualInstance = null;
|
||||
if ( ( result += Serializer.TryDeserialize(data, property.StorageType, ref actualInstance) ).Failed )
|
||||
return result;
|
||||
|
||||
property.Write(instance, actualInstance);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return fsMetaType.Get(storageType).CreateInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d980f5fcb4bdda4d8cfcd296dc5d5cb
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsForwardConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
public class fsListConverter : fsConverter
|
||||
{
|
||||
|
||||
public override bool CanProcess(Type type) {
|
||||
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>);
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return fsMetaType.Get(storageType).CreateInstance();
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance_, out fsData serialized, Type storageType) {
|
||||
var instance = (IList)instance_;
|
||||
var result = fsResult.Success;
|
||||
|
||||
var elementType = storageType.RTGetGenericArguments()[0];
|
||||
serialized = fsData.CreateList(instance.Count);
|
||||
var serializedList = serialized.AsList;
|
||||
|
||||
for ( var i = 0; i < instance.Count; i++ ) {
|
||||
var item = instance[i];
|
||||
fsData itemData;
|
||||
|
||||
// auto instance?
|
||||
if ( item == null && elementType.RTIsDefined<fsAutoInstance>(true) ) {
|
||||
item = fsMetaType.Get(elementType).CreateInstance();
|
||||
instance[i] = item;
|
||||
}
|
||||
|
||||
var itemResult = Serializer.TrySerialize(elementType, item, out itemData);
|
||||
result.AddMessages(itemResult);
|
||||
if ( itemResult.Failed ) continue;
|
||||
serializedList.Add(itemData);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance_, Type storageType) {
|
||||
var instance = (IList)instance_;
|
||||
var result = fsResult.Success;
|
||||
|
||||
if ( ( result += CheckType(data, fsDataType.Array) ).Failed ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if ( data.AsList.Count == 0 ) {
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
var elementType = storageType.RTGetGenericArguments()[0];
|
||||
//if we have the exact same count, deserialize overwrite
|
||||
if ( instance.Count == data.AsList.Count && fsMetaType.Get(elementType).DeserializeOverwriteRequest ) {
|
||||
for ( var i = 0; i < data.AsList.Count; i++ ) {
|
||||
object item = instance[i];
|
||||
var itemResult = Serializer.TryDeserialize(data.AsList[i], elementType, ref item);
|
||||
if ( itemResult.Failed ) continue;
|
||||
instance[i] = item;
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
//otherwise clear and start anew
|
||||
instance.Clear();
|
||||
var capacityProperty = instance.GetType().RTGetProperty("Capacity");
|
||||
capacityProperty.SetValue(instance, data.AsList.Count);
|
||||
for ( var i = 0; i < data.AsList.Count; i++ ) {
|
||||
object item = null;
|
||||
var itemResult = Serializer.TryDeserialize(data.AsList[i], elementType, ref item);
|
||||
if ( itemResult.Failed ) continue;
|
||||
instance.Add(item);
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bbe0663eca9e63479fc5f4d5633a727
|
||||
timeCreated: 1542286078
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsListConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
public class fsPrimitiveConverter : fsConverter
|
||||
{
|
||||
public override bool CanProcess(Type type) {
|
||||
return
|
||||
type.IsPrimitive ||
|
||||
type == typeof(string) ||
|
||||
type == typeof(decimal);
|
||||
}
|
||||
|
||||
public override bool RequestCycleSupport(Type storageType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool RequestInheritanceSupport(Type storageType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool UseBool(Type type) {
|
||||
return type == typeof(bool);
|
||||
}
|
||||
|
||||
private static bool UseInt64(Type type) {
|
||||
return type == typeof(sbyte) || type == typeof(byte) ||
|
||||
type == typeof(Int16) || type == typeof(UInt16) ||
|
||||
type == typeof(Int32) || type == typeof(UInt32) ||
|
||||
type == typeof(Int64) || type == typeof(UInt64);
|
||||
}
|
||||
|
||||
private static bool UseDouble(Type type) {
|
||||
return type == typeof(float) ||
|
||||
type == typeof(double) ||
|
||||
type == typeof(decimal);
|
||||
}
|
||||
|
||||
private static bool UseString(Type type) {
|
||||
return type == typeof(string) ||
|
||||
type == typeof(char);
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
var instanceType = instance.GetType();
|
||||
|
||||
if ( fsGlobalConfig.Serialize64BitIntegerAsString && ( instanceType == typeof(Int64) || instanceType == typeof(UInt64) ) ) {
|
||||
serialized = new fsData((string)Convert.ChangeType(instance, typeof(string)));
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
if ( UseBool(instanceType) ) {
|
||||
serialized = new fsData((bool)instance);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
if ( UseInt64(instanceType) ) {
|
||||
serialized = new fsData((Int64)Convert.ChangeType(instance, typeof(Int64)));
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
if ( UseDouble(instanceType) ) {
|
||||
// Casting from float to double introduces floating point jitter, ie, 0.1 becomes 0.100000001490116.
|
||||
// Casting to decimal as an intermediate step removes the jitter. Not sure why.
|
||||
if ( instance.GetType() == typeof(float) &&
|
||||
// Decimal can't store float.MinValue/float.MaxValue/float.PositiveInfinity/float.NegativeInfinity/float.NaN - an exception gets thrown in that scenario.
|
||||
(float)instance != float.MinValue &&
|
||||
(float)instance != float.MaxValue &&
|
||||
!float.IsInfinity((float)instance) &&
|
||||
!float.IsNaN((float)instance)
|
||||
) {
|
||||
serialized = new fsData((double)(decimal)(float)instance);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
serialized = new fsData((double)Convert.ChangeType(instance, typeof(double)));
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
if ( UseString(instanceType) ) {
|
||||
serialized = new fsData((string)Convert.ChangeType(instance, typeof(string)));
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
serialized = null;
|
||||
return fsResult.Fail("Unhandled primitive type " + instance.GetType());
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData storage, ref object instance, Type storageType) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
if ( UseBool(storageType) ) {
|
||||
if ( ( result += CheckType(storage, fsDataType.Boolean) ).Succeeded ) {
|
||||
instance = storage.AsBool;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if ( UseDouble(storageType) || UseInt64(storageType) ) {
|
||||
if ( storage.IsDouble ) {
|
||||
if ( storageType == typeof(float) ) {
|
||||
instance = (float)storage.AsDouble;
|
||||
} else {
|
||||
instance = Convert.ChangeType(storage.AsDouble, storageType);
|
||||
}
|
||||
} else if ( storage.IsInt64 ) {
|
||||
if ( storageType == typeof(int) ) {
|
||||
instance = (int)storage.AsInt64;
|
||||
} else {
|
||||
instance = Convert.ChangeType(storage.AsInt64, storageType);
|
||||
}
|
||||
} else if ( fsGlobalConfig.Serialize64BitIntegerAsString && storage.IsString &&
|
||||
( storageType == typeof(Int64) || storageType == typeof(UInt64) ) ) {
|
||||
instance = Convert.ChangeType(storage.AsString, storageType);
|
||||
} else {
|
||||
return fsResult.Fail(GetType().Name + " expected number but got " + storage.Type + " in " + storage);
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
if ( UseString(storageType) ) {
|
||||
if ( ( result += CheckType(storage, fsDataType.String) ).Succeeded ) {
|
||||
if ( storageType == typeof(char) ) {
|
||||
instance = storage.AsString[0];
|
||||
} else {
|
||||
instance = storage.AsString;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return fsResult.Fail(GetType().Name + ": Bad data; expected bool, number, string, but got " + storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36a3ab41e204e8043a26b8c4abce84af
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsPrimitiveConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
public class fsReflectedConverter : fsConverter
|
||||
{
|
||||
|
||||
public override bool CanProcess(Type type) {
|
||||
if ( type.IsArray || typeof(ICollection).IsAssignableFrom(type) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
serialized = fsData.CreateDictionary();
|
||||
var result = fsResult.Success;
|
||||
|
||||
fsMetaType metaType = fsMetaType.Get(instance.GetType());
|
||||
|
||||
//Dont do this for UnityObject. While there is fsUnityObjectConverter, this converter is also used as override,
|
||||
//when serializing a UnityObject directly.
|
||||
object defaultInstance = null;
|
||||
if ( fsGlobalConfig.SerializeDefaultValues == false && !( instance is UnityEngine.Object ) ) {
|
||||
defaultInstance = metaType.GetDefaultInstance();
|
||||
}
|
||||
|
||||
for ( int i = 0; i < metaType.Properties.Length; ++i ) {
|
||||
fsMetaProperty property = metaType.Properties[i];
|
||||
|
||||
if ( property.WriteOnly ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( property.AsReference && Serializer.IgnoreSerializeCycleReferences ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyValue = property.Read(instance);
|
||||
|
||||
// auto instance?
|
||||
if ( propertyValue == null && property.AutoInstance ) {
|
||||
propertyValue = fsMetaType.Get(property.StorageType).CreateInstance();
|
||||
property.Write(instance, propertyValue);
|
||||
} else if ( fsGlobalConfig.SerializeDefaultValues == false && defaultInstance != null ) {
|
||||
if ( Equals(propertyValue, property.Read(defaultInstance)) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fsData serializedData;
|
||||
var itemResult = Serializer.TrySerialize(property.StorageType, propertyValue, out serializedData);
|
||||
result.AddMessages(itemResult);
|
||||
if ( itemResult.Failed ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
serialized.AsDictionary[property.JsonName] = serializedData;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
|
||||
var result = fsResult.Success;
|
||||
|
||||
// Verify that we actually have an Object
|
||||
if ( ( result += CheckType(data, fsDataType.Object) ).Failed ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if ( data.AsDictionary.Count == 0 ) {
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
fsMetaType metaType = fsMetaType.Get(storageType);
|
||||
|
||||
for ( int i = 0; i < metaType.Properties.Length; ++i ) {
|
||||
fsMetaProperty property = metaType.Properties[i];
|
||||
|
||||
if ( property.ReadOnly ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fsData propertyData;
|
||||
if ( data.AsDictionary.TryGetValue(property.JsonName, out propertyData) ) {
|
||||
object deserializedValue = null;
|
||||
|
||||
//This does not work well with no serializing default values -> Find a workaround.
|
||||
if ( fsGlobalConfig.SerializeDefaultValues ) {
|
||||
if ( metaType.DeserializeOverwriteRequest || typeof(ICollection).IsAssignableFrom(storageType) ) {
|
||||
deserializedValue = property.Read(instance);
|
||||
}
|
||||
}
|
||||
|
||||
var itemResult = Serializer.TryDeserialize(propertyData, property.StorageType, ref deserializedValue, null);
|
||||
result.AddMessages(itemResult);
|
||||
if ( itemResult.Failed ) continue;
|
||||
|
||||
property.Write(instance, deserializedValue);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
fsMetaType metaType = fsMetaType.Get(storageType);
|
||||
return metaType.CreateInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12c3fc91102686643b600cfd6acbfc44
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsReflectedConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer.Internal
|
||||
{
|
||||
public class fsTypeConverter : fsConverter
|
||||
{
|
||||
public override bool CanProcess(Type type) {
|
||||
return typeof(Type).IsAssignableFrom(type);
|
||||
}
|
||||
|
||||
public override bool RequestCycleSupport(Type type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool RequestInheritanceSupport(Type type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
var type = (Type)instance;
|
||||
serialized = new fsData(type.FullName);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
|
||||
if ( data.IsString == false ) {
|
||||
return fsResult.Fail("Type converter requires a string");
|
||||
}
|
||||
|
||||
instance = ReflectionTools.GetType(data.AsString, true);
|
||||
if ( instance == null ) {
|
||||
return fsResult.Fail("Unable to find type " + data.AsString);
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
public override object CreateInstance(fsData data, Type storageType) {
|
||||
return storageType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04822397e73105643b393319d787924a
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/Converters/fsTypeConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
///<summary> Implement on type to migrate from another serialization-wise. This works in pair with the [fsMigrateToAttribute] and [fsMigrateVersionsAttribute] attributes.</summary>
|
||||
public interface IMigratable { }
|
||||
public interface IMigratable<T> : IMigratable
|
||||
{
|
||||
void Migrate(T model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fe18dd8cd84b3045b3f8c4c66ab3827
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/IMigratable.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
///<summary>Will receive callbacks on serialization/deserialization. Multiple collectors are possible and are stacked.</summary>
|
||||
public interface ISerializationCollector : ISerializationCollectable
|
||||
{
|
||||
///<summary>Called when the collector pushed on stack with parent the previous collector</summary>
|
||||
void OnPush(ISerializationCollector parent);
|
||||
///<summary>Called when a collectable is to be collected. The depth is local to this collector only starting from 0</summary>
|
||||
void OnCollect(ISerializationCollectable child, int depth);
|
||||
///<summary>Called when the collector pops from stack with parent the previous collector</summary>
|
||||
void OnPop(ISerializationCollector parent);
|
||||
}
|
||||
|
||||
///<summary>Will be possible to be collected by a collector</summary>
|
||||
public interface ISerializationCollectable { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcdec3f36feecf44b9aa5892c687b3fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/ISerializationCollector.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jacob Dufault
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c00e5ee9fdcb1cf4fa3e604852fdeed4
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/License
|
||||
(FullSerializer).txt
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
///<summary> Will make the field deserialize-only</summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public sealed class fsWriteOnlyAttribute : Attribute { }
|
||||
|
||||
///<summary> Will make the field serialize-only</summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public sealed class fsReadOnlyAttribute : Attribute { }
|
||||
|
||||
///<summary> Explicitly ignore a field from being serialized completely</summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public sealed class fsIgnoreAttribute : Attribute { }
|
||||
|
||||
///<summary> Explicitly ignore a field from being serialized/deserialized in build</summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public sealed class fsIgnoreInBuildAttribute : Attribute { }
|
||||
|
||||
///<summary> Explicitly opt in a field to be serialized and with specified name</summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public sealed class fsSerializeAsAttribute : Attribute
|
||||
{
|
||||
readonly public string Name;
|
||||
public fsSerializeAsAttribute() { }
|
||||
public fsSerializeAsAttribute(string name) {
|
||||
this.Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Use on a class to deserialize migrate into target type. This works in pair with IMigratable interface.</summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class fsMigrateToAttribute : System.Attribute
|
||||
{
|
||||
public readonly System.Type targetType;
|
||||
public fsMigrateToAttribute(System.Type targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Use on a class to specify previous serialization versions to migrate from. This works in pair with IMigratable interface.</summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class fsMigrateVersionsAttribute : System.Attribute
|
||||
{
|
||||
public readonly System.Type[] previousTypes;
|
||||
public fsMigrateVersionsAttribute(params System.Type[] previousTypes) {
|
||||
this.previousTypes = previousTypes;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Use on a class and field to request cycle references support</summary>
|
||||
// TODO: Refactor FS to only be required on field.
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field)]
|
||||
public sealed class fsSerializeAsReference : Attribute { }
|
||||
|
||||
///<summary> Use on a class to request try deserialize overwrite</summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class fsDeserializeOverwrite : Attribute { }
|
||||
|
||||
///<summary> Use on a class to mark it for creating instance unititialized (which is faster)</summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class fsUninitialized : System.Attribute { }
|
||||
|
||||
///<summary> Use on a class to request try create instance automatically on serialization</summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class fsAutoInstance : Attribute
|
||||
{
|
||||
public readonly bool makeInstance;
|
||||
public fsAutoInstance(bool makeInstance = true) {
|
||||
this.makeInstance = makeInstance;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> This attribute controls some serialization behavior for a type. See the comments on each of the fields for more information.</summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
|
||||
public sealed class fsObjectAttribute : Attribute
|
||||
{
|
||||
//Converter override to use
|
||||
public Type Converter;
|
||||
//Processor to use
|
||||
public Type Processor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1562b1a4a986ffc4fbe1694ff00bf6be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsAttributes.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
///<summary> The serialization converter allows for customization of the serialization process.</summary>
|
||||
public abstract class fsBaseConverter
|
||||
{
|
||||
///<summary> The serializer that owns this converter.</summary>
|
||||
public fsSerializer Serializer;
|
||||
|
||||
///<summary> Construct an object instance that will be passed to TryDeserialize. This should **not** deserialize the object.</summary>
|
||||
public virtual object CreateInstance(fsData data, Type storageType) {
|
||||
if ( RequestCycleSupport(storageType) ) {
|
||||
throw new InvalidOperationException("Please override CreateInstance for " +
|
||||
GetType().FullName + "; the object graph for " + storageType +
|
||||
" can contain potentially contain cycles, so separated instance creation " +
|
||||
"is needed");
|
||||
}
|
||||
|
||||
return storageType;
|
||||
}
|
||||
|
||||
///<summary> If true, then the serializer will support cyclic references with the given converted type.</summary>
|
||||
public virtual bool RequestCycleSupport(Type storageType) {
|
||||
if ( storageType == typeof(string) ) return false;
|
||||
return storageType.IsClass || storageType.IsInterface;
|
||||
}
|
||||
|
||||
///<summary> If true, then the serializer will include inheritance data for the given converter.</summary>
|
||||
public virtual bool RequestInheritanceSupport(Type storageType) {
|
||||
return storageType.IsSealed == false;
|
||||
}
|
||||
|
||||
///<summary> Serialize the actual object into the given data storage.</summary>
|
||||
public abstract fsResult TrySerialize(object instance, out fsData serialized, Type storageType);
|
||||
|
||||
///<summary> Deserialize data into the object instance.</summary>
|
||||
public abstract fsResult TryDeserialize(fsData data, ref object instance, Type storageType);
|
||||
|
||||
protected fsResult FailExpectedType(fsData data, params fsDataType[] types) {
|
||||
return fsResult.Fail(GetType().Name + " expected one of " +
|
||||
string.Join(", ", types.Select(t => t.ToString()).ToArray()) +
|
||||
" but got " + data.Type + " in " + data);
|
||||
}
|
||||
|
||||
protected fsResult CheckType(fsData data, fsDataType type) {
|
||||
if ( data.Type != type ) {
|
||||
return fsResult.Fail(GetType().Name + " expected " + type + " but got " + data.Type + " in " + data);
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
protected fsResult CheckKey(fsData data, string key, out fsData subitem) {
|
||||
return CheckKey(data.AsDictionary, key, out subitem);
|
||||
}
|
||||
|
||||
protected fsResult CheckKey(Dictionary<string, fsData> data, string key, out fsData subitem) {
|
||||
if ( data.TryGetValue(key, out subitem) == false ) {
|
||||
return fsResult.Fail(GetType().Name + " requires a <" + key + "> key in the data " + data);
|
||||
}
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
protected fsResult SerializeMember<T>(Dictionary<string, fsData> data, Type overrideConverterType, string name, T value) {
|
||||
fsData memberData;
|
||||
var result = Serializer.TrySerialize(typeof(T), value, out memberData, overrideConverterType);
|
||||
if ( result.Succeeded ) data[name] = memberData;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected fsResult DeserializeMember<T>(Dictionary<string, fsData> data, Type overrideConverterType, string name, out T value) {
|
||||
fsData memberData;
|
||||
if ( data.TryGetValue(name, out memberData) == false ) {
|
||||
value = default(T);
|
||||
return fsResult.Fail("Unable to find member \"" + name + "\"");
|
||||
}
|
||||
|
||||
object storage = null;
|
||||
var result = Serializer.TryDeserialize(memberData, typeof(T), ref storage, overrideConverterType);
|
||||
value = (T)storage;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a98c62150afed7418a6da0abe9fe7a8
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsBaseConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
///<summary> The serialization converter allows for customization of the serialization process.</summary>
|
||||
public abstract class fsConverter : fsBaseConverter
|
||||
{
|
||||
|
||||
///<summary> Can this converter serialize and deserialize the given object type?</summary>
|
||||
public abstract bool CanProcess(Type type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c81fdbd9e3ff8904fa0b5152599f13ac
|
||||
timeCreated: 1458897574
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
public class fsCyclicReferenceManager
|
||||
{
|
||||
// We use the default ReferenceEquals when comparing two objects because
|
||||
// custom objects may override equals methods. These overriden equals may
|
||||
// treat equals differently; we want to serialize/deserialize the object
|
||||
// graph *identically* to how it currently exists.
|
||||
class ObjectReferenceEqualityComparator : IEqualityComparer<object>
|
||||
{
|
||||
public static readonly IEqualityComparer<object> Instance = new ObjectReferenceEqualityComparator();
|
||||
bool IEqualityComparer<object>.Equals(object x, object y) { return ReferenceEquals(x, y); }
|
||||
int IEqualityComparer<object>.GetHashCode(object obj) { return RuntimeHelpers.GetHashCode(obj); }
|
||||
}
|
||||
|
||||
private Dictionary<object, int> _objectIds;
|
||||
private int _nextId;
|
||||
|
||||
private Dictionary<int, object> _marked;
|
||||
private int _depth;
|
||||
|
||||
public fsCyclicReferenceManager() {
|
||||
_objectIds = new Dictionary<object, int>(ObjectReferenceEqualityComparator.Instance);
|
||||
_marked = new Dictionary<int, object>();
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
_depth = 0;
|
||||
_nextId = 0;
|
||||
_objectIds.Clear();
|
||||
_marked.Clear();
|
||||
}
|
||||
|
||||
public bool Enter() {
|
||||
_depth++;
|
||||
return _depth == 1;
|
||||
}
|
||||
|
||||
public bool Exit() {
|
||||
_depth--;
|
||||
|
||||
if ( _depth == 0 ) {
|
||||
_nextId = 0;
|
||||
_objectIds.Clear();
|
||||
_marked.Clear();
|
||||
}
|
||||
|
||||
if ( _depth < 0 ) {
|
||||
_depth = 0;
|
||||
throw new InvalidOperationException("Internal Error - Mismatched Enter/Exit");
|
||||
}
|
||||
|
||||
return _depth == 0;
|
||||
}
|
||||
|
||||
public object GetReferenceObject(int id) {
|
||||
object result = null;
|
||||
if ( !_marked.TryGetValue(id, out result) ) {
|
||||
throw new InvalidOperationException("Internal Deserialization Error - Object " +
|
||||
"definition has not been encountered for object with id=" + id +
|
||||
"; have you reordered or modified the serialized data? If this is an issue " +
|
||||
"with an unmodified Full Json implementation and unmodified serialization " +
|
||||
"data, please report an issue with an included test case.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void AddReferenceWithId(int id, object reference) {
|
||||
_marked[id] = reference;
|
||||
}
|
||||
|
||||
public int GetReferenceId(object item) {
|
||||
int id;
|
||||
if ( !_objectIds.TryGetValue(item, out id) ) {
|
||||
id = _nextId++;
|
||||
_objectIds[item] = id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public bool IsReference(object item) {
|
||||
return _marked.ContainsKey(GetReferenceId(item));
|
||||
}
|
||||
|
||||
public void MarkSerialized(object item) {
|
||||
int referenceId = GetReferenceId(item);
|
||||
|
||||
if ( _marked.ContainsKey(referenceId) ) {
|
||||
throw new InvalidOperationException("Internal Error - " + item + " has already been marked as serialized");
|
||||
}
|
||||
|
||||
_marked[referenceId] = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bdee320e42b9084e82dfe394c02852e
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsCyclicReferenceManager.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,291 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
///<summary> The actual type that a JsonData instance can store.</summary>
|
||||
public enum fsDataType
|
||||
{
|
||||
Array,
|
||||
Object,
|
||||
Double,
|
||||
Int64,
|
||||
Boolean,
|
||||
String,
|
||||
Null
|
||||
}
|
||||
|
||||
///<summary> A union type that stores a serialized value. The stored type can be one of six different types: null, boolean, double, Int64, string, Dictionary, or List.</summary>
|
||||
public sealed class fsData
|
||||
{
|
||||
|
||||
///<summary> The raw value that this serialized data stores. It can be one of six different types; a boolean, a double, Int64, a string, a Dictionary, or a List.</summary>
|
||||
private object _value;
|
||||
|
||||
public readonly static fsData True = new fsData(true);
|
||||
public readonly static fsData False = new fsData(false);
|
||||
public readonly static fsData Null = new fsData();
|
||||
|
||||
public fsDataType Type {
|
||||
get
|
||||
{
|
||||
if ( _value == null ) return fsDataType.Null;
|
||||
if ( _value is double ) return fsDataType.Double;
|
||||
if ( _value is Int64 ) return fsDataType.Int64;
|
||||
if ( _value is bool ) return fsDataType.Boolean;
|
||||
if ( _value is string ) return fsDataType.String;
|
||||
if ( _value is Dictionary<string, fsData> ) return fsDataType.Object;
|
||||
if ( _value is List<fsData> ) return fsDataType.Array;
|
||||
throw new InvalidOperationException("unknown JSON data type");
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Creates a fsData instance that holds null.</summary>
|
||||
public fsData() {
|
||||
_value = null;
|
||||
}
|
||||
|
||||
///<summary> Creates a fsData instance that holds a boolean.</summary>
|
||||
public fsData(bool boolean) {
|
||||
_value = boolean;
|
||||
}
|
||||
|
||||
///<summary> Creates a fsData instance that holds a double.</summary>
|
||||
public fsData(double f) {
|
||||
_value = f;
|
||||
}
|
||||
|
||||
///<summary> Creates a new fsData instance that holds an integer.</summary>
|
||||
public fsData(Int64 i) {
|
||||
_value = i;
|
||||
}
|
||||
|
||||
///<summary> Creates a fsData instance that holds a string.</summary>
|
||||
public fsData(string str) {
|
||||
_value = str;
|
||||
}
|
||||
|
||||
///<summary> Creates a fsData instance that holds a dictionary of values.</summary>
|
||||
public fsData(Dictionary<string, fsData> dict) {
|
||||
_value = dict;
|
||||
}
|
||||
|
||||
///<summary> Creates a fsData instance that holds a list of values.</summary>
|
||||
public fsData(List<fsData> list) {
|
||||
_value = list;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Helper method to create a fsData instance that holds a dictionary.</summary>
|
||||
public static fsData CreateDictionary() {
|
||||
return new fsData(new Dictionary<string, fsData>(
|
||||
fsGlobalConfig.IsCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
///<summary> Helper method to create a fsData instance that holds a list.</summary>
|
||||
public static fsData CreateList() {
|
||||
return new fsData(new List<fsData>());
|
||||
}
|
||||
|
||||
///<summary> Helper method to create a fsData instance that holds a list with the initial capacity.</summary>
|
||||
public static fsData CreateList(int capacity) {
|
||||
return new fsData(new List<fsData>(capacity));
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Transforms the internal fsData instance into a dictionary.</summary>
|
||||
internal void BecomeDictionary() {
|
||||
_value = new Dictionary<string, fsData>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
///<summary> Returns a shallow clone of this data instance.</summary>
|
||||
internal fsData Clone() {
|
||||
var clone = new fsData();
|
||||
clone._value = _value;
|
||||
return clone;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to null.</summary>
|
||||
public bool IsNull {
|
||||
get { return _value == null; }
|
||||
}
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to a double.</summary>
|
||||
public bool IsDouble {
|
||||
get { return _value is double; }
|
||||
}
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to an Int64.</summary>
|
||||
public bool IsInt64 {
|
||||
get { return _value is Int64; }
|
||||
}
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to a boolean.</summary>
|
||||
public bool IsBool {
|
||||
get { return _value is bool; }
|
||||
}
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to a string.</summary>
|
||||
public bool IsString {
|
||||
get { return _value is string; }
|
||||
}
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to a Dictionary.</summary>
|
||||
public bool IsDictionary {
|
||||
get { return _value is Dictionary<string, fsData>; }
|
||||
}
|
||||
|
||||
///<summary> Returns true if this fsData instance maps back to a List.</summary>
|
||||
public bool IsList {
|
||||
get { return _value is List<fsData>; }
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Casts this fsData to a double. Throws an exception if it is not a double.</summary>
|
||||
public double AsDouble {
|
||||
get { return Cast<double>(); }
|
||||
}
|
||||
|
||||
///<summary> Casts this fsData to an Int64. Throws an exception if it is not an Int64.</summary>
|
||||
public Int64 AsInt64 {
|
||||
get { return Cast<Int64>(); }
|
||||
}
|
||||
|
||||
///<summary> Casts this fsData to a boolean. Throws an exception if it is not a boolean.</summary>
|
||||
public bool AsBool {
|
||||
get { return Cast<bool>(); }
|
||||
}
|
||||
|
||||
///<summary> Casts this fsData to a string. Throws an exception if it is not a string.</summary>
|
||||
public string AsString {
|
||||
get { return Cast<string>(); }
|
||||
}
|
||||
|
||||
///<summary> Casts this fsData to a Dictionary. Throws an exception if it is not a Dictionary.</summary>
|
||||
public Dictionary<string, fsData> AsDictionary {
|
||||
get { return Cast<Dictionary<string, fsData>>(); }
|
||||
}
|
||||
|
||||
///<summary> Casts this fsData to a List. Throws an exception if it is not a List.</summary>
|
||||
public List<fsData> AsList {
|
||||
get { return Cast<List<fsData>>(); }
|
||||
}
|
||||
|
||||
///<summary> Internal helper method to cast the underlying storage to the given type or throw a pretty printed exception on failure.</summary>
|
||||
private T Cast<T>() {
|
||||
if ( _value is T ) { return (T)_value; }
|
||||
|
||||
throw new InvalidCastException("Unable to cast <" + this + "> (with type = " +
|
||||
_value.GetType() + ") to type " + typeof(T));
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
public override string ToString() {
|
||||
return fsJsonPrinter.CompressedJson(this);
|
||||
}
|
||||
|
||||
///<summary> Determines whether the specified object is equal to the current object.</summary>
|
||||
public override bool Equals(object obj) {
|
||||
return Equals(obj as fsData);
|
||||
}
|
||||
|
||||
///<summary> Determines whether the specified object is equal to the current object.</summary>
|
||||
public bool Equals(fsData other) {
|
||||
if ( other == null || Type != other.Type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( Type ) {
|
||||
case fsDataType.Null:
|
||||
return true;
|
||||
|
||||
case fsDataType.Double:
|
||||
return AsDouble == other.AsDouble || Math.Abs(AsDouble - other.AsDouble) < double.Epsilon;
|
||||
|
||||
case fsDataType.Int64:
|
||||
return AsInt64 == other.AsInt64;
|
||||
|
||||
case fsDataType.Boolean:
|
||||
return AsBool == other.AsBool;
|
||||
|
||||
case fsDataType.String:
|
||||
return AsString == other.AsString;
|
||||
|
||||
case fsDataType.Array:
|
||||
var thisList = AsList;
|
||||
var otherList = other.AsList;
|
||||
|
||||
if ( thisList.Count != otherList.Count ) return false;
|
||||
|
||||
for ( int i = 0; i < thisList.Count; ++i ) {
|
||||
if ( thisList[i].Equals(otherList[i]) == false ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case fsDataType.Object:
|
||||
var thisDict = AsDictionary;
|
||||
var otherDict = other.AsDictionary;
|
||||
|
||||
if ( thisDict.Count != otherDict.Count ) return false;
|
||||
|
||||
foreach ( string key in thisDict.Keys ) {
|
||||
if ( otherDict.ContainsKey(key) == false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( thisDict[key].Equals(otherDict[key]) == false ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Exception("Unknown data type");
|
||||
}
|
||||
|
||||
///<summary> Returns true iff a == b.</summary>
|
||||
public static bool operator ==(fsData a, fsData b) {
|
||||
// If both are null, or both are same instance, return true.
|
||||
if ( ReferenceEquals(a, b) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If one is null, but not both, return false.
|
||||
if ( ( (object)a == null ) || ( (object)b == null ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( a.IsDouble && b.IsDouble ) {
|
||||
return Math.Abs(a.AsDouble - b.AsDouble) < double.Epsilon;
|
||||
}
|
||||
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
///<summary> Returns true iff a != b.</summary>
|
||||
public static bool operator !=(fsData a, fsData b) {
|
||||
return !( a == b );
|
||||
}
|
||||
|
||||
///<summary> Returns a hash code for this instance.</summary>
|
||||
public override int GetHashCode() {
|
||||
return _value.GetHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 780ba11f7939c2643a2c94ba9a4c2c6d
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsData.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
///<summary> The direct converter is similar to a regular converter, except that it targets specifically only one type. This means that it can be used without performance impact when discovering converters. It is strongly recommended that you derive from fsDirectConverter{TModel}.</summary>
|
||||
public abstract class fsDirectConverter : fsBaseConverter
|
||||
{
|
||||
public abstract Type ModelType { get; }
|
||||
}
|
||||
|
||||
public abstract class fsDirectConverter<TModel> : fsDirectConverter
|
||||
{
|
||||
public override Type ModelType { get { return typeof(TModel); } }
|
||||
|
||||
public sealed override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
|
||||
var serializedDictionary = new Dictionary<string, fsData>();
|
||||
var result = DoSerialize((TModel)instance, serializedDictionary);
|
||||
serialized = new fsData(serializedDictionary);
|
||||
return result;
|
||||
}
|
||||
|
||||
public sealed override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
|
||||
var result = fsResult.Success;
|
||||
if ( ( result += CheckType(data, fsDataType.Object) ).Failed ) return result;
|
||||
|
||||
var obj = (TModel)instance;
|
||||
result += DoDeserialize(data.AsDictionary, ref obj);
|
||||
instance = obj;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract fsResult DoSerialize(TModel model, Dictionary<string, fsData> serialized);
|
||||
protected abstract fsResult DoDeserialize(Dictionary<string, fsData> data, ref TModel model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 137ee4bc1374e32488d1adcd174bad7a
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsDirectConverter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,37 @@
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
// Global configuration options.
|
||||
public static class fsGlobalConfig
|
||||
{
|
||||
|
||||
///<summary> Serialize default values?</summary>
|
||||
public static bool SerializeDefaultValues = false;
|
||||
|
||||
///<summary> Should deserialization be case sensitive? If this is false and the JSON has multiple members with the same keys only separated by case, then this results in undefined behavior.</summary>
|
||||
public static bool IsCaseSensitive = false;
|
||||
|
||||
///<summary> The attributes that will force a field or property to *not* be serialized. Ignore attribute take predecence.</summary>
|
||||
public static System.Type[] IgnoreSerializeAttributes =
|
||||
{
|
||||
typeof(System.NonSerializedAttribute),
|
||||
typeof(fsIgnoreAttribute)
|
||||
};
|
||||
|
||||
///<summary> The attributes that will force a field or property to be serialized. Ignore attribute take predecence.</summary>
|
||||
public static System.Type[] SerializeAttributes =
|
||||
{
|
||||
typeof(UnityEngine.SerializeField),
|
||||
typeof(fsSerializeAsAttribute)
|
||||
};
|
||||
|
||||
///<summary> If not null, this string format will be used for DateTime instead of the default one.</summary>
|
||||
public static string CustomDateTimeFormatString = null;
|
||||
|
||||
///<summary> Int64 and UInt64 will be serialized and deserialized as string for compatibility</summary>
|
||||
public static bool Serialize64BitIntegerAsString = false;
|
||||
|
||||
///<summary> Enums are serialized using their names by default. Setting this to true will serialize them as integers instead.</summary>
|
||||
public static bool SerializeEnumsAsInteger = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 766ca959e12335842974a66cbf15c23f
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsGlobalConfig.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,489 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
// TODO: properly propagate warnings/etc for fsResult states
|
||||
|
||||
///<summary> A simple recursive descent parser for JSON.</summary>
|
||||
public class fsJsonParser
|
||||
{
|
||||
private int _start;
|
||||
private string _input;
|
||||
|
||||
private fsResult MakeFailure(string message) {
|
||||
int start = Math.Max(0, _start - 20);
|
||||
int length = Math.Min(50, _input.Length - start);
|
||||
|
||||
string error = "Error while parsing: " + message + "; context = <" +
|
||||
_input.Substring(start, length) + ">";
|
||||
return fsResult.Fail(error);
|
||||
}
|
||||
|
||||
private bool TryMoveNext() {
|
||||
if ( _start < _input.Length ) {
|
||||
++_start;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool HasValue() {
|
||||
return HasValue(0);
|
||||
}
|
||||
|
||||
private bool HasValue(int offset) {
|
||||
return ( _start + offset ) >= 0 && ( _start + offset ) < _input.Length;
|
||||
}
|
||||
|
||||
private char Character() {
|
||||
return Character(0);
|
||||
}
|
||||
|
||||
private char Character(int offset) {
|
||||
return _input[_start + offset];
|
||||
}
|
||||
|
||||
///<summary> Skips input such that Character() will return a non-whitespace character</summary>
|
||||
private void SkipSpace() {
|
||||
while ( HasValue() ) {
|
||||
char c = Character();
|
||||
|
||||
// whitespace; fine to skip
|
||||
if ( char.IsWhiteSpace(c) ) {
|
||||
TryMoveNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
// comment?
|
||||
if ( HasValue(1) && Character(0) == '/' ) {
|
||||
if ( Character(1) == '/' ) {
|
||||
// skip the rest of the line
|
||||
while ( HasValue() && Environment.NewLine.Contains("" + Character()) == false ) {
|
||||
TryMoveNext();
|
||||
}
|
||||
continue;
|
||||
} else if ( Character(1) == '*' ) {
|
||||
// skip to comment close
|
||||
TryMoveNext();
|
||||
TryMoveNext();
|
||||
while ( HasValue(1) ) {
|
||||
if ( Character(0) == '*' && Character(1) == '/' ) {
|
||||
TryMoveNext();
|
||||
TryMoveNext();
|
||||
TryMoveNext();
|
||||
break;
|
||||
} else {
|
||||
TryMoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
// let other checks to check fail
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region Escaping
|
||||
private bool IsHex(char c) {
|
||||
return ( ( c >= '0' && c <= '9' ) ||
|
||||
( c >= 'a' && c <= 'f' ) ||
|
||||
( c >= 'A' && c <= 'F' ) );
|
||||
}
|
||||
|
||||
private uint ParseSingleChar(char c1, uint multipliyer) {
|
||||
uint p1 = 0;
|
||||
if ( c1 >= '0' && c1 <= '9' )
|
||||
p1 = (uint)( c1 - '0' ) * multipliyer;
|
||||
else if ( c1 >= 'A' && c1 <= 'F' )
|
||||
p1 = (uint)( ( c1 - 'A' ) + 10 ) * multipliyer;
|
||||
else if ( c1 >= 'a' && c1 <= 'f' )
|
||||
p1 = (uint)( ( c1 - 'a' ) + 10 ) * multipliyer;
|
||||
return p1;
|
||||
}
|
||||
|
||||
private uint ParseUnicode(char c1, char c2, char c3, char c4) {
|
||||
uint p1 = ParseSingleChar(c1, 0x1000);
|
||||
uint p2 = ParseSingleChar(c2, 0x100);
|
||||
uint p3 = ParseSingleChar(c3, 0x10);
|
||||
uint p4 = ParseSingleChar(c4, 0x1);
|
||||
|
||||
return p1 + p2 + p3 + p4;
|
||||
}
|
||||
|
||||
private fsResult TryUnescapeChar(out char escaped) {
|
||||
// skip leading backslash '\'
|
||||
TryMoveNext();
|
||||
if ( HasValue() == false ) {
|
||||
escaped = ' ';
|
||||
return MakeFailure("Unexpected end of input after \\");
|
||||
}
|
||||
|
||||
switch ( Character() ) {
|
||||
case '\\': TryMoveNext(); escaped = '\\'; return fsResult.Success;
|
||||
case '/': TryMoveNext(); escaped = '/'; return fsResult.Success;
|
||||
case '"': TryMoveNext(); escaped = '\"'; return fsResult.Success;
|
||||
case 'a': TryMoveNext(); escaped = '\a'; return fsResult.Success;
|
||||
case 'b': TryMoveNext(); escaped = '\b'; return fsResult.Success;
|
||||
case 'f': TryMoveNext(); escaped = '\f'; return fsResult.Success;
|
||||
case 'n': TryMoveNext(); escaped = '\n'; return fsResult.Success;
|
||||
case 'r': TryMoveNext(); escaped = '\r'; return fsResult.Success;
|
||||
case 't': TryMoveNext(); escaped = '\t'; return fsResult.Success;
|
||||
case '0': TryMoveNext(); escaped = '\0'; return fsResult.Success;
|
||||
case 'u':
|
||||
TryMoveNext();
|
||||
if ( IsHex(Character(0))
|
||||
&& IsHex(Character(1))
|
||||
&& IsHex(Character(2))
|
||||
&& IsHex(Character(3)) ) {
|
||||
|
||||
uint codePoint = ParseUnicode(Character(0), Character(1), Character(2), Character(3));
|
||||
|
||||
TryMoveNext();
|
||||
TryMoveNext();
|
||||
TryMoveNext();
|
||||
TryMoveNext();
|
||||
|
||||
escaped = (char)codePoint;
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
// invalid escape sequence
|
||||
escaped = (char)0;
|
||||
return MakeFailure(
|
||||
string.Format("invalid escape sequence '\\u{0}{1}{2}{3}'\n",
|
||||
Character(0),
|
||||
Character(1),
|
||||
Character(2),
|
||||
Character(3)));
|
||||
default:
|
||||
escaped = (char)0;
|
||||
return MakeFailure(string.Format("Invalid escape sequence \\{0}", Character()));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private fsResult TryParseExact(string content) {
|
||||
for ( int i = 0; i < content.Length; ++i ) {
|
||||
if ( Character() != content[i] ) {
|
||||
return MakeFailure("Expected " + content[i]);
|
||||
}
|
||||
|
||||
if ( TryMoveNext() == false ) {
|
||||
return MakeFailure("Unexpected end of content when parsing " + content);
|
||||
}
|
||||
}
|
||||
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
private fsResult TryParseTrue(out fsData data) {
|
||||
var fail = TryParseExact("true");
|
||||
|
||||
if ( fail.Succeeded ) {
|
||||
data = new fsData(true);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
data = null;
|
||||
return fail;
|
||||
}
|
||||
|
||||
private fsResult TryParseFalse(out fsData data) {
|
||||
var fail = TryParseExact("false");
|
||||
|
||||
if ( fail.Succeeded ) {
|
||||
data = new fsData(false);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
data = null;
|
||||
return fail;
|
||||
}
|
||||
|
||||
private fsResult TryParseNull(out fsData data) {
|
||||
var fail = TryParseExact("null");
|
||||
|
||||
if ( fail.Succeeded ) {
|
||||
data = new fsData();
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
data = null;
|
||||
return fail;
|
||||
}
|
||||
|
||||
|
||||
private bool IsSeparator(char c) {
|
||||
return char.IsWhiteSpace(c) || c == ',' || c == '}' || c == ']';
|
||||
}
|
||||
|
||||
///<summary> Parses numbers that follow the regular expression [-+](\d+|\d*\.\d*)</summary>
|
||||
private fsResult TryParseNumber(out fsData data) {
|
||||
int start = _start;
|
||||
|
||||
// read until we get to a separator
|
||||
while (
|
||||
TryMoveNext() &&
|
||||
( HasValue() && IsSeparator(Character()) == false ) ) {
|
||||
}
|
||||
|
||||
// try to parse the value
|
||||
string numberString = _input.Substring(start, _start - start);
|
||||
|
||||
// double -- includes a .
|
||||
if ( numberString.Contains(".") || numberString.Contains("e") || numberString.Contains("E") ||
|
||||
numberString == "Infinity" || numberString == "-Infinity" || numberString == "NaN" ) {
|
||||
double doubleValue;
|
||||
if ( double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out doubleValue) == false ) {
|
||||
data = null;
|
||||
return MakeFailure("Bad double format with " + numberString);
|
||||
}
|
||||
|
||||
data = new fsData(doubleValue);
|
||||
return fsResult.Success;
|
||||
} else {
|
||||
Int64 intValue;
|
||||
if ( Int64.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out intValue) == false ) {
|
||||
data = null;
|
||||
return MakeFailure("Bad Int64 format with " + numberString);
|
||||
}
|
||||
|
||||
data = new fsData(intValue);
|
||||
return fsResult.Success;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly StringBuilder _cachedStringBuilder = new StringBuilder(256);
|
||||
///<summary> Parses a string</summary>
|
||||
private fsResult TryParseString(out string str) {
|
||||
_cachedStringBuilder.Length = 0;
|
||||
|
||||
// skip the first "
|
||||
if ( Character() != '"' || TryMoveNext() == false ) {
|
||||
str = string.Empty;
|
||||
return MakeFailure("Expected initial \" when parsing a string");
|
||||
}
|
||||
|
||||
// read until the next "
|
||||
while ( HasValue() && Character() != '\"' ) {
|
||||
char c = Character();
|
||||
|
||||
// escape if necessary
|
||||
if ( c == '\\' ) {
|
||||
char unescaped;
|
||||
var fail = TryUnescapeChar(out unescaped);
|
||||
if ( fail.Failed ) {
|
||||
str = string.Empty;
|
||||
return fail;
|
||||
}
|
||||
|
||||
_cachedStringBuilder.Append(unescaped);
|
||||
}
|
||||
|
||||
// no escaping necessary
|
||||
else {
|
||||
_cachedStringBuilder.Append(c);
|
||||
|
||||
// get the next character
|
||||
if ( TryMoveNext() == false ) {
|
||||
str = string.Empty;
|
||||
return MakeFailure("Unexpected end of input when reading a string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// skip the first "
|
||||
if ( HasValue() == false || Character() != '"' || TryMoveNext() == false ) {
|
||||
str = string.Empty;
|
||||
return MakeFailure("No closing \" when parsing a string");
|
||||
}
|
||||
|
||||
str = _cachedStringBuilder.ToString();
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
///<summary> Parses an array</summary>
|
||||
private fsResult TryParseArray(out fsData arr) {
|
||||
if ( Character() != '[' ) {
|
||||
arr = null;
|
||||
return MakeFailure("Expected initial [ when parsing an array");
|
||||
}
|
||||
|
||||
// skip '['
|
||||
if ( TryMoveNext() == false ) {
|
||||
arr = null;
|
||||
return MakeFailure("Unexpected end of input when parsing an array");
|
||||
}
|
||||
SkipSpace();
|
||||
|
||||
var result = new List<fsData>();
|
||||
|
||||
while ( HasValue() && Character() != ']' ) {
|
||||
// parse the element
|
||||
fsData element;
|
||||
var fail = RunParse(out element);
|
||||
if ( fail.Failed ) {
|
||||
arr = null;
|
||||
return fail;
|
||||
}
|
||||
|
||||
result.Add(element);
|
||||
|
||||
// parse the comma
|
||||
SkipSpace();
|
||||
if ( HasValue() && Character() == ',' ) {
|
||||
if ( TryMoveNext() == false ) break;
|
||||
SkipSpace();
|
||||
}
|
||||
}
|
||||
|
||||
// skip the final ]
|
||||
if ( HasValue() == false || Character() != ']' || TryMoveNext() == false ) {
|
||||
arr = null;
|
||||
return MakeFailure("No closing ] for array");
|
||||
}
|
||||
|
||||
arr = new fsData(result);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
private fsResult TryParseObject(out fsData obj) {
|
||||
if ( Character() != '{' ) {
|
||||
obj = null;
|
||||
return MakeFailure("Expected initial { when parsing an object");
|
||||
}
|
||||
|
||||
// skip '{'
|
||||
if ( TryMoveNext() == false ) {
|
||||
obj = null;
|
||||
return MakeFailure("Unexpected end of input when parsing an object");
|
||||
}
|
||||
SkipSpace();
|
||||
|
||||
var result = new Dictionary<string, fsData>(
|
||||
fsGlobalConfig.IsCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
while ( HasValue() && Character() != '}' ) {
|
||||
fsResult failure;
|
||||
|
||||
// parse the key
|
||||
SkipSpace();
|
||||
string key;
|
||||
failure = TryParseString(out key);
|
||||
if ( failure.Failed ) {
|
||||
obj = null;
|
||||
return failure;
|
||||
}
|
||||
SkipSpace();
|
||||
|
||||
// parse the ':' after the key
|
||||
if ( HasValue() == false || Character() != ':' || TryMoveNext() == false ) {
|
||||
obj = null;
|
||||
return MakeFailure("Expected : after key \"" + key + "\"");
|
||||
}
|
||||
SkipSpace();
|
||||
|
||||
// parse the value
|
||||
fsData value;
|
||||
failure = RunParse(out value);
|
||||
if ( failure.Failed ) {
|
||||
obj = null;
|
||||
return failure;
|
||||
}
|
||||
|
||||
result.Add(key, value);
|
||||
|
||||
// parse the comma
|
||||
SkipSpace();
|
||||
if ( HasValue() && Character() == ',' ) {
|
||||
if ( TryMoveNext() == false ) break;
|
||||
SkipSpace();
|
||||
}
|
||||
}
|
||||
|
||||
// skip the final }
|
||||
if ( HasValue() == false || Character() != '}' || TryMoveNext() == false ) {
|
||||
obj = null;
|
||||
return MakeFailure("No closing } for object");
|
||||
}
|
||||
|
||||
obj = new fsData(result);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
private fsResult RunParse(out fsData data) {
|
||||
SkipSpace();
|
||||
|
||||
if ( HasValue() == false ) {
|
||||
data = default(fsData);
|
||||
return MakeFailure("Unexpected end of input");
|
||||
}
|
||||
|
||||
switch ( Character() ) {
|
||||
case 'I': // Infinity
|
||||
case 'N': // NaN
|
||||
case '.':
|
||||
case '+':
|
||||
case '-':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9': return TryParseNumber(out data);
|
||||
case '"': {
|
||||
string str;
|
||||
fsResult fail = TryParseString(out str);
|
||||
if ( fail.Failed ) {
|
||||
data = null;
|
||||
return fail;
|
||||
}
|
||||
data = new fsData(str);
|
||||
return fsResult.Success;
|
||||
}
|
||||
case '[': return TryParseArray(out data);
|
||||
case '{': return TryParseObject(out data);
|
||||
case 't': return TryParseTrue(out data);
|
||||
case 'f': return TryParseFalse(out data);
|
||||
case 'n': return TryParseNull(out data);
|
||||
default:
|
||||
data = null;
|
||||
return MakeFailure("unable to parse; invalid token \"" + Character() + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Parses the specified input. Returns a failure state if parsing failed.</summary>
|
||||
public static fsResult Parse(string input, out fsData data) {
|
||||
if ( string.IsNullOrEmpty(input) ) {
|
||||
data = default(fsData);
|
||||
return fsResult.Fail("No input");
|
||||
}
|
||||
|
||||
var context = new fsJsonParser(input);
|
||||
return context.RunParse(out data);
|
||||
}
|
||||
|
||||
///<summary> Helper method for Parse that does not allow the error information to be recovered.</summary>
|
||||
public static fsData Parse(string input) {
|
||||
fsData data;
|
||||
Parse(input, out data).AssertSuccess();
|
||||
return data;
|
||||
}
|
||||
|
||||
private fsJsonParser(string input) {
|
||||
_input = input;
|
||||
_start = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1deb9a1c9eedbea4e953ba28be392351
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsJsonParser.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,275 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
public static class fsJsonPrinter
|
||||
{
|
||||
|
||||
///<summary> Inserts the given number of indents into the builder.</summary>
|
||||
private static void InsertSpacing(TextWriter stream, int count) {
|
||||
for ( int i = 0; i < count; ++i ) {
|
||||
stream.Write(" ");
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Escapes a string.</summary>
|
||||
private static string EscapeString(string str) {
|
||||
|
||||
// Escaping a string is pretty allocation heavy, so we try hard to not do it.
|
||||
bool needsEscape = false;
|
||||
for ( int i = 0; i < str.Length; ++i ) {
|
||||
char c = str[i];
|
||||
|
||||
// unicode code point
|
||||
int intChar = Convert.ToInt32(c);
|
||||
if ( intChar < 0 || intChar > 127 ) {
|
||||
needsEscape = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// standard escape character
|
||||
switch ( c ) {
|
||||
case '"':
|
||||
case '\\':
|
||||
case '\a':
|
||||
case '\b':
|
||||
case '\f':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\0':
|
||||
needsEscape = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( needsEscape ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( needsEscape == false ) {
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for ( int i = 0; i < str.Length; ++i ) {
|
||||
char c = str[i];
|
||||
|
||||
// unicode code point
|
||||
int intChar = Convert.ToInt32(c);
|
||||
if ( intChar < 0 || intChar > 127 ) {
|
||||
result.Append(string.Format("\\u{0:x4} ", intChar).Trim());
|
||||
continue;
|
||||
}
|
||||
|
||||
// standard escape character
|
||||
switch ( c ) {
|
||||
case '"': result.Append("\\\""); continue;
|
||||
case '\\': result.Append(@"\\"); continue;
|
||||
case '\a': result.Append(@"\a"); continue;
|
||||
case '\b': result.Append(@"\b"); continue;
|
||||
case '\f': result.Append(@"\f"); continue;
|
||||
case '\n': result.Append(@"\n"); continue;
|
||||
case '\r': result.Append(@"\r"); continue;
|
||||
case '\t': result.Append(@"\t"); continue;
|
||||
case '\0': result.Append(@"\0"); continue;
|
||||
}
|
||||
|
||||
// no escaping needed
|
||||
result.Append(c);
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private static void BuildCompressedString(fsData data, TextWriter stream) {
|
||||
switch ( data.Type ) {
|
||||
case fsDataType.Null:
|
||||
stream.Write("null");
|
||||
break;
|
||||
|
||||
case fsDataType.Boolean:
|
||||
if ( data.AsBool ) stream.Write("true");
|
||||
else stream.Write("false");
|
||||
break;
|
||||
|
||||
case fsDataType.Double:
|
||||
// doubles must *always* include a decimal
|
||||
stream.Write(ConvertDoubleToString(data.AsDouble));
|
||||
break;
|
||||
|
||||
case fsDataType.Int64:
|
||||
stream.Write(data.AsInt64);
|
||||
break;
|
||||
|
||||
case fsDataType.String:
|
||||
stream.Write('"');
|
||||
stream.Write(EscapeString(data.AsString));
|
||||
stream.Write('"');
|
||||
break;
|
||||
|
||||
case fsDataType.Object: {
|
||||
stream.Write('{');
|
||||
bool comma = false;
|
||||
foreach ( var entry in data.AsDictionary ) {
|
||||
if ( comma ) stream.Write(',');
|
||||
comma = true;
|
||||
stream.Write('"');
|
||||
stream.Write(entry.Key);
|
||||
stream.Write('"');
|
||||
stream.Write(":");
|
||||
BuildCompressedString(entry.Value, stream);
|
||||
}
|
||||
stream.Write('}');
|
||||
break;
|
||||
}
|
||||
|
||||
case fsDataType.Array: {
|
||||
stream.Write('[');
|
||||
bool comma = false;
|
||||
foreach ( var entry in data.AsList ) {
|
||||
if ( comma ) stream.Write(',');
|
||||
comma = true;
|
||||
BuildCompressedString(entry, stream);
|
||||
}
|
||||
stream.Write(']');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Formats this data into the given builder.</summary>
|
||||
private static void BuildPrettyString(fsData data, TextWriter stream, int depth) {
|
||||
switch ( data.Type ) {
|
||||
case fsDataType.Null:
|
||||
stream.Write("null");
|
||||
break;
|
||||
|
||||
case fsDataType.Boolean:
|
||||
if ( data.AsBool ) stream.Write("true");
|
||||
else stream.Write("false");
|
||||
break;
|
||||
|
||||
case fsDataType.Double:
|
||||
stream.Write(ConvertDoubleToString(data.AsDouble));
|
||||
break;
|
||||
|
||||
case fsDataType.Int64:
|
||||
stream.Write(data.AsInt64);
|
||||
break;
|
||||
|
||||
|
||||
case fsDataType.String:
|
||||
stream.Write('"');
|
||||
stream.Write(EscapeString(data.AsString));
|
||||
stream.Write('"');
|
||||
break;
|
||||
|
||||
case fsDataType.Object: {
|
||||
stream.Write('{');
|
||||
stream.WriteLine();
|
||||
bool comma = false;
|
||||
foreach ( var entry in data.AsDictionary ) {
|
||||
if ( comma ) {
|
||||
stream.Write(',');
|
||||
stream.WriteLine();
|
||||
}
|
||||
comma = true;
|
||||
InsertSpacing(stream, depth + 1);
|
||||
stream.Write('"');
|
||||
stream.Write(entry.Key);
|
||||
stream.Write('"');
|
||||
stream.Write(": ");
|
||||
BuildPrettyString(entry.Value, stream, depth + 1);
|
||||
}
|
||||
stream.WriteLine();
|
||||
InsertSpacing(stream, depth);
|
||||
stream.Write('}');
|
||||
break;
|
||||
}
|
||||
|
||||
case fsDataType.Array:
|
||||
// special case for empty lists; we don't put an empty line between the brackets
|
||||
if ( data.AsList.Count == 0 ) {
|
||||
stream.Write("[]");
|
||||
} else {
|
||||
bool comma = false;
|
||||
|
||||
stream.Write('[');
|
||||
stream.WriteLine();
|
||||
foreach ( var entry in data.AsList ) {
|
||||
if ( comma ) {
|
||||
stream.Write(',');
|
||||
stream.WriteLine();
|
||||
}
|
||||
comma = true;
|
||||
InsertSpacing(stream, depth + 1);
|
||||
BuildPrettyString(entry, stream, depth + 1);
|
||||
}
|
||||
stream.WriteLine();
|
||||
InsertSpacing(stream, depth);
|
||||
stream.Write(']');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Returns fsData to json pretty or not</summary>
|
||||
public static string ToJson(fsData data, bool pretty) {
|
||||
if ( pretty ) { return PrettyJson(data); }
|
||||
return CompressedJson(data);
|
||||
}
|
||||
|
||||
///<summary> Writes the pretty JSON output data to the given stream.</summary>
|
||||
public static void PrettyJson(fsData data, TextWriter outputStream) {
|
||||
BuildPrettyString(data, outputStream, 0);
|
||||
}
|
||||
|
||||
///<summary> Returns the data in a pretty printed JSON format.</summary>
|
||||
public static string PrettyJson(fsData data) {
|
||||
var sb = new StringBuilder();
|
||||
using ( var writer = new StringWriter(sb) ) {
|
||||
BuildPrettyString(data, writer, 0);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Writes the compressed JSON output data to the given stream.</summary>
|
||||
public static void CompressedJson(fsData data, StreamWriter outputStream) {
|
||||
BuildCompressedString(data, outputStream);
|
||||
}
|
||||
|
||||
///<summary> Returns the data in a relatively compressed JSON format.</summary>
|
||||
public static string CompressedJson(fsData data) {
|
||||
var sb = new StringBuilder();
|
||||
using ( var writer = new StringWriter(sb) ) {
|
||||
BuildCompressedString(data, writer);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Utility method that converts a double to a string.</summary>
|
||||
private static string ConvertDoubleToString(double d) {
|
||||
if ( Double.IsInfinity(d) || Double.IsNaN(d) )
|
||||
return d.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
string doubledString = d.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
// NOTE/HACK: If we don't serialize with a period or an exponent,
|
||||
// then the number will be deserialized as an Int64, not a double.
|
||||
if ( doubledString.Contains(".") == false &&
|
||||
doubledString.Contains("e") == false &&
|
||||
doubledString.Contains("E") == false ) {
|
||||
doubledString += ".0";
|
||||
}
|
||||
|
||||
return doubledString;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdbea492eb6faf24799cb4d10cc56762
|
||||
timeCreated: 1458897574
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsJsonPrinter.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
///<summary> A field on a MetaType.</summary>
|
||||
public class fsMetaProperty
|
||||
{
|
||||
|
||||
///<summary> Internal handle to the reflected member.</summary>
|
||||
public FieldInfo Field { get; private set; }
|
||||
///<summary> The serialized name of the property, as it should appear in JSON.</summary>
|
||||
public string JsonName { get; private set; }
|
||||
///<summary> The type of value that is stored inside of the property.</summary>
|
||||
public Type StorageType { get { return Field.FieldType; } }
|
||||
///<summary> The real name of the member info.</summary>
|
||||
public string MemberName { get { return Field.Name; } }
|
||||
///<summary> Is the property read only?</summary>
|
||||
public bool ReadOnly { get; private set; }
|
||||
///<summary> Is the property write only?</summary>
|
||||
public bool WriteOnly { get; private set; }
|
||||
///<summary> Make instance automatically?</summary>
|
||||
public bool AutoInstance { get; private set; }
|
||||
///<summary> Serialize as reference?</summary>
|
||||
public bool AsReference { get; private set; }
|
||||
|
||||
internal fsMetaProperty(FieldInfo field) {
|
||||
this.Field = field;
|
||||
var attr = Field.RTGetAttribute<fsSerializeAsAttribute>(true);
|
||||
this.JsonName = attr != null && !string.IsNullOrEmpty(attr.Name) ? attr.Name : field.Name;
|
||||
this.ReadOnly = Field.RTIsDefined<fsReadOnlyAttribute>(true);
|
||||
this.WriteOnly = Field.RTIsDefined<fsWriteOnlyAttribute>(true);
|
||||
var autoInstanceAtt = StorageType.RTGetAttribute<fsAutoInstance>(true);
|
||||
this.AutoInstance = autoInstanceAtt != null && autoInstanceAtt.makeInstance && !StorageType.IsAbstract;
|
||||
this.AsReference = Field.RTIsDefined<fsSerializeAsReference>(true);
|
||||
}
|
||||
|
||||
///<summary> Reads a value from the property that this MetaProperty represents, using the given object instance as the context.</summary>
|
||||
public object Read(object context) {
|
||||
return Field.GetValue(context);
|
||||
}
|
||||
|
||||
///<summary> Writes a value to the property that this MetaProperty represents, using given object instance as the context.</summary>
|
||||
public void Write(object context, object value) {
|
||||
Field.SetValue(context, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d121eeff08701d442900f21e5ef0736e
|
||||
timeCreated: 1458897574
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsMetaProperty.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
///<summary> MetaType contains metadata about a type. This is used by the reflection serializer.</summary>
|
||||
public class fsMetaType
|
||||
{
|
||||
|
||||
private static Dictionary<Type, fsMetaType> _metaTypes = new Dictionary<Type, fsMetaType>();
|
||||
private static Dictionary<Type, object> _defaultInstances = new Dictionary<Type, object>();
|
||||
|
||||
///<summary> Return MetaType</summary>
|
||||
public static fsMetaType Get(Type type) {
|
||||
fsMetaType metaType;
|
||||
if ( _metaTypes.TryGetValue(type, out metaType) == false ) {
|
||||
metaType = new fsMetaType(type);
|
||||
_metaTypes[type] = metaType;
|
||||
}
|
||||
|
||||
return metaType;
|
||||
}
|
||||
|
||||
///<summary> Clears out the cached type results</summary>
|
||||
public static void FlushMem() {
|
||||
_metaTypes = new Dictionary<Type, fsMetaType>();
|
||||
_defaultInstances = new Dictionary<Type, object>();
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
private delegate object ObjectGenerator();
|
||||
|
||||
private ObjectGenerator generator;
|
||||
public Type reflectedType { get; private set; }
|
||||
public fsMetaProperty[] Properties { get; private set; }
|
||||
public bool DeserializeOverwriteRequest { get; private set; }
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
//...
|
||||
private fsMetaType(Type reflectedType) {
|
||||
this.reflectedType = reflectedType;
|
||||
this.generator = GetGenerator(reflectedType);
|
||||
|
||||
var properties = new List<fsMetaProperty>();
|
||||
CollectProperties(properties, reflectedType);
|
||||
this.Properties = properties.ToArray();
|
||||
|
||||
//TODO: Use it?
|
||||
// this.DeserializeOverwriteRequest = reflectedType.RTIsDefined<fsDeserializeOverwrite>(true);
|
||||
}
|
||||
|
||||
//...
|
||||
static void CollectProperties(List<fsMetaProperty> properties, Type reflectedType) {
|
||||
FieldInfo[] fields = reflectedType.RTGetFields();
|
||||
for ( var i = 0; i < fields.Length; i++ ) {
|
||||
var field = fields[i];
|
||||
|
||||
if ( field.DeclaringType != reflectedType ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( CanSerializeField(field) ) {
|
||||
properties.Add(new fsMetaProperty(field));
|
||||
}
|
||||
}
|
||||
|
||||
if ( reflectedType.BaseType != null ) {
|
||||
CollectProperties(properties, reflectedType.BaseType);
|
||||
}
|
||||
}
|
||||
|
||||
//...
|
||||
public static bool CanSerializeField(FieldInfo field) {
|
||||
|
||||
// We don't serialize static fields
|
||||
if ( field.IsStatic ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We don't serialize delegates
|
||||
if ( typeof(Delegate).IsAssignableFrom(field.FieldType) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
if ( field.RTIsDefined<fsIgnoreInBuildAttribute>(true) ) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// We don't serialize compiler generated fields.
|
||||
if ( field.RTIsDefined<CompilerGeneratedAttribute>(true) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We don't serialize members annotated with any of the ignore serialize attributes
|
||||
for ( var i = 0; i < fsGlobalConfig.IgnoreSerializeAttributes.Length; i++ ) {
|
||||
if ( field.RTIsDefined(fsGlobalConfig.IgnoreSerializeAttributes[i], true) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( field.IsPublic ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for ( var i = 0; i < fsGlobalConfig.SerializeAttributes.Length; i++ ) {
|
||||
if ( field.RTIsDefined(fsGlobalConfig.SerializeAttributes[i], true) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///<summary> Create generator</summary>
|
||||
static ObjectGenerator GetGenerator(Type reflectedType) {
|
||||
|
||||
if ( reflectedType.IsInterface || reflectedType.IsAbstract ) {
|
||||
return () => { throw new Exception("Cannot create an instance of an interface or abstract type for " + reflectedType); };
|
||||
}
|
||||
|
||||
if ( typeof(UnityEngine.ScriptableObject).IsAssignableFrom(reflectedType) ) {
|
||||
return () => { return UnityEngine.ScriptableObject.CreateInstance(reflectedType); };
|
||||
}
|
||||
|
||||
if ( reflectedType.IsArray ) {
|
||||
// we have to start with a size zero array otherwise it will have invalid data inside of it
|
||||
return () => { return Array.CreateInstance(reflectedType.GetElementType(), 0); };
|
||||
}
|
||||
|
||||
if ( reflectedType == typeof(string) ) {
|
||||
return () => { return string.Empty; };
|
||||
}
|
||||
|
||||
if ( reflectedType.IsValueType || reflectedType.RTIsDefined<fsUninitialized>(true) || !HasDefaultConstructor(reflectedType) ) {
|
||||
return () => { return System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(reflectedType); };
|
||||
}
|
||||
|
||||
// var exp = Expression.Lambda<Func<object>>(Expression.New(reflectedType)).Compile();
|
||||
// return () => { return exp(); };
|
||||
|
||||
return () => { try { return Activator.CreateInstance(reflectedType, /*nonPublic:*/ true); } catch { return null; } };
|
||||
}
|
||||
|
||||
//...
|
||||
static bool HasDefaultConstructor(Type reflectedType) {
|
||||
// arrays are considered to have a default constructor
|
||||
if ( reflectedType.IsArray ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// value types (ie, structs) always have a default constructor
|
||||
if ( reflectedType.IsValueType ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// consider private constructors as well
|
||||
return reflectedType.RTGetDefaultConstructor() != null;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Returns a *cached* default instance of target type This is mostly used for comparing default serialization properties</summary>
|
||||
public object GetDefaultInstance() {
|
||||
object instance = null;
|
||||
if ( _defaultInstances.TryGetValue(reflectedType, out instance) ) {
|
||||
return instance;
|
||||
}
|
||||
return _defaultInstances[reflectedType] = CreateInstance();
|
||||
}
|
||||
|
||||
///<summary> Creates a new instance of the type that this metadata points back to.</summary>
|
||||
public object CreateInstance() {
|
||||
if ( generator != null ) { return generator(); }
|
||||
throw new Exception("Cant create instance generator for " + reflectedType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6055c8d075412e4ea6162755a736ab1
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsMetaType.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Enables injecting code before/after an object has been serialized. This is most
|
||||
/// useful if you want to run the default serialization process but apply a pre/post
|
||||
/// processing step.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Multiple object processors can be active at the same time. When running they are
|
||||
/// called in a "nested" fashion - if we have processor1 and process2 added to the
|
||||
/// serializer in that order (p1 then p2), then the execution order will be
|
||||
/// p1#Before p2#Before /serialization/ p2#After p1#After.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public abstract class fsObjectProcessor
|
||||
{
|
||||
/// Is the processor interested in objects of the given type?
|
||||
/// </summary>
|
||||
/// <param name="type">The given type.</param>
|
||||
/// <returns>True if the processor should be applied, false otherwise.</returns>
|
||||
public virtual bool CanProcess(Type type) { throw new NotImplementedException(); }
|
||||
|
||||
/// <summary>
|
||||
/// Called before serialization.
|
||||
/// </summary>
|
||||
/// <param name="storageType">The field/property type that is storing the instance.</param>
|
||||
/// <param name="instance">The type of the instance.</param>
|
||||
public virtual void OnBeforeSerialize(Type storageType, object instance) { }
|
||||
|
||||
/// <summary>
|
||||
/// Called after serialization.
|
||||
/// </summary>
|
||||
/// <param name="storageType">The field/property type that is storing the instance.</param>
|
||||
/// <param name="instance">The type of the instance.</param>
|
||||
/// <param name="data">The data that was serialized.</param>
|
||||
public virtual void OnAfterSerialize(Type storageType, object instance, ref fsData data) { }
|
||||
|
||||
/// <summary>
|
||||
/// Called before deserialization.
|
||||
/// </summary>
|
||||
/// <param name="storageType">The field/property type that is storing the instance.</param>
|
||||
/// <param name="data">The data that will be used for deserialization.</param>
|
||||
public virtual void OnBeforeDeserialize(Type storageType, ref fsData data) { }
|
||||
|
||||
/// <summary>
|
||||
/// Called before deserialization has begun but *after* the object instance has been created. This will get
|
||||
/// invoked even if the user passed in an existing instance.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// **IMPORTANT**: The actual instance that gets passed here is *not* guaranteed to be an a subtype of storageType, since
|
||||
/// the value for instance is whatever the active converter returned for CreateInstance() - ie, some converters will return
|
||||
/// dummy types in CreateInstance() if instance creation cannot be separated from deserialization (ie, KeyValuePair).
|
||||
/// </remarks>
|
||||
/// <param name="storageType">The field/property type that is storing the instance.</param>
|
||||
/// <param name="instance">The created object instance. No deserialization has been applied to it.</param>
|
||||
/// <param name="data">The data that will be used for deserialization.</param>
|
||||
public virtual void OnBeforeDeserializeAfterInstanceCreation(Type storageType, object instance, ref fsData data) { }
|
||||
|
||||
/// <summary>
|
||||
/// Called after deserialization.
|
||||
/// </summary>
|
||||
/// <param name="storageType">The field/property type that is storing the instance.</param>
|
||||
/// <param name="instance">The type of the instance.</param>
|
||||
public virtual void OnAfterDeserialize(Type storageType, object instance) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5f9a3782591e9d4bb9fe8200327f3ec
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsObjectProcessor.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
///<summary> The result of some sort of operation. A result is either successful or not, but if it is successful then there may be a set of warnings/messages associated with it. These warnings describe the performed error recovery operations.</summary>
|
||||
public struct fsResult
|
||||
{
|
||||
|
||||
// We cache the empty string array so we can unify some collections processing code.
|
||||
private static readonly string[] EmptyStringArray = { };
|
||||
|
||||
///<summary> Is this result successful?</summary>
|
||||
private bool _success;
|
||||
|
||||
///<summary> The warning or error messages associated with the result if any.</summary>
|
||||
private List<string> _messages;
|
||||
|
||||
///<summary> A successful result.</summary>
|
||||
public static fsResult Success = new fsResult { _success = true };
|
||||
|
||||
///<summary> Create a result that is successful but contains the given warning message.</summary>
|
||||
public static fsResult Warn(string warning) {
|
||||
return new fsResult
|
||||
{
|
||||
_success = true,
|
||||
_messages = new List<string> { warning }
|
||||
};
|
||||
}
|
||||
|
||||
///<summary> Create a result that failed.</summary>
|
||||
public static fsResult Fail(string warning) {
|
||||
return new fsResult
|
||||
{
|
||||
_success = false,
|
||||
_messages = new List<string> { warning }
|
||||
};
|
||||
}
|
||||
|
||||
///<summary> Adds a new message to this result.</summary>
|
||||
public void AddMessage(string message) {
|
||||
if ( _messages == null ) { _messages = new List<string>(); }
|
||||
_messages.Add(message);
|
||||
}
|
||||
|
||||
///<summary> Adds only the messages from the other result into this result, ignoring the success/failure status of the other result.</summary>
|
||||
public void AddMessages(fsResult result) {
|
||||
if ( result._messages == null ) { return; }
|
||||
if ( _messages == null ) { _messages = new List<string>(); }
|
||||
_messages.AddRange(result._messages);
|
||||
}
|
||||
|
||||
///<summary> Merges the other result into this one. If the other result failed, then this one too will have failed.</summary>
|
||||
fsResult Merge(fsResult other) {
|
||||
// Copy success/messages over
|
||||
_success = _success && other._success;
|
||||
if ( other._messages != null ) {
|
||||
if ( _messages == null ) _messages = new List<string>(other._messages);
|
||||
else _messages.AddRange(other._messages);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
///<summary> Only use this as +=!</summary>
|
||||
public static fsResult operator +(fsResult a, fsResult b) {
|
||||
return a.Merge(b);
|
||||
}
|
||||
|
||||
///<summary> Did this result fail? If so, you can see the reasons why in `RawMessages`.</summary>
|
||||
public bool Failed { get { return _success == false; } }
|
||||
|
||||
///<summary> Was the result a success? Note that even successful operations may have warning messages (`RawMessages`) associated with them.</summary>
|
||||
public bool Succeeded { get { return _success; } }
|
||||
|
||||
///<summary> Does this result have any warnings? This says nothing about if it failed or succeeded, just if it has warning messages associated with it.</summary>
|
||||
public bool HasWarnings { get { return _messages != null && _messages.Any(); } }
|
||||
|
||||
///<summary> A simply utility method that will assert that this result is successful. If it is not, then an exception is thrown.</summary>
|
||||
public fsResult AssertSuccess() {
|
||||
if ( Failed ) { throw AsException; }
|
||||
return this;
|
||||
}
|
||||
|
||||
///<summary> A simple utility method that will assert that this result is successful and that there are no warning messages. This throws an exception if either of those asserts are false.</summary>
|
||||
public fsResult AssertSuccessWithoutWarnings() {
|
||||
if ( Failed || RawMessages.Any() ) { throw AsException; }
|
||||
return this;
|
||||
}
|
||||
|
||||
///<summary> Utility method to convert the result to an exception. This method is only defined is `Failed` returns true.</summary>
|
||||
public Exception AsException {
|
||||
get
|
||||
{
|
||||
if ( !Failed && !RawMessages.Any() ) throw new Exception("Only a failed result can be converted to an exception");
|
||||
return new Exception(FormattedMessages);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> RawMessages {
|
||||
get
|
||||
{
|
||||
if ( _messages != null ) {
|
||||
return _messages;
|
||||
}
|
||||
return EmptyStringArray;
|
||||
}
|
||||
}
|
||||
|
||||
public string FormattedMessages {
|
||||
get
|
||||
{
|
||||
return string.Join(",\n", RawMessages.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return FormattedMessages;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ce5d190483269b40bb75a3937f869bd
|
||||
timeCreated: 1458897573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsResult.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,712 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ParadoxNotion.Serialization.FullSerializer.Internal;
|
||||
using ParadoxNotion.Serialization.FullSerializer.Internal.DirectConverters;
|
||||
|
||||
namespace ParadoxNotion.Serialization.FullSerializer
|
||||
{
|
||||
|
||||
///<summary>*Heavily* modified FullSerializer</summary>
|
||||
public class fsSerializer
|
||||
{
|
||||
public const string KEY_OBJECT_REFERENCE = "$ref";
|
||||
public const string KEY_OBJECT_DEFINITION = "$id";
|
||||
public const string KEY_INSTANCE_TYPE = "$type";
|
||||
public const string KEY_VERSION = "$version";
|
||||
public const string KEY_CONTENT = "$content";
|
||||
|
||||
///<summary> Returns true if the given key is a special keyword that full serializer uses to add additional metadata on top of the emitted JSON.</summary>
|
||||
public static bool IsReservedKeyword(string key) {
|
||||
switch ( key ) {
|
||||
case ( KEY_OBJECT_REFERENCE ): return true;
|
||||
case ( KEY_OBJECT_DEFINITION ): return true;
|
||||
case ( KEY_INSTANCE_TYPE ): return true;
|
||||
case ( KEY_VERSION ): return true;
|
||||
case ( KEY_CONTENT ): return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///<summary>Irriversibly removes all meta data</summary>
|
||||
public static void RemoveMetaData(ref fsData data) {
|
||||
if ( data.IsDictionary ) {
|
||||
data.AsDictionary.Remove(KEY_OBJECT_REFERENCE);
|
||||
data.AsDictionary.Remove(KEY_OBJECT_DEFINITION);
|
||||
data.AsDictionary.Remove(KEY_INSTANCE_TYPE);
|
||||
data.AsDictionary.Remove(KEY_VERSION);
|
||||
data.AsDictionary.Remove(KEY_CONTENT);
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Ensures that the data is a dictionary. If it is not, then it is wrapped inside of one.</summary>
|
||||
private static void EnsureDictionary(ref fsData data) {
|
||||
if ( data.IsDictionary == false ) {
|
||||
var existingData = data.Clone();
|
||||
data.BecomeDictionary();
|
||||
data.AsDictionary[KEY_CONTENT] = existingData;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsObjectReference(fsData data) {
|
||||
if ( data.IsDictionary == false ) return false;
|
||||
return data.AsDictionary.ContainsKey(KEY_OBJECT_REFERENCE);
|
||||
}
|
||||
private static bool IsObjectDefinition(fsData data) {
|
||||
if ( data.IsDictionary == false ) return false;
|
||||
return data.AsDictionary.ContainsKey(KEY_OBJECT_DEFINITION);
|
||||
}
|
||||
private static bool IsVersioned(fsData data) {
|
||||
if ( data.IsDictionary == false ) return false;
|
||||
return data.AsDictionary.ContainsKey(KEY_VERSION);
|
||||
}
|
||||
private static bool IsTypeSpecified(fsData data) {
|
||||
if ( data.IsDictionary == false ) return false;
|
||||
return data.AsDictionary.ContainsKey(KEY_INSTANCE_TYPE);
|
||||
}
|
||||
private static bool IsWrappedData(fsData data) {
|
||||
if ( data.IsDictionary == false ) return false;
|
||||
return data.AsDictionary.ContainsKey(KEY_CONTENT);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
private static void Invoke_OnBeforeSerialize(List<fsObjectProcessor> processors, Type storageType, object instance) {
|
||||
for ( int i = 0; i < processors.Count; ++i ) {
|
||||
processors[i].OnBeforeSerialize(storageType, instance);
|
||||
}
|
||||
|
||||
//!!Call only on non-Unity objects, since they are called back anyways by Unity!!
|
||||
if ( instance is UnityEngine.ISerializationCallbackReceiver && !( instance is UnityEngine.Object ) ) {
|
||||
( (UnityEngine.ISerializationCallbackReceiver)instance ).OnBeforeSerialize();
|
||||
}
|
||||
}
|
||||
private static void Invoke_OnAfterSerialize(List<fsObjectProcessor> processors, Type storageType, object instance, ref fsData data) {
|
||||
// We run the after calls in reverse order; this significantly reduces the interaction burden between
|
||||
// multiple processors - it makes each one much more independent and ignorant of the other ones.
|
||||
for ( int i = processors.Count - 1; i >= 0; --i ) {
|
||||
processors[i].OnAfterSerialize(storageType, instance, ref data);
|
||||
}
|
||||
}
|
||||
private static void Invoke_OnBeforeDeserialize(List<fsObjectProcessor> processors, Type storageType, ref fsData data) {
|
||||
for ( int i = 0; i < processors.Count; ++i ) {
|
||||
processors[i].OnBeforeDeserialize(storageType, ref data);
|
||||
}
|
||||
}
|
||||
private static void Invoke_OnBeforeDeserializeAfterInstanceCreation(List<fsObjectProcessor> processors, Type storageType, object instance, ref fsData data) {
|
||||
for ( int i = 0; i < processors.Count; ++i ) {
|
||||
processors[i].OnBeforeDeserializeAfterInstanceCreation(storageType, instance, ref data);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Invoke_OnAfterDeserialize(List<fsObjectProcessor> processors, Type storageType, object instance) {
|
||||
for ( int i = processors.Count - 1; i >= 0; --i ) {
|
||||
processors[i].OnAfterDeserialize(storageType, instance);
|
||||
}
|
||||
|
||||
//!!Call only on non-Unity objects, since they are called back anyways by Unity!!
|
||||
if ( instance is UnityEngine.ISerializationCallbackReceiver && !( instance is UnityEngine.Object ) ) {
|
||||
( (UnityEngine.ISerializationCallbackReceiver)instance ).OnAfterDeserialize();
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> This manages instance writing so that we do not write unnecessary $id fields. We only need to write out an $id field when there is a corresponding $ref field. This is able to write $id references lazily because the fsData instance is not actually written out to text until we have entirely finished serializing it.</summary>
|
||||
internal class fsLazyCycleDefinitionWriter
|
||||
{
|
||||
private Dictionary<int, fsData> _pendingDefinitions = new Dictionary<int, fsData>();
|
||||
private HashSet<int> _references = new HashSet<int>();
|
||||
|
||||
public void WriteDefinition(int id, fsData data) {
|
||||
if ( _references.Contains(id) ) {
|
||||
EnsureDictionary(ref data);
|
||||
data.AsDictionary[KEY_OBJECT_DEFINITION] = new fsData(id.ToString());
|
||||
} else {
|
||||
_pendingDefinitions[id] = data;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteReference(int id, Dictionary<string, fsData> dict) {
|
||||
fsData data;
|
||||
if ( _pendingDefinitions.TryGetValue(id, out data) ) {
|
||||
EnsureDictionary(ref data);
|
||||
data.AsDictionary[KEY_OBJECT_DEFINITION] = new fsData(id.ToString());
|
||||
_pendingDefinitions.Remove(id);
|
||||
} else { _references.Add(id); }
|
||||
|
||||
// Write the reference
|
||||
dict[KEY_OBJECT_REFERENCE] = new fsData(id.ToString());
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
_pendingDefinitions.Clear();
|
||||
_references.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
///<summary> Converter type to converter instance lookup table. This could likely be stored inside of _cachedConverters, but there is a semantic difference because _cachedConverters goes from serialized type to converter.</summary>
|
||||
private Dictionary<Type, fsBaseConverter> _cachedOverrideConverterInstances;
|
||||
///<summary> A cache from type to it's converter.</summary>
|
||||
private Dictionary<Type, fsBaseConverter> _cachedConverters;
|
||||
///<summary> Converters that can be used for type registration.</summary>
|
||||
private readonly List<fsConverter> _availableConverters;
|
||||
///<summary> Direct converters (optimized _converters). We use these so we don't have to perform a scan through every item in _converters and can instead just do an O(1) lookup. This is potentially important to perf when there are a ton of direct converters.</summary>
|
||||
private readonly Dictionary<Type, fsDirectConverter> _availableDirectConverters;
|
||||
|
||||
///<summary> Processors that are available.</summary>
|
||||
private readonly List<fsObjectProcessor> _processors;
|
||||
///<summary> A cache from type to the set of processors that are interested in it.</summary>
|
||||
private Dictionary<Type, List<fsObjectProcessor>> _cachedProcessors;
|
||||
|
||||
///<summary> Reference manager for cycle detection.</summary>
|
||||
private fsCyclicReferenceManager _references;
|
||||
private fsLazyCycleDefinitionWriter _lazyReferenceWriter;
|
||||
///<summary> Collectors get callbacks on child serialization/deserialization</summary>
|
||||
private Stack<ISerializationCollector> _collectors;
|
||||
///<summary> Collector collection child depth (local to each collector)</summary>
|
||||
private int _collectableDepth;
|
||||
|
||||
///<summary> A UnityObject references database for serialization/deserialization</summary>
|
||||
public List<UnityEngine.Object> ReferencesDatabase { get; set; }
|
||||
///<summary> Ignore cycle references?</summary> //TODO: Refactor cycle references to avoid doing this.
|
||||
public bool IgnoreSerializeCycleReferences { get; set; }
|
||||
///<summary> An event raised before an object has been serialized given the object</summary>
|
||||
public event Action<object> onBeforeObjectSerialized;
|
||||
///<summary> An event raised after an object has been serialized given the object and the serialization data</summary>
|
||||
public event Action<object, fsData> onAfterObjectSerialized;
|
||||
|
||||
|
||||
//...
|
||||
public fsSerializer() {
|
||||
_cachedOverrideConverterInstances = new Dictionary<Type, fsBaseConverter>();
|
||||
_cachedConverters = new Dictionary<Type, fsBaseConverter>();
|
||||
_cachedProcessors = new Dictionary<Type, List<fsObjectProcessor>>();
|
||||
|
||||
_references = new fsCyclicReferenceManager();
|
||||
_lazyReferenceWriter = new fsLazyCycleDefinitionWriter();
|
||||
_collectors = new Stack<ISerializationCollector>();
|
||||
|
||||
// note: The order here is important. Items at the beginning of this
|
||||
// list will be used before converters at the end. Converters
|
||||
// added via AddConverter() are added to the front of the list.
|
||||
_availableConverters = new List<fsConverter>
|
||||
{
|
||||
new fsUnityObjectConverter { Serializer = this },
|
||||
new fsTypeConverter { Serializer = this },
|
||||
new fsEnumConverter { Serializer = this },
|
||||
new fsPrimitiveConverter { Serializer = this },
|
||||
new fsArrayConverter { Serializer = this },
|
||||
new fsDictionaryConverter { Serializer = this },
|
||||
new fsListConverter { Serializer = this },
|
||||
new fsReflectedConverter { Serializer = this }
|
||||
};
|
||||
_availableDirectConverters = new Dictionary<Type, fsDirectConverter>();
|
||||
|
||||
_processors = new List<fsObjectProcessor>();
|
||||
|
||||
//DirectConverters. Add manually for performance
|
||||
AddConverter(new AnimationCurve_DirectConverter());
|
||||
AddConverter(new Bounds_DirectConverter());
|
||||
AddConverter(new GUIStyleState_DirectConverter());
|
||||
AddConverter(new GUIStyle_DirectConverter());
|
||||
AddConverter(new Gradient_DirectConverter());
|
||||
AddConverter(new Keyframe_DirectConverter());
|
||||
AddConverter(new LayerMask_DirectConverter());
|
||||
AddConverter(new RectOffset_DirectConverter());
|
||||
AddConverter(new Rect_DirectConverter());
|
||||
|
||||
AddConverter(new Vector2Int_DirectConverter());
|
||||
AddConverter(new Vector3Int_DirectConverter());
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
//Cleanup cycle references.
|
||||
//This is done to ensure that a problem in one serialization does not transfer to others.
|
||||
public void PurgeTemporaryData() {
|
||||
_references.Clear();
|
||||
_lazyReferenceWriter.Clear();
|
||||
_collectors.Clear();
|
||||
}
|
||||
|
||||
///<summary> Fetches all of the processors for the given type.</summary>
|
||||
private List<fsObjectProcessor> GetProcessors(Type type) {
|
||||
List<fsObjectProcessor> processors;
|
||||
if ( _cachedProcessors.TryGetValue(type, out processors) ) {
|
||||
return processors;
|
||||
}
|
||||
|
||||
// Check to see if the user has defined a custom processor for the type. If they
|
||||
// have, then we don't need to scan through all of the processor to check which
|
||||
// one can process the type; instead, we directly use the specified processor.
|
||||
var attr = type.RTGetAttribute<fsObjectAttribute>(true);
|
||||
if ( attr != null && attr.Processor != null ) {
|
||||
var processor = (fsObjectProcessor)Activator.CreateInstance(attr.Processor);
|
||||
processors = new List<fsObjectProcessor>();
|
||||
processors.Add(processor);
|
||||
_cachedProcessors[type] = processors;
|
||||
} else if ( _cachedProcessors.TryGetValue(type, out processors) == false ) {
|
||||
processors = new List<fsObjectProcessor>();
|
||||
|
||||
for ( int i = 0; i < _processors.Count; ++i ) {
|
||||
var processor = _processors[i];
|
||||
if ( processor.CanProcess(type) ) {
|
||||
processors.Add(processor);
|
||||
}
|
||||
}
|
||||
|
||||
_cachedProcessors[type] = processors;
|
||||
}
|
||||
|
||||
return processors;
|
||||
}
|
||||
|
||||
///<summary> Adds a new converter that can be used to customize how an object is serialized and deserialized.</summary>
|
||||
public void AddConverter(fsBaseConverter converter) {
|
||||
if ( converter.Serializer != null ) {
|
||||
throw new InvalidOperationException("Cannot add a single converter instance to " +
|
||||
"multiple fsConverters -- please construct a new instance for " + converter);
|
||||
}
|
||||
|
||||
if ( converter is fsDirectConverter ) {
|
||||
var directConverter = (fsDirectConverter)converter;
|
||||
_availableDirectConverters[directConverter.ModelType] = directConverter;
|
||||
} else if ( converter is fsConverter ) {
|
||||
_availableConverters.Insert(0, (fsConverter)converter);
|
||||
} else {
|
||||
throw new InvalidOperationException("Unable to add converter " + converter +
|
||||
"; the type association strategy is unknown. Please use either " +
|
||||
"fsDirectConverter or fsConverter as your base type.");
|
||||
}
|
||||
|
||||
converter.Serializer = this;
|
||||
_cachedConverters = new Dictionary<Type, fsBaseConverter>();
|
||||
}
|
||||
|
||||
///<summary> Fetches a converter that can serialize/deserialize the given type.</summary>
|
||||
private fsBaseConverter GetConverter(Type type, Type overrideConverterType) {
|
||||
|
||||
// Use an override converter type instead if that's what the user has requested.
|
||||
if ( overrideConverterType != null ) {
|
||||
fsBaseConverter overrideConverter;
|
||||
if ( _cachedOverrideConverterInstances.TryGetValue(overrideConverterType, out overrideConverter) == false ) {
|
||||
overrideConverter = (fsBaseConverter)Activator.CreateInstance(overrideConverterType);
|
||||
overrideConverter.Serializer = this;
|
||||
_cachedOverrideConverterInstances[overrideConverterType] = overrideConverter;
|
||||
}
|
||||
|
||||
return overrideConverter;
|
||||
}
|
||||
|
||||
// Try to lookup an existing converter.
|
||||
fsBaseConverter converter;
|
||||
if ( _cachedConverters.TryGetValue(type, out converter) ) {
|
||||
return converter;
|
||||
}
|
||||
|
||||
// Check to see if the user has defined a custom converter for the type. If they
|
||||
// have, then we don't need to scan through all of the converters to check which
|
||||
// one can process the type; instead, we directly use the specified converter.
|
||||
{
|
||||
var attr = type.RTGetAttribute<fsObjectAttribute>(true);
|
||||
if ( attr != null && attr.Converter != null ) {
|
||||
converter = (fsBaseConverter)Activator.CreateInstance(attr.Converter);
|
||||
converter.Serializer = this;
|
||||
return _cachedConverters[type] = converter;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for a [fsForward] attribute.
|
||||
{
|
||||
var attr = type.RTGetAttribute<fsForwardAttribute>(true);
|
||||
if ( attr != null ) {
|
||||
converter = new fsForwardConverter(attr);
|
||||
converter.Serializer = this;
|
||||
return _cachedConverters[type] = converter;
|
||||
}
|
||||
}
|
||||
|
||||
// No converter specified. Find match from general ones.
|
||||
{
|
||||
fsDirectConverter directConverter;
|
||||
if ( _availableDirectConverters.TryGetValue(type, out directConverter) ) {
|
||||
return _cachedConverters[type] = directConverter;
|
||||
}
|
||||
|
||||
for ( var i = 0; i < _availableConverters.Count; i++ ) {
|
||||
if ( _availableConverters[i].CanProcess(type) ) {
|
||||
return _cachedConverters[type] = _availableConverters[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No converter available
|
||||
return _cachedConverters[type] = null;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Serialize the given value.</summary>
|
||||
public fsResult TrySerialize(Type storageType, object instance, out fsData data) {
|
||||
return TrySerialize(storageType, instance, out data, null);
|
||||
}
|
||||
|
||||
///<summary> Serialize the given value. StorageType: field type. OverideConverter: optional override converter. Instance: the object instance. Data: the serialized state.</summary>
|
||||
public fsResult TrySerialize(Type storageType, object instance, out fsData data, Type overrideConverterType) {
|
||||
|
||||
var realType = instance == null ? storageType : instance.GetType();
|
||||
var processors = GetProcessors(realType);
|
||||
Invoke_OnBeforeSerialize(processors, storageType, instance);
|
||||
|
||||
// We always serialize null directly as null
|
||||
if ( ReferenceEquals(instance, null) ) {
|
||||
data = new fsData();
|
||||
Invoke_OnAfterSerialize(processors, storageType, instance, ref data);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
if ( onBeforeObjectSerialized != null ) { onBeforeObjectSerialized(instance); }
|
||||
|
||||
fsResult result;
|
||||
|
||||
try {
|
||||
_references.Enter();
|
||||
result = Internal_Serialize(storageType, instance, out data, overrideConverterType);
|
||||
}
|
||||
|
||||
finally { if ( _references.Exit() ) { _lazyReferenceWriter.Clear(); } }
|
||||
|
||||
//versioning
|
||||
TrySerializeVersioning(instance, ref data);
|
||||
|
||||
//invoke processors
|
||||
Invoke_OnAfterSerialize(processors, storageType, instance, ref data);
|
||||
|
||||
if ( onAfterObjectSerialized != null ) { onAfterObjectSerialized(instance, data); }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//...
|
||||
fsResult Internal_Serialize(Type storageType, object instance, out fsData data, Type overrideConverterType) {
|
||||
|
||||
var instanceType = instance.GetType();
|
||||
var instanceTypeConverter = GetConverter(instanceType, overrideConverterType);
|
||||
if ( instanceTypeConverter == null ) {
|
||||
data = new fsData();
|
||||
// return fsResult.Warn(string.Format("No converter for {0}", instanceType));
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
var needsCycleSupport = instanceType.RTIsDefined<fsSerializeAsReference>(true);
|
||||
if ( needsCycleSupport ) {
|
||||
// We've already serialized this object instance (or it is pending higher up on the call stack).
|
||||
// Just serialize a reference to it to escape the cycle.
|
||||
if ( _references.IsReference(instance) ) {
|
||||
data = fsData.CreateDictionary();
|
||||
_lazyReferenceWriter.WriteReference(_references.GetReferenceId(instance), data.AsDictionary);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
// Mark inside the object graph that we've serialized the instance. We do this *before*
|
||||
// serialization so that if we get back into this function recursively, it'll already
|
||||
// be marked and we can handle the cycle properly without going into an infinite loop.
|
||||
_references.MarkSerialized(instance);
|
||||
}
|
||||
|
||||
//push collector
|
||||
TryPush(instance);
|
||||
|
||||
// Serialize the instance with it's actual instance type, not storageType.
|
||||
var serializeResult = instanceTypeConverter.TrySerialize(instance, out data, instanceType);
|
||||
|
||||
//pop collector
|
||||
TryPop(instance);
|
||||
|
||||
if ( serializeResult.Failed ) {
|
||||
return serializeResult;
|
||||
}
|
||||
|
||||
// Do we need to add type information? If the field type and the instance type are different.
|
||||
if ( storageType != instanceType && GetConverter(storageType, overrideConverterType).RequestInheritanceSupport(storageType) ) {
|
||||
EnsureDictionary(ref data);
|
||||
data.AsDictionary[KEY_INSTANCE_TYPE] = new fsData(instanceType.FullName);
|
||||
}
|
||||
|
||||
if ( needsCycleSupport ) {
|
||||
_lazyReferenceWriter.WriteDefinition(_references.GetReferenceId(instance), data);
|
||||
}
|
||||
|
||||
return serializeResult;
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary> Attempts to deserialize a value from a serialized state.</summary>
|
||||
public fsResult TryDeserialize(fsData data, Type storageType, ref object result) {
|
||||
return TryDeserialize(data, storageType, ref result, null);
|
||||
}
|
||||
|
||||
///<summary> Attempts to deserialize a value from a serialized state.</summary>
|
||||
public fsResult TryDeserialize(fsData data, Type storageType, ref object result, Type overrideConverterType) {
|
||||
|
||||
if ( data.IsNull ) {
|
||||
result = null;
|
||||
var processors = GetProcessors(storageType);
|
||||
Invoke_OnBeforeDeserialize(processors, storageType, ref data);
|
||||
Invoke_OnAfterDeserialize(processors, storageType, null);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
try {
|
||||
_references.Enter();
|
||||
return Internal_Deserialize(data, storageType, ref result, overrideConverterType);
|
||||
}
|
||||
|
||||
finally { _references.Exit(); }
|
||||
}
|
||||
|
||||
//...
|
||||
fsResult Internal_Deserialize(fsData data, Type storageType, ref object result, Type overrideConverterType) {
|
||||
//$ref encountered. Do before inheritance.
|
||||
if ( IsObjectReference(data) ) {
|
||||
int refId = int.Parse(data.AsDictionary[KEY_OBJECT_REFERENCE].AsString);
|
||||
result = _references.GetReferenceObject(refId);
|
||||
return fsResult.Success;
|
||||
}
|
||||
|
||||
var deserializeResult = fsResult.Success;
|
||||
var objectType = result != null ? result.GetType() : storageType;
|
||||
Type forwardMigrationPreviousType = null;
|
||||
|
||||
// Gather processors and call OnBeforeDeserialize before anything
|
||||
var processors = GetProcessors(objectType);
|
||||
Invoke_OnBeforeDeserialize(processors, objectType, ref data);
|
||||
|
||||
// If the serialized state contains type information, then we need to make sure to update our
|
||||
// objectType and data to the proper values so that when we construct an object instance later
|
||||
// and run deserialization we run it on the proper type.
|
||||
// $type
|
||||
if ( IsTypeSpecified(data) ) {
|
||||
var typeNameData = data.AsDictionary[KEY_INSTANCE_TYPE];
|
||||
|
||||
do {
|
||||
if ( !typeNameData.IsString ) {
|
||||
deserializeResult.AddMessage(string.Format("{0} value must be a string", KEY_INSTANCE_TYPE));
|
||||
break;
|
||||
}
|
||||
|
||||
var typeName = typeNameData.AsString;
|
||||
var type = ReflectionTools.GetType(typeName, storageType);
|
||||
|
||||
if ( type == null ) {
|
||||
deserializeResult.AddMessage(string.Format("{0} type can not be resolved", typeName));
|
||||
break;
|
||||
}
|
||||
|
||||
var migrateAtt = type.RTGetAttribute<fsMigrateToAttribute>(true);
|
||||
if ( migrateAtt != null ) {
|
||||
// if migrating from another type, save the original type and mutate the current type
|
||||
if ( !typeof(IMigratable).IsAssignableFrom(migrateAtt.targetType) ) {
|
||||
throw new Exception("TargetType of [fsMigrateToAttribute] must implement IMigratable<T> with T being the target type");
|
||||
}
|
||||
forwardMigrationPreviousType = type;
|
||||
if ( type.IsGenericType && migrateAtt.targetType.IsGenericTypeDefinition ) {
|
||||
type = migrateAtt.targetType.MakeGenericType(type.GetGenericArguments());
|
||||
} else { type = migrateAtt.targetType; }
|
||||
}
|
||||
|
||||
if ( !storageType.IsAssignableFrom(type) ) {
|
||||
deserializeResult.AddMessage(string.Format("Ignoring type specifier. Field or type {0} can't hold and instance of type {1}", storageType, type));
|
||||
break;
|
||||
}
|
||||
|
||||
objectType = type;
|
||||
|
||||
} while ( false );
|
||||
}
|
||||
|
||||
var converter = GetConverter(objectType, overrideConverterType);
|
||||
if ( converter == null ) {
|
||||
return fsResult.Warn(string.Format("No Converter available for {0}", objectType));
|
||||
}
|
||||
|
||||
// Construct an object instance if we don't have one already using actual objectType
|
||||
if ( ReferenceEquals(result, null) || result.GetType() != objectType ) {
|
||||
result = converter.CreateInstance(data, objectType);
|
||||
}
|
||||
|
||||
// if migrating from another type, do migration now.
|
||||
if ( forwardMigrationPreviousType != null ) {
|
||||
//we deserialize versioning first on the old model type and then do migration
|
||||
var previousInstance = GetConverter(forwardMigrationPreviousType, null).CreateInstance(data, forwardMigrationPreviousType);
|
||||
TryDeserializeVersioning(ref previousInstance, ref data);
|
||||
TryDeserializeMigration(ref result, ref data, forwardMigrationPreviousType, previousInstance);
|
||||
} else {
|
||||
// if not a forward migration, try deserialize versioning as normal
|
||||
TryDeserializeVersioning(ref result, ref data);
|
||||
}
|
||||
|
||||
// invoke callback with objectType
|
||||
Invoke_OnBeforeDeserializeAfterInstanceCreation(processors, objectType, result, ref data);
|
||||
|
||||
// $id
|
||||
if ( IsObjectDefinition(data) ) {
|
||||
var sourceId = int.Parse(data.AsDictionary[KEY_OBJECT_DEFINITION].AsString);
|
||||
_references.AddReferenceWithId(sourceId, result);
|
||||
}
|
||||
|
||||
// $content
|
||||
if ( IsWrappedData(data) ) {
|
||||
data = data.AsDictionary[KEY_CONTENT];
|
||||
}
|
||||
|
||||
// push collector
|
||||
TryPush(result);
|
||||
|
||||
// must pass actual objectType
|
||||
deserializeResult += converter.TryDeserialize(data, ref result, objectType);
|
||||
if ( deserializeResult.Succeeded ) { Invoke_OnAfterDeserialize(processors, objectType, result); }
|
||||
|
||||
// pop collector
|
||||
TryPop(result);
|
||||
|
||||
return deserializeResult;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary>Push collector to stack</summary>
|
||||
void TryPush(object o) {
|
||||
|
||||
if ( o is ISerializationCollectable ) {
|
||||
_collectableDepth++;
|
||||
if ( _collectors.Count > 0 ) {
|
||||
_collectors.Peek().OnCollect((ISerializationCollectable)o, _collectableDepth);
|
||||
}
|
||||
}
|
||||
|
||||
//collector is also collectable, so we start at depth 0
|
||||
if ( o is ISerializationCollector ) {
|
||||
_collectableDepth = -1;
|
||||
var parent = _collectors.Count > 0 ? _collectors.Peek() : null;
|
||||
_collectors.Push((ISerializationCollector)o);
|
||||
( (ISerializationCollector)o ).OnPush(parent);
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Pop collector in stack and/or collect object</summary>
|
||||
void TryPop(object o) {
|
||||
|
||||
//collector is also collectable, so we collect at depth 0
|
||||
if ( o is ISerializationCollector ) {
|
||||
_collectableDepth = 0;
|
||||
_collectors.Pop().OnPop(_collectors.Count > 0 ? _collectors.Peek() : null);
|
||||
}
|
||||
|
||||
if ( o is ISerializationCollectable ) {
|
||||
_collectableDepth--;
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
//This is an alternative idea with collection happening AFTER serialization/deserialization
|
||||
//There can probably be two callbacks OnBefore and OnAfter?
|
||||
// ///<summary>Push collector to stack</summary>
|
||||
// void TryPush(object o) {
|
||||
// if ( o is ISerializationCollector ) {
|
||||
// _collectableDepth = -1;
|
||||
// var parent = _collectors.Count > 0 ? _collectors.Peek() : null;
|
||||
// _collectors.Push((ISerializationCollector)o);
|
||||
// ( (ISerializationCollector)o ).OnPush(parent);
|
||||
// }
|
||||
|
||||
// //collector is also collectable, so we start at depth 0
|
||||
// if ( o is ISerializationCollectable ) {
|
||||
// _collectableDepth++;
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// ///<summary>Pop collector in stack and/or collect object</summary>
|
||||
// void TryPop(object o) {
|
||||
// if ( o is ISerializationCollector ) {
|
||||
// _collectableDepth = 1;
|
||||
// _collectors.Pop().OnPop(_collectors.Count > 0 ? _collectors.Peek() : null);
|
||||
// }
|
||||
|
||||
// //collector is also collectable, so we collect at depth 0
|
||||
// if ( o is ISerializationCollectable ) {
|
||||
// _collectableDepth--;
|
||||
// if ( _collectors.Count > 0 ) {
|
||||
// _collectors.Peek().OnCollect((ISerializationCollectable)o, _collectableDepth);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
///<summary>Version migration serialize</summary>
|
||||
void TrySerializeVersioning(object currentInstance, ref fsData data) {
|
||||
if ( currentInstance is IMigratable && data.IsDictionary ) {
|
||||
var att = currentInstance.GetType().RTGetAttribute<fsMigrateVersionsAttribute>(true);
|
||||
if ( att != null && att.previousTypes.Length > 0 ) {
|
||||
data.AsDictionary[KEY_VERSION] = new fsData(att.previousTypes.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Version migration deserialize</summary>
|
||||
void TryDeserializeVersioning(ref object currentInstance, ref fsData currentData) {
|
||||
if ( currentInstance is IMigratable && currentData.IsDictionary ) {
|
||||
|
||||
var instanceType = currentInstance.GetType();
|
||||
fsData serializedVersionData;
|
||||
int serializedVersion = 0;
|
||||
if ( currentData.AsDictionary.TryGetValue(KEY_VERSION, out serializedVersionData) ) {
|
||||
serializedVersion = (int)serializedVersionData.AsInt64;
|
||||
}
|
||||
|
||||
var att = instanceType.RTGetAttribute<fsMigrateVersionsAttribute>(true);
|
||||
if ( att != null ) {
|
||||
var previousTypes = att.previousTypes;
|
||||
var currentVersion = previousTypes.Length;
|
||||
|
||||
if ( currentVersion > serializedVersion ) {
|
||||
var previousType = previousTypes[serializedVersion];
|
||||
TryDeserializeMigration(ref currentInstance, ref currentData, previousType, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Create instance of previous type, deserialize it with previous data and call Migrate to currentInstance</summary>
|
||||
void TryDeserializeMigration(ref object currentInstance, ref fsData currentData, Type previousType, object previousInstance) {
|
||||
if ( currentInstance is IMigratable && currentData.IsDictionary ) {
|
||||
|
||||
var instanceType = currentInstance.GetType();
|
||||
if ( instanceType.IsGenericType && previousType.IsGenericTypeDefinition ) {
|
||||
previousType = previousType.MakeGenericType(instanceType.GetGenericArguments());
|
||||
}
|
||||
|
||||
System.Reflection.InterfaceMapping interfaceMap;
|
||||
try { interfaceMap = instanceType.GetInterfaceMap(typeof(IMigratable<>).MakeGenericType(previousType)); }
|
||||
catch ( Exception e ) { throw new Exception("Type must implement IMigratable<T> for each one of the types specified in the [fsMigrateVersionsAttribute] or [fsMigrateToAttribute]\n" + e.Message); }
|
||||
var migrateMethod = interfaceMap.InterfaceMethods.First(m => m.Name == nameof(IMigratable<object>.Migrate));
|
||||
|
||||
//create previous instance and deserialize through converter only
|
||||
var converter = GetConverter(previousType, null);
|
||||
if ( previousInstance == null ) { previousInstance = converter.CreateInstance(currentData, previousType); }
|
||||
converter.TryDeserialize(currentData, ref previousInstance, previousType).AssertSuccess();
|
||||
migrateMethod.Invoke(currentInstance, ReflectionTools.SingleTempArgsArray(previousInstance));
|
||||
|
||||
fsData serializedData;
|
||||
//we serialize the previous instance then remove all serialization keys from the original data that will
|
||||
//be used for deserialization on the current instance down later. This way we dont overwrite the migration.
|
||||
converter.TrySerialize(previousInstance, out serializedData, previousType).AssertSuccess();
|
||||
foreach ( var pair in serializedData.AsDictionary ) { currentData.AsDictionary.Remove(pair.Key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e14172521dbad7d49899b998d378516c
|
||||
timeCreated: 1458897574
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsSerializer.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace ParadoxNotion.Serialization
|
||||
{
|
||||
|
||||
//an interface used along with fsRecoveryProcessor to handle missing types and their recovery
|
||||
public interface IMissingRecoverable
|
||||
{
|
||||
string missingType { get; set; }
|
||||
string recoveryState { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ca05c8a629ef6247b4f73b5161c72dd
|
||||
timeCreated: 1477153143
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 14914
|
||||
packageName: NodeCanvas
|
||||
packageVersion: 3.3.1
|
||||
assetPath: Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/IMissingRecoverable.cs
|
||||
uploadId: 704937
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace ParadoxNotion.Serialization
|
||||
{
|
||||
|
||||
public interface ISerializedMethodBaseInfo : ISerializedReflectedInfo
|
||||
{
|
||||
MethodBase GetMethodBase();
|
||||
bool HasChanged();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user