示例#1
0
 public IEnumerable <Object> FetchDependencies(ISerializedFile file, bool isLog = false)
 {
     if (Type == PrimitiveType.Complex)
     {
         if (IsArray)
         {
             IEnumerable <ISerializableStructure> structures = (IEnumerable <ISerializableStructure>)Value;
             foreach (ISerializableStructure structure in structures)
             {
                 foreach (Object asset in structure.FetchDependencies(file, isLog))
                 {
                     yield return(asset);
                 }
             }
         }
         else
         {
             ISerializableStructure structure = (ISerializableStructure)Value;
             foreach (Object asset in structure.FetchDependencies(file, isLog))
             {
                 yield return(asset);
             }
         }
     }
 }
示例#2
0
        private static SerializableStructure ForceCreateComplexStructure(SerializableType type, int depth)
        {
            SerializableStructure @base = type.Base == null ? null : ForceCreateComplexStructure(type.Base, depth);

            if (type.Fields.Count > 0 && depth <= MaxDepthLevel)
            {
                List <SerializableField> fields = new List <SerializableField>();
                foreach (Field field in type.Fields)
                {
                    if (depth == MaxDepthLevel)
                    {
                        if (field.Type.Type == PrimitiveType.Complex)
                        {
                            continue;
                        }
                        if (field.IsArray)
                        {
                            continue;
                        }
                    }

                    ISerializableStructure fieldStructure = field.Type.Type == PrimitiveType.Complex ? CreateComplexStructure(field.Type, depth + 1) : null;
                    SerializableField      sField         = new SerializableField(field.Type.Type, fieldStructure, field.IsArray, field.Name);
                    fields.Add(sField);
                }
                return(new SerializableStructure(type, @base, fields));
            }
            else
            {
                return(new SerializableStructure(type, @base, EmptyFields));
            }
        }
示例#3
0
 public SerializableField(PrimitiveType type, ISerializableStructure complex, bool isArray, string name)
 {
     Type        = type;
     ComplexType = (type == PrimitiveType.Complex && complex == null) ? throw new ArgumentNullException(nameof(complex)) : complex;
     IsArray     = isArray;
     Name        = name ?? throw new ArgumentNullException(nameof(name));
 }
 public IEnumerable <PPtr <Object> > FetchDependencies(DependencyContext context)
 {
     if (Type == PrimitiveType.Complex)
     {
         if (IsArray)
         {
             ISerializableStructure[] structures = (ISerializableStructure[])Value;
             foreach (PPtr <Object> asset in context.FetchDependencies(structures, Name))
             {
                 yield return(asset);
             }
         }
         else
         {
             ISerializableStructure structure = (ISerializableStructure)Value;
             foreach (PPtr <Object> asset in context.FetchDependencies(structure, Name))
             {
                 yield return(asset);
             }
         }
     }
 }
示例#5
0
        public static void DumpSerializedTypes(SerializableStructure structure, StreamWriter sw, int indent)
        {
            string spaces = new string(' ', indent * 2);

            if (indent > 10)
            {
                sw.WriteLine($"{spaces}Max depth exceded");
            }
            sw.WriteLine($"{spaces}{structure.Type} : {structure.Base?.ToString() ?? "object"}");
            if (structure.Base != null && structure.Base.Type.Namespace != "UnityEngine")
            {
                DumpSerializedTypes(structure.Base, sw, indent + 1);
            }
            foreach (var field in structure.Fields)
            {
                spaces = new string(' ', (indent + 1) * 2);
                if (field.Type == PrimitiveType.Complex)
                {
                    ISerializableStructure ComplexType = Util.GetMember <ISerializableStructure>(field, "ComplexType");
                    if (ComplexType is SerializablePointer pptr)
                    {
                        sw.WriteLine($"{spaces}PPTR<{ComplexType}> {field.Name};");
                    }
                    else if (ComplexType is SerializableStructure fieldStructure)
                    {
                        sw.WriteLine($"{spaces}{fieldStructure} {field.Name};");
                        DumpSerializedTypes(fieldStructure, sw, indent + 1);
                    }
                    else
                    {
                        sw.WriteLine($"{spaces}{ComplexType} {field.Name};");
                    }
                }
                else
                {
                    sw.WriteLine($"{spaces}{field.Type} {field.Name};");
                }
            }
        }
