コード例 #1
0
ファイル: ListUON.cs プロジェクト: Hengle/clapotis
        public override string  Serialize(UON.SerializationData data, object o)
        {
            int refIndex;

            if (data.GetReferenceIndex(o, out refIndex) == true)
            {
                return("#" + refIndex);
            }

            StringBuilder buffer = UONUtility.GetBuffer();
            IList         array  = o as IList;

            data.workingType = UONUtility.GetArraySubType(data.workingType);

            buffer.Append('[');

            foreach (object element in array)
            {
                string raw = data.ToUON(element);

                if (string.IsNullOrEmpty(raw) == false)
                {
                    if (buffer.Length > 1)
                    {
                        buffer.Append(',');
                    }

                    buffer.Append(raw);
                }
            }

            buffer.Append(']');

            return(UONUtility.ReturnBuffer(buffer));
        }
コード例 #2
0
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     if (this.GetAssetPath != null)
     {
         return(this.LoadAssetAtPath.Invoke(null, new object[] { raw.ToString(1, raw.Length - 2), typeof(UnityEngine.Object) }));
     }
     return(null);
 }
コード例 #3
0
 public override string  Serialize(UON.SerializationData data, object o)
 {
     if (this.GetAssetPath != null)
     {
         return("\"" + this.GetAssetPath.Invoke(null, new object[] { o }) + "\"");
     }
     return(null);
 }
コード例 #4
0
ファイル: UONType.cs プロジェクト: Hengle/clapotis
        public string   AppendTypeIfNecessary(UON.SerializationData data, Type targetType)
        {
            if (data.nestedLevel > 0 && (data.latestType == null || data.latestType != targetType))
            {
                data.latestType = targetType;
                return("(" + data.GetTypeIndex(targetType) + ')');
            }

            return(string.Empty);
        }
コード例 #5
0
ファイル: ClassUON.cs プロジェクト: Hengle/clapotis
        public override string  Serialize(UON.SerializationData data, object o)
        {
            int refIndex;

            if (data.GetReferenceIndex(o, out refIndex) == true)
            {
                return("#" + refIndex);
            }

            StringBuilder buffer = UONUtility.GetBuffer();

            FieldInfo[]       fields;
            IUONSerialization serializationInterface = o as IUONSerialization;

            if (serializationInterface != null)
            {
                serializationInterface.OnSerializing();
            }

            if (this.typesFields.TryGetValue(data.workingType, out fields) == false)
            {
                fields = UONUtility.GetFieldsHierarchyOrdered(data.workingType, typeof(object), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).ToArray();
            }

            buffer.Append('{');

            foreach (FieldInfo field in fields)
            {
#if NETFX_CORE
                if (field.IsDefined(typeof(NonSerializedAttribute)) == false)
#else
                if (field.IsNotSerialized == false)
#endif
                {
                    string raw = data.ToUON(field.GetValue(o));

                    if (string.IsNullOrEmpty(raw) == false)
                    {
                        if (buffer.Length > 1)
                        {
                            buffer.Append(',');
                        }

                        buffer.Append('"');
                        buffer.Append(field.Name);
                        buffer.Append("\":");
                        buffer.Append(raw);
                    }
                }
            }

            buffer.Append('}');

            return(UONUtility.ReturnBuffer(buffer));
        }
コード例 #6
0
ファイル: ArrayUON.cs プロジェクト: Hengle/clapotis
        public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
        {
            if (raw[0] == '#')
            {
                return(data.deserializedReferences[int.Parse(raw.ToString(1, raw.Length - 1))]);
            }

            if (raw[0] != '[')
            {
                throw new FormatException("No opening char '[' found in \"" + raw + "\".");
            }

            if (instance != null && (instance is Array) == false)
            {
                throw new InvalidCastException("The given object of type \"" + instance.GetType() + "\" is not an Array.");
            }

            StringBuilder currentType = UONUtility.GetBuffer();
            int           deep        = 0;
            Type          arrayType   = data.latestType;
            Array         array       = null;

            for (int i = 1, j = 0; i < raw.Length; i++)
            {
                if (raw[i] == '{' || raw[i] == '[')
                {
                    ++deep;
                }
                else if (raw[i] == '}' || raw[i] == ']' || raw[i] == ',')
                {
                    if (instance == null)
                    {
                        instance           = Array.CreateInstance(arrayType.GetElementType(), int.Parse(currentType.ToString()));
                        currentType.Length = 0;
                        continue;
                    }

                    if (array == null)
                    {
                        array = instance as Array;
                        data.deserializedReferences.Add(array);
                    }

                    if (deep == 0 && currentType.Length > 0)
                    {
                        if (UON.VerboseLevel > 0)
                        {
                            Debug.Log(currentType.ToString());
                        }

                        if (currentType[0] == '(')
                        {
                            int n = currentType.IndexOf(")");
                            data.latestType = data.registeredTypes[int.Parse(currentType.ToString(1, n - 1))];
                            currentType     = currentType.Remove(0, n + 1);
                        }

                        if (j < array.Length)
                        {
                            array.SetValue(data.FromUON(data.latestType, currentType), j++);
                        }

                        currentType.Length = 0;
                        continue;
                    }

                    if (raw[i] == '}' || raw[i] == ']')
                    {
                        --deep;
                    }
                }

                currentType.Append(raw[i]);
            }

            UONUtility.RestoreBuffer(currentType);

            return(instance);
        }
