Пример #1
0
        private static bool VerifyTransformRecord
        (
            TransformSerializer transformSerializer,
            IEnumerable <string> validParentNames,
            out DynamicsSetup.ParseMessage error
        )
        {
            error = null;
            var objectName = transformSerializer.name;

            if (objectName.Length == 0)
            {
                // Todo: Need more details...
                error = new DynamicsSetup.ParseMessage("コライダー名が指定されていないものがあります");
            }

            var parentName = transformSerializer.parentName;

            if (parentName.Length == 0)
            {
                error = new DynamicsSetup.ParseMessage(objectName + " : 親名が指定されていません");
            }
            else if (!validParentNames.Contains(parentName))
            {
                error = new DynamicsSetup.ParseMessage(objectName + " : 親が見つかりません: " + parentName);
            }

            return(error == null);
        }
Пример #2
0
        private static bool VerifyTransformRecords
        (
            IEnumerable <TransformSerializer> sourceRecords,
            IEnumerable <string> validParentNames,
            List <TransformSerializer> validRecords,
            List <DynamicsSetup.ParseMessage> errors
        )
        {
            var newValidRecords = new List <TransformSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                DynamicsSetup.ParseMessage error = null;
                var isValidRecord = VerifyTransformRecord(sourceRecord, validParentNames, out error);
                if (isValidRecord)
                {
                    if (newValidRecords.Any(item => item.name == sourceRecord.name))
                    {
                        error         = new DynamicsSetup.ParseMessage(sourceRecord.name + " : 名前が重複します");
                        isValidRecord = false;
                    }
                }

                if (isValidRecord)
                {
                    newValidRecords.Add(sourceRecord);
                }
                else
                {
                    errors.Add(error);
                }
            }
            validRecords.AddRange(newValidRecords);
            return(sourceRecords.Count() == newValidRecords.Count);
        }
Пример #3
0
        private static bool VerifyColliderRecords
        (
            IEnumerable <IColliderSerializer> colliderRecords,
            GameObject rootObject,
            IEnumerable <string> validParentNames,
            List <IColliderSerializer> validRecords,
            List <DynamicsSetup.ParseMessage> errors
        )
        {
            var newValidRecords = new List <IColliderSerializer>(colliderRecords.Count());

            foreach (var sourceRecord in colliderRecords)
            {
                DynamicsSetup.ParseMessage error = null;
                var objectName    = sourceRecord.GetBaseInfo().transform.name;
                var isValidRecord = true;
                if (!VerifyTransformRecord(sourceRecord.GetBaseInfo().transform, validParentNames, out error))
                {
                    isValidRecord = false;
                }

                var linkedRendererName = sourceRecord.GetLinkedRendererName();
                if (!string.IsNullOrEmpty(linkedRendererName) &&
                    rootObject.FindChildComponentByName <Renderer>(linkedRendererName) == null)
                {
                    error         = new DynamicsSetup.ParseMessage(objectName + " : linkedRendererが見つかりません: " + linkedRendererName);
                    isValidRecord = false;
                }

                if (newValidRecords.Any(item => item.GetBaseInfo().transform.name == objectName))
                {
                    error         = new DynamicsSetup.ParseMessage(objectName + " : 名前が重複します");
                    isValidRecord = false;
                }

                if (isValidRecord)
                {
                    newValidRecords.Add(sourceRecord);
                }
                else
                {
                    errors.Add(error);
                }
            }
            validRecords.AddRange(newValidRecords);
            return(colliderRecords.Count() == newValidRecords.Count);
        }
Пример #4
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);
        }
Пример #5
0
        // Verification

        private static bool VerifyPivotRecords
        (
            IEnumerable <PivotSerializer> sourceRecords,
            IEnumerable <string> validParentNames,
            List <PivotSerializer> validRecords,
            List <DynamicsSetup.ParseMessage> errors
        )
        {
            var newValidRecords = new List <PivotSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                DynamicsSetup.ParseMessage error = null;
                if (sourceRecord.name.Length == 0)
                {
                    // Todo: Need more details...
                    error = new DynamicsSetup.ParseMessage("名前が指定されていない基点オブジェクトがあります");
                }

                var parentName = sourceRecord.parentName;
                if (parentName.Length == 0)
                {
                    error = new DynamicsSetup.ParseMessage(sourceRecord.name + " : 親名が指定されていません");
                }
                else if (!validParentNames.Contains(parentName))
                {
                    error = new DynamicsSetup.ParseMessage(sourceRecord.name + " : 親が見つかりません: " + parentName);
                }

                if (error == null)
                {
                    newValidRecords.Add(sourceRecord);
                }
                else
                {
                    errors.Add(error);
                }
            }
            validRecords.AddRange(newValidRecords);
            return(sourceRecords.Count() == newValidRecords.Count());
        }
