Пример #1
0
#pragma warning restore 0649

        // Parsing and verification

        private static IEnumerable <IColliderSerializer> SerializeColliderRecords
        (
            IEnumerable <TextRecordParsing.Record> sourceRecords,
            List <DynamicsSetup.ParseMessage> errorRecords
        )
        {
            var serializerClasses = new Dictionary <string, System.Type>
            {
                { SphereColliderToken, typeof(SphereColliderSerializer) },
                { CapsuleColliderToken, typeof(CapsuleColliderSerializer) },
                { PanelColliderToken, typeof(PanelColliderSerializer) },
            };

            var colliderSerializers = new List <IColliderSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                IColliderSerializer        newColliderInfo = null;
                DynamicsSetup.ParseMessage error           = null;
                var baseInfo = DynamicsSetup.SerializeObjectFromStrings <ColliderSerializerBaseInfo>(sourceRecord.Items, null, ref error);
                if (baseInfo != null)
                {
                    System.Type serializerType;
                    if (serializerClasses.TryGetValue(baseInfo.colliderType, out serializerType))
                    {
                        newColliderInfo = DynamicsSetup.SerializeObjectFromStrings(
                            serializerType, sourceRecord.Items, "linkedRenderer", ref error)
                                          as IColliderSerializer;
                    }
                    else
                    {
                        error = new DynamicsSetup.ParseMessage("Invalid collider type: " + baseInfo.colliderType, sourceRecord.Items);
                    }
                }

                if (newColliderInfo != null)
                {
                    colliderSerializers.Add(newColliderInfo);
                }
                else
                {
                    errorRecords.Add(error);
                }
            }
            return(colliderSerializers);
        }
#pragma warning restore 0649

        // Object serialization

        private static IEnumerable <PivotSerializer> SerializePivotRecords
        (
            IEnumerable <TextRecordParsing.Record> sourceRecords,
            List <DynamicsSetup.ParseMessage> errorRecords
        )
        {
            var validRecords = new List <PivotSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                DynamicsSetup.ParseMessage error = null;
                var newRecord = DynamicsSetup.SerializeObjectFromStrings <PivotSerializer>(sourceRecord.Items, null, ref error);
                if (newRecord != null)
                {
                    validRecords.Add(newRecord);
                }
                else
                {
                    errorRecords.Add(error);
                }
            }
            return(validRecords);
        }