コード例 #7
0
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     return(null);
 }
コード例 #8
0
 public override string  Serialize(UON.SerializationData data, object o)
 {
     return(null);
 }
コード例 #9
0
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     return(Enum.ToObject(data.latestType, int.Parse(raw.ToString())));
 }
コード例 #10
0
ファイル: BooleanUON.cs プロジェクト: Hengle/clapotis
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     return(raw[0] == 'T' ? true : false);
 }
コード例 #11
0
ファイル: BooleanUON.cs プロジェクト: Hengle/clapotis
 public override string  Serialize(UON.SerializationData data, object o)
 {
     return((Boolean)o == true ? "T" : "F");
 }
コード例 #12
0
ファイル: ListUON.cs プロジェクト: Hengle/clapotis
        public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
        {
            if (raw[0] == '#')
            {
                return(data.deserializedReferences[int.Parse(raw.ToString(1, raw.Length - 1))]);
            }

            if (raw[0] != '[')
            {
                throw new FormatException("No opening char '[' found in \"" + raw + "\".");
            }

            StringBuilder currentType = UONUtility.GetBuffer();
            int           deep        = 0;
            IList         list;

            if (instance == null)
            {
                instance = Activator.CreateInstance(data.latestType);
            }

            data.deserializedReferences.Add(instance);

            list = instance as IList;

            if (list == null)
            {
                throw new InvalidCastException("The given object of type \"" + instance.GetType() + "\" does not implement interface IList.");
            }
            else
            {
                list.Clear();
            }

            for (int i = 1; i < raw.Length; i++)
            {
                if (raw[i] == '{' || raw[i] == '[')
                {
                    ++deep;
                }
                else if (raw[i] == '}' || raw[i] == ']' || raw[i] == ',')
                {
                    if (deep == 0 && currentType.Length > 0)
                    {
                        if (UON.VerboseLevel > 0)
                        {
                            Debug.Log(currentType.ToString());
                        }

                        if (currentType[0] == '(')
                        {
                            int n = currentType.IndexOf(")");
                            data.latestType = data.registeredTypes[int.Parse(currentType.ToString(1, n - 1))];
                            currentType     = currentType.Remove(0, n + 1);
                        }

                        list.Add(data.FromUON(data.latestType, currentType));

                        currentType.Length = 0;
                        continue;
                    }

                    if (raw[i] == '}' || raw[i] == ']')
                    {
                        --deep;
                    }
                }

                currentType.Append(raw[i]);
            }

            UONUtility.RestoreBuffer(currentType);

            return(instance);
        }
コード例 #13
0
 public override string  Serialize(UON.SerializationData data, object o)
 {
     return(((byte)o).ToHex());
 }
コード例 #14
0
 public override string  Serialize(UON.SerializationData data, object o)
 {
     return(o.ToString());
 }
コード例 #15
0
ファイル: StringUON.cs プロジェクト: Hengle/clapotis
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     return(raw.Replace("\\\"", "\"").ToString(1, raw.Length - 2));
 }
コード例 #16
0
ファイル: StringUON.cs プロジェクト: Hengle/clapotis
 public override string  Serialize(UON.SerializationData data, object o)
 {
     return("\"" + (o as string).Replace("\"", "\\\"") + '"');
 }