Пример #6
0
        private static IEnumerable <SpringBoneSerializer> SerializeSpringBoneRecords
        (
            IEnumerable <TextRecordParsing.Record> sourceRecords,
            List <DynamicsSetup.ParseMessage> errorRecords
        )
        {
            var validRecords = new List <SpringBoneSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                var itemQueue = sourceRecord.ToQueue();
                SpringBoneBaseSerializer   newBaseRecord = null;
                DynamicsSetup.ParseMessage error         = null;
                try
                {
                    newBaseRecord = itemQueue.DequeueObject <SpringBoneBaseSerializer>();
                }
                catch (System.Exception exception)
                {
                    error = new DynamicsSetup.ParseMessage("Error building SpringBoneBaseSerializer", sourceRecord.Items, exception.ToString());
                }

                if (newBaseRecord != null)
                {
                    // The rest of the queue should be collider names
                    var colliderNames = new List <string>(itemQueue).Where(item => item.Length > 0);
                    var newRecord     = new SpringBoneSerializer
                    {
                        baseData      = newBaseRecord,
                        colliderNames = colliderNames.ToArray()
                    };
                    validRecords.Add(newRecord);
                }
                else
                {
                    errorRecords.Add(error);
                }
            }
            return(validRecords);
        }
Пример #7
0
        private static IEnumerable <TransformSerializer> SerializeTransformRecords
        (
            IEnumerable <TextRecordParsing.Record> sourceRecords,
            List <DynamicsSetup.ParseMessage> errorRecords
        )
        {
            var transformRecords = new List <TransformSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                DynamicsSetup.ParseMessage error = null;
                var transformRecord = DynamicsSetup.SerializeObjectFromStrings <TransformSerializer>(sourceRecord.Items, null, ref error);
                if (transformRecord != null)
                {
                    transformRecords.Add(transformRecord);
                }
                else
                {
                    errorRecords.Add(error);
                }
            }
            return(transformRecords);
        }
Пример #8
0
        private static bool VerifySpringBoneRecords
        (
            IEnumerable <SpringBoneSerializer> sourceRecords,
            IEnumerable <string> validBoneNames,
            IEnumerable <string> validPivotNames,
            IEnumerable <string> validColliderNames,
            List <SpringBoneSerializer> validRecords,
            out bool hasMissingColliders,
            List <DynamicsSetup.ParseMessage> errors
        )
        {
            hasMissingColliders = false;
            var newValidRecords = new List <SpringBoneSerializer>(sourceRecords.Count());

            foreach (var sourceRecord in sourceRecords)
            {
                DynamicsSetup.ParseMessage error = null;
                var baseData = sourceRecord.baseData;
                if (baseData.boneName.Length == 0)
                {
                    // Todo: Need more details...
                    error = new DynamicsSetup.ParseMessage("名前が指定されていない基点オブジェクトがあります");
                }
                else if (!validBoneNames.Contains(baseData.boneName))
                {
                    error = new DynamicsSetup.ParseMessage(baseData.boneName + " : オブジェくトが見つかりません");
                }

                var pivotName = baseData.pivotName;
                if (pivotName.Length == 0)
                {
                    error = new DynamicsSetup.ParseMessage(baseData.boneName + " : 基点名が指定されていません");
                }
                else if (!validPivotNames.Contains(pivotName))
                {
                    error = new DynamicsSetup.ParseMessage(baseData.boneName + " : 基点オブジェクトが見つかりません: " + pivotName);
                }

                var missingColliders = sourceRecord.colliderNames
                                       .Where(name => !validColliderNames.Contains(name));
                if (missingColliders.Any())
                {
                    // Missing colliders are just a warning
                    hasMissingColliders = true;
                    Debug.LogWarning(
                        baseData.boneName + " : コライダーが見つかりません:\n"
                        + string.Join(" ", missingColliders.ToArray()));
                }

                if (error == null)
                {
                    newValidRecords.Add(sourceRecord);
                }
                else
                {
                    errors.Add(error);
                }
            }
            validRecords.AddRange(newValidRecords);
            return(sourceRecords.Count() == newValidRecords.Count());
        }