Ejemplo n.º 1
0
        private bool Read_Struct <T>(ref T inObject, TypeUtility.TypeSerializerDelegate <T> inSerializer) where T : struct
        {
            int prevErrorLength = m_ErrorString.Length;

            inObject = default(T);
            inSerializer(ref inObject, this);
            return(m_ErrorString.Length == prevErrorLength);
        }
Ejemplo n.º 2
0
        private bool Read_Custom <T>(ref T inObject, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            int prevErrorLength = m_ErrorString.Length;

            if (inObject == null)
            {
                inObject = (T)TypeUtility.Instantiate(typeof(T), this);
            }
            inSerializer(ref inObject, this);
            return(m_ErrorString.Length == prevErrorLength);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Writes an object onto the current array.
 /// </summary>
 private void DoWriteStruct <T>(ref T ioData, T inDefault, TypeUtility.TypeSerializerDelegate <T> inSerializer) where T : struct
 {
     if (!EqualityComparer <T> .Default.Equals(ioData, inDefault))
     {
         BeginWriteObject();
         Write_Struct(ref ioData, inSerializer);
         EndObject();
     }
     else
     {
         WriteNull();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Writes an object onto the current array.
 /// </summary>
 private void DoWriteCustom <T>(ref T ioData, T inDefault, TypeUtility.TypeSerializerDelegate <T> inSerializer)
 {
     if (ioData != null && !ioData.Equals(inDefault))
     {
         BeginWriteObject();
         Write_Custom(ref ioData, inSerializer);
         EndValue();
     }
     else
     {
         WriteNull();
     }
 }
Ejemplo n.º 5
0
 public void Map(string inKey, ref Dictionary <int, UnityEngine.BoundsInt> ioMap, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructMap <UnityEngine.BoundsInt>(inKey, ref ioMap, inOptions,
                                         Serialize_BoundsInt_Cached ?? (Serialize_BoundsInt_Cached = Serialize_BoundsInt));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads an object from the current node.
        /// </summary>
        private bool DoReadCustom <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            bool bSuccess = BeginReadObject(inKey);

            if (IsMissing() || IsNull())
            {
                ioData   = inDefault;
                bSuccess = true;
            }
            else
            {
                bSuccess &= Read_Custom(ref ioData, inSerializer);
            }
            EndObject();

            return(bSuccess);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Writes an object into the current object.
 /// </summary>
 private void DoWriteStruct <T>(string inKey, ref T ioData, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer) where T : struct
 {
     BeginWriteObject(inKey);
     Write_Struct(ref ioData, inSerializer);
     EndObject();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Writes an object onto the current array.
 /// </summary>
 private void DoWriteStruct <T>(ref T ioData, TypeUtility.TypeSerializerDelegate <T> inSerializer) where T : struct
 {
     BeginWriteObject();
     Write_Struct(ref ioData, inSerializer);
     EndObject();
 }
Ejemplo n.º 9
0
        private void DoCustomArray <T>(string inKey, ref List <T> ioArray, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            if (IsReading)
            {
                bool bSuccess = BeginReadArray(inKey);
                {
                    if (IsMissing())
                    {
                        if ((inOptions & FieldOptions.Optional) != 0)
                        {
                            if (ioArray != null)
                            {
                                ioArray.Clear();
                            }
                            ioArray  = null;
                            bSuccess = true;
                        }
                        else
                        {
                            bSuccess = false;
                        }
                    }
                    else if (IsNull())
                    {
                        if (ioArray != null)
                        {
                            ioArray.Clear();
                        }
                        ioArray  = null;
                        bSuccess = true;
                    }
                    else
                    {
                        int nodeCount = GetChildCount();
                        if (ioArray != null)
                        {
                            ioArray.Clear();
                            if (ioArray.Capacity < nodeCount)
                            {
                                ioArray.Capacity = nodeCount;
                            }
                        }
                        else
                        {
                            ioArray = new List <T>(nodeCount);
                        }

                        for (int i = 0; i < nodeCount; ++i)
                        {
                            T obj = default(T);
                            bSuccess &= DoReadCustom(i, ref obj, FieldOptions.None, inSerializer);
                            ioArray.Add(obj);
                        }
                    }
                }
                EndArray();

                if (!bSuccess)
                {
                    AddErrorMessage("Unable to read array '{0}'.", inKey);
                }

                return;
            }

            if (ioArray == null)
            {
                if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
                {
                    WriteNull(inKey);
                }
            }
            else
            {
                BeginWriteArray(inKey);
                DeclareChildCount(ioArray.Count);
                for (int i = 0; i < ioArray.Count; ++i)
                {
                    T obj = ioArray[i];
                    DoWriteCustom <T>(ref obj, inSerializer);
                }
                EndArray();
            }
        }
Ejemplo n.º 10
0
 public void Array(string inKey, ref UnityEngine.Vector4[] ioArray, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructArray <UnityEngine.Vector4>(inKey, ref ioArray, inOptions,
                                         Serialize_Vector4_Cached ?? (Serialize_Vector4_Cached = Serialize_Vector4));
 }
Ejemplo n.º 11
0
 public void Map(string inKey, ref Dictionary <int, UnityEngine.Vector4> ioMap, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructMap <UnityEngine.Vector4>(inKey, ref ioMap, inOptions,
                                       Serialize_Vector4_Cached ?? (Serialize_Vector4_Cached = Serialize_Vector4));
 }
Ejemplo n.º 12
0
 public void Array(string inKey, ref UnityEngine.Quaternion[] ioArray, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructArray <UnityEngine.Quaternion>(inKey, ref ioArray, inOptions,
                                            Serialize_Quaternion_Cached ?? (Serialize_Quaternion_Cached = Serialize_Quaternion));
 }
Ejemplo n.º 13
0
 public void Map(string inKey, ref Dictionary <int, UnityEngine.Quaternion> ioMap, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructMap <UnityEngine.Quaternion>(inKey, ref ioMap, inOptions,
                                          Serialize_Quaternion_Cached ?? (Serialize_Quaternion_Cached = Serialize_Quaternion));
 }
Ejemplo n.º 14
0
 public void Set(string inKey, ref HashSet <UnityEngine.BoundsInt> ioSet, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructSet <UnityEngine.BoundsInt>(inKey, ref ioSet, inOptions,
                                         Serialize_BoundsInt_Cached ?? (Serialize_BoundsInt_Cached = Serialize_BoundsInt));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Writes an object into the current object.
 /// </summary>
 private void DoWriteCustom <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
 {
     if (ioData != null && !ioData.Equals(inDefault))
     {
         BeginWriteObject(inKey);
         Write_Custom(ref ioData, inSerializer);
         EndValue();
     }
     else if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
     {
         WriteNull(inKey);
     }
 }
Ejemplo n.º 16
0
 public void Array(string inKey, ref UnityEngine.BoundsInt[] ioArray, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructArray <UnityEngine.BoundsInt>(inKey, ref ioArray, inOptions,
                                           Serialize_BoundsInt_Cached ?? (Serialize_BoundsInt_Cached = Serialize_BoundsInt));
 }
Ejemplo n.º 17
0
 public void Serialize(string inKey, ref UnityEngine.Bounds ioData, UnityEngine.Bounds inDefault, FieldOptions inOptions = FieldOptions.None)
 {
     DoStruct <UnityEngine.Bounds>(inKey, ref ioData, inDefault, inOptions,
                                   Serialize_Bounds_Cached ?? (Serialize_Bounds_Cached = Serialize_Bounds));
 }
Ejemplo n.º 18
0
 public void Array(string inKey, ref List <UnityEngine.RectInt> ioArray, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructArray <UnityEngine.RectInt>(inKey, ref ioArray, inOptions,
                                         Serialize_RectInt_Cached ?? (Serialize_RectInt_Cached = Serialize_RectInt));
 }
Ejemplo n.º 19
0
 public void Serialize(string inKey, ref UnityEngine.RectInt ioData, UnityEngine.RectInt inDefault, FieldOptions inOptions = FieldOptions.None)
 {
     DoStruct <UnityEngine.RectInt>(inKey, ref ioData, inDefault, inOptions,
                                    Serialize_RectInt_Cached ?? (Serialize_RectInt_Cached = Serialize_RectInt));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Writes an object into the current object.
 /// </summary>
 private void DoWriteStruct <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer) where T : struct
 {
     if (!EqualityComparer <T> .Default.Equals(ioData, inDefault))
     {
         BeginWriteObject(inKey);
         Write_Struct(ref ioData, inSerializer);
         EndObject();
     }
     else if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
     {
         WriteNull(inKey);
     }
 }
Ejemplo n.º 21
0
 public void Serialize(string inKey, ref UnityEngine.Vector3 ioData, UnityEngine.Vector3 inDefault, FieldOptions inOptions = FieldOptions.None)
 {
     DoStruct <UnityEngine.Vector3>(inKey, ref ioData, inDefault, inOptions,
                                    Serialize_Vector3_Cached ?? (Serialize_Vector3_Cached = Serialize_Vector3));
 }
Ejemplo n.º 22
0
 public void Serialize(string inKey, ref UnityEngine.BoundsInt ioData, FieldOptions inOptions = FieldOptions.None)
 {
     DoStruct <UnityEngine.BoundsInt>(inKey, ref ioData, inOptions,
                                      Serialize_BoundsInt_Cached ?? (Serialize_BoundsInt_Cached = Serialize_BoundsInt));
 }
Ejemplo n.º 23
0
 public void Set(string inKey, ref HashSet <UnityEngine.Quaternion> ioSet, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructSet <UnityEngine.Quaternion>(inKey, ref ioSet, inOptions,
                                          Serialize_Quaternion_Cached ?? (Serialize_Quaternion_Cached = Serialize_Quaternion));
 }
Ejemplo n.º 24
0
 private void Write_Custom <T>(ref T inObject, TypeUtility.TypeSerializerDelegate <T> inSerializer)
 {
     inSerializer(ref inObject, this);
 }
Ejemplo n.º 25
0
 public void Serialize(string inKey, ref UnityEngine.Quaternion ioData, FieldOptions inOptions = FieldOptions.None)
 {
     DoStruct <UnityEngine.Quaternion>(inKey, ref ioData, inOptions,
                                       Serialize_Quaternion_Cached ?? (Serialize_Quaternion_Cached = Serialize_Quaternion));
 }
Ejemplo n.º 26
0
        private void DoCustom <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            if (IsReading)
            {
                bool bSuccess = DoReadCustom <T>(inKey, ref ioData, inDefault, inOptions, inSerializer);

                if (!bSuccess)
                {
                    AddErrorMessage("Unable to read struct '{0}'.", inKey);
                }
                return;
            }

            DoWriteCustom <T>(inKey, ref ioData, inDefault, inOptions, inSerializer);
        }
Ejemplo n.º 27
0
 public void Set(string inKey, ref HashSet <UnityEngine.Vector4> ioSet, FieldOptions inOptions = FieldOptions.None)
 {
     DoStructSet <UnityEngine.Vector4>(inKey, ref ioSet, inOptions,
                                       Serialize_Vector4_Cached ?? (Serialize_Vector4_Cached = Serialize_Vector4));
 }
Ejemplo n.º 28
0
        private void DoCustomMap <T>(string inKey, ref Dictionary <int, T> ioMap, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            if (IsReading)
            {
                bool bSuccess = BeginReadArray(inKey);
                {
                    if (IsMissing())
                    {
                        if ((inOptions & FieldOptions.Optional) != 0)
                        {
                            if (ioMap != null)
                            {
                                ioMap.Clear();
                            }
                            ioMap    = null;
                            bSuccess = true;
                        }
                        else
                        {
                            bSuccess = false;
                        }
                    }
                    else if (IsNull())
                    {
                        if (ioMap != null)
                        {
                            ioMap.Clear();
                        }
                        ioMap    = null;
                        bSuccess = true;
                    }
                    else
                    {
                        int nodeCount = GetChildCount();
                        if (ioMap != null)
                        {
                            ioMap.Clear();
                        }
                        else
                        {
                            ioMap = new Dictionary <int, T>(nodeCount);
                        }

                        for (int i = 0; i < nodeCount; ++i)
                        {
                            bSuccess &= BeginReadObject(i);
                            {
                                int key = default(int);
                                bSuccess &= DoRead(MAP_KEY, ref key, FieldOptions.None, Read_Int32_Cached ?? (Read_Int32_Cached = Read_Int32));

                                T obj = default(T);
                                bSuccess &= DoReadCustom(MAP_VALUE, ref obj, FieldOptions.None, inSerializer);

                                ioMap.Add(key, obj);
                            }
                            EndObject();
                        }
                    }
                }
                EndArray();

                if (!bSuccess)
                {
                    AddErrorMessage("Unable to read array '{0}'.", inKey);
                }

                return;
            }

            if (ioMap == null)
            {
                if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
                {
                    WriteNull(inKey);
                }
            }
            else
            {
                BeginWriteArray(inKey);
                DeclareChildCount(ioMap.Count);
                foreach (var keyValue in ioMap)
                {
                    BeginWriteObject();

                    int key = keyValue.Key;
                    DoWrite(MAP_KEY, ref key, FieldOptions.PreferAttribute, this.Write_Int32);

                    T obj = keyValue.Value;
                    DoWriteCustom(MAP_VALUE, ref obj, FieldOptions.None, inSerializer);

                    EndObject();
                }
                EndArray();
            }
        }
Ejemplo n.º 29
0
 public void Serialize(string inKey, ref UnityEngine.Vector4 ioData, FieldOptions inOptions = FieldOptions.None)
 {
     DoStruct <UnityEngine.Vector4>(inKey, ref ioData, inOptions,
                                    Serialize_Vector4_Cached ?? (Serialize_Vector4_Cached = Serialize_Vector4));
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Reads an object from the current node.
        /// </summary>
        private bool DoReadCustom <T>(int inIndex, ref T ioData, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            bool bSuccess = BeginReadObject(inIndex);

            if (IsMissing())
            {
                if ((inOptions & FieldOptions.Optional) != 0)
                {
                    ioData   = default(T);
                    bSuccess = true;
                }
                else
                {
                    bSuccess &= false;
                }
            }
            else if (IsNull())
            {
                ioData   = default(T);
                bSuccess = true;
            }
            else
            {
                bSuccess &= Read_Custom(ref ioData, inSerializer);
            }
            EndObject();

            return(bSuccess);
        }