コード例 #17
0
ファイル: ClassUON.cs プロジェクト: Hengle/clapotis
        public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
        {
            if (raw[0] == '#')
            {
                return(data.deserializedReferences[int.Parse(raw.ToString(1, raw.Length - 1))]);
            }

            if (raw[0] != '{')
            {
                throw new FormatException("No opening char '{' found in \"" + raw + "\".");
            }

            StringBuilder currentType = UONUtility.GetBuffer();
            string        key         = null;
            int           deep        = 0;
            Step          step        = Step.OpenQuoteKey;

            if (instance == null)
            {
                if (typeof(ScriptableObject).IsAssignableFrom(data.latestType) == true)
                {
                    instance = ScriptableObject.CreateInstance(data.latestType);
                }
                else
                {
#if !NETFX_CORE
                    if (data.latestType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null) == null)
                    {
                        instance = FormatterServices.GetUninitializedObject(data.latestType);
                    }
                    else
#else
                    if (data.latestType.GetConstructor(Type.EmptyTypes) == null)
#endif
                    { instance = Activator.CreateInstance(data.latestType); }
                }
            }

            data.deserializedReferences.Add(instance);

            IUONSerialization deserializationInterface = instance as IUONSerialization;

            if (deserializationInterface != null)
            {
                this.fieldsData.entries.Clear();
            }

            if (raw[1] != '}')
            {
                for (int i = 1; i < raw.Length; i++)
                {
                    if (step == Step.OpenQuoteKey)
                    {
                        if (raw[i] != '"')
                        {
                            throw new FormatException("Expected '\"' instead of \"" + raw[i] + "\" at position " + i + ".");
                        }

                        ++step;
                    }
                    else if (step == Step.Key)
                    {
                        for (; i < raw.Length; i++)
                        {
                            if (raw[i] == '"')
                            {
                                key = currentType.ToString();
                                currentType.Length = 0;
                                ++step;
                                break;
                            }

                            currentType.Append(raw[i]);
                        }
                    }
                    else if (step == Step.Colon)
                    {
                        if (raw[i] != ':')
                        {
                            throw new FormatException("Expected ':' instead of \"" + raw[i] + "\" at position " + i + ".");
                        }

                        ++step;
                    }
                    else if (step == Step.Value)
                    {
                        bool inText = false;

                        for (; i < raw.Length; i++)
                        {
                            if (raw[i] == '"' && (inText == false || this.IsSpecialCharCancelled(raw, i) == false))
                            {
                                inText = !inText;
                            }
                            else if ((raw[i] == '{' || raw[i] == '[') && inText == false)
                            {
                                ++deep;
                            }
                            else if ((raw[i] == '}' || raw[i] == ']' || raw[i] == ',') && inText == false)
                            {
                                if (deep == 0 && currentType.Length > 0)
                                {
                                    if (UON.VerboseLevel > 0)
                                    {
                                        Debug.Log(key);
                                        Debug.Log(currentType.ToString());
                                    }

                                    if (deserializationInterface != null)
                                    {
                                        this.fieldsData.entries.Add(key, currentType.ToString());
                                    }

                                    data.AssignField(key, currentType, instance);

                                    currentType.Length = 0;
                                    step = Step.Comma;
                                    --i;
                                    break;
                                }

                                if (raw[i] == '}' || raw[i] == ']')
                                {
                                    --deep;
                                }
                            }

                            currentType.Append(raw[i]);
                        }
                    }
                    else if (step == Step.Comma)
                    {
                        if (raw[i] == '}')
                        {
                            break;
                        }

                        if (raw[i] != ',')
                        {
                            throw new FormatException("Expected ',' instead of \"" + raw[i] + "\" at position " + i + ".");
                        }

                        step = Step.OpenQuoteKey;
                    }
                }
            }

            UONUtility.RestoreBuffer(currentType);

            if (deserializationInterface != null)
            {
                deserializationInterface.OnDeserialized(this.fieldsData);
            }

            return(instance);
        }
コード例 #18
0
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     return(UInt32.Parse(raw.ToString()));
 }
コード例 #19
0
ファイル: UONType.cs プロジェクト: Hengle/clapotis
 public abstract string  Serialize(UON.SerializationData data, object instance);
コード例 #20
0
 public override object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance)
 {
     return(raw.ToString().HexToByte());
 }
コード例 #21
0
ファイル: UONType.cs プロジェクト: Hengle/clapotis
 public abstract object  Deserialize(UON.SerializationData data, StringBuilder raw, object instance);