示例#6
0
        public void Read(AssetReader reader)
        {
            switch (Type)
            {
            case PrimitiveType.Bool:
                if (IsArray)
                {
                    Value = reader.ReadBooleanArray();
                }
                else
                {
                    Value = reader.ReadBoolean();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Char:
                if (IsArray)
                {
                    Value = reader.ReadCharArray();
                }
                else
                {
                    Value = reader.ReadChar();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.SByte:
                if (IsArray)
                {
                    Value = reader.ReadByteArray();
                }
                else
                {
                    Value = reader.ReadSByte();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Byte:
                if (IsArray)
                {
                    Value = reader.ReadByteArray();
                }
                else
                {
                    Value = reader.ReadByte();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Short:
                if (IsArray)
                {
                    Value = reader.ReadInt16Array();
                }
                else
                {
                    Value = reader.ReadInt16();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.UShort:
                if (IsArray)
                {
                    Value = reader.ReadUInt16Array();
                }
                else
                {
                    Value = reader.ReadUInt16();
                }
                reader.AlignStream(AlignType.Align4);
                break;

            case PrimitiveType.Int:
                if (IsArray)
                {
                    Value = reader.ReadInt32Array();
                }
                else
                {
                    Value = reader.ReadInt32();
                }
                break;

            case PrimitiveType.UInt:
                if (IsArray)
                {
                    Value = reader.ReadUInt32Array();
                }
                else
                {
                    Value = reader.ReadUInt32();
                }
                break;

            case PrimitiveType.Long:
                if (IsArray)
                {
                    Value = reader.ReadInt64Array();
                }
                else
                {
                    Value = reader.ReadInt64();
                }
                break;

            case PrimitiveType.ULong:
                if (IsArray)
                {
                    Value = reader.ReadUInt64Array();
                }
                else
                {
                    Value = reader.ReadUInt64();
                }
                break;

            case PrimitiveType.Single:
                if (IsArray)
                {
                    Value = reader.ReadSingleArray();
                }
                else
                {
                    Value = reader.ReadSingle();
                }
                break;

            case PrimitiveType.Double:
                if (IsArray)
                {
                    Value = reader.ReadDoubleArray();
                }
                else
                {
                    Value = reader.ReadDouble();
                }
                break;

            case PrimitiveType.String:
                if (IsArray)
                {
                    Value = reader.ReadStringArray();
                }
                else
                {
                    Value = reader.ReadString();
                }
                break;

            case PrimitiveType.Complex:
                if (IsArray)
                {
                    int count = reader.ReadInt32();
                    ISerializableStructure[] structures = new ISerializableStructure[count];
                    for (int i = 0; i < count; i++)
                    {
                        ISerializableStructure structure = ComplexType.CreateDuplicate();
                        structure.Read(reader);
                        structures[i] = structure;
                    }
                    Value = structures;
                }
                else
                {
                    ISerializableStructure structure = ComplexType.CreateDuplicate();
                    structure.Read(reader);
                    Value = structure;
                }
                break;

            default:
                throw new NotImplementedException($"Unknown {nameof(PrimitiveType)} '{Type}'");
            }
        }
示例#7
0
        public YAMLNode ExportYAML(IExportContainer container)
        {
            if (IsArray)
            {
                if (Type == PrimitiveType.Complex)
                {
                    IEnumerable <ISerializableStructure> structures = (IEnumerable <ISerializableStructure>)Value;
                    return(structures.ExportYAML(container));
                }
                else
                {
                    switch (Type)
                    {
                    case PrimitiveType.Bool:
                    {
                        bool[] array = (bool[])Value;
                        return(array.ExportYAML());
                    }

                    case PrimitiveType.Char:
                    {
                        char[] array = (char[])Value;
                        return(array.ExportYAML());
                    }

                    case PrimitiveType.SByte:
                    {
                        byte[] array = (byte[])Value;
                        return(array.ExportYAML());
                    }

                    case PrimitiveType.Byte:
                    {
                        byte[] array = (byte[])Value;
                        return(array.ExportYAML());
                    }

                    case PrimitiveType.Short:
                    {
                        short[] array = (short[])Value;
                        return(array.ExportYAML(true));
                    }

                    case PrimitiveType.UShort:
                    {
                        ushort[] array = (ushort[])Value;
                        return(array.ExportYAML(true));
                    }

                    case PrimitiveType.Int:
                    {
                        int[] array = (int[])Value;
                        return(array.ExportYAML(true));
                    }

                    case PrimitiveType.UInt:
                    {
                        uint[] array = (uint[])Value;
                        return(array.ExportYAML(true));
                    }

                    case PrimitiveType.Long:
                    {
                        long[] array = (long[])Value;
                        return(array.ExportYAML(true));
                    }

                    case PrimitiveType.ULong:
                    {
                        ulong[] array = (ulong[])Value;
                        return(array.ExportYAML(true));
                    }

                    case PrimitiveType.Single:
                    {
                        float[] array = (float[])Value;
                        return(array.ExportYAML());
                    }

                    case PrimitiveType.Double:
                    {
                        double[] array = (double[])Value;
                        return(array.ExportYAML());
                    }

                    case PrimitiveType.String:
                    {
                        string[] array = (string[])Value;
                        return(array.ExportYAML());
                    }

                    default:
                        throw new NotSupportedException(Type.ToString());
                    }
                }
            }
            else
            {
                if (Type == PrimitiveType.Complex)
                {
                    ISerializableStructure structure = (ISerializableStructure)Value;
                    return(structure.ExportYAML(container));
                }
                else
                {
                    switch (Type)
                    {
                    case PrimitiveType.Bool:
                        return(new YAMLScalarNode((bool)Value));

                    case PrimitiveType.Char:
                        return(new YAMLScalarNode((int)(char)Value));

                    case PrimitiveType.SByte:
                        return(new YAMLScalarNode((sbyte)Value));

                    case PrimitiveType.Byte:
                        return(new YAMLScalarNode((byte)Value));

                    case PrimitiveType.Short:
                        return(new YAMLScalarNode((short)Value));

                    case PrimitiveType.UShort:
                        return(new YAMLScalarNode((ushort)Value));

                    case PrimitiveType.Int:
                        return(new YAMLScalarNode((int)Value));

                    case PrimitiveType.UInt:
                        return(new YAMLScalarNode((uint)Value));

                    case PrimitiveType.Long:
                        return(new YAMLScalarNode((long)Value));

                    case PrimitiveType.ULong:
                        return(new YAMLScalarNode((ulong)Value));

                    case PrimitiveType.Single:
                        return(new YAMLScalarNode((float)Value));

                    case PrimitiveType.Double:
                        return(new YAMLScalarNode((double)Value));

                    case PrimitiveType.String:
                        return(new YAMLScalarNode((string)Value));

                    default:
                        throw new NotSupportedException(Type.ToString());
                    }
                }
            }
        }