Пример #1
0
            public static ParsedColliderSetup ReadColliderSetupFromText(GameObject colliderRoot, string recordText)
            {
                List <TextRecordParsing.Record> rawColliderRecords     = null;
                List <TextRecordParsing.Record> rawDynamicsNullRecords = null;
                List <TextRecordParsing.Record> rawComponentRecords    = null;

                try
                {
                    var sourceRecords = TextRecordParsing.ParseRecordsFromText(recordText);
                    TextRecordParsing.Record versionRecord = null;
                    DynamicsSetup.GetVersionFromSetupRecords(sourceRecords, out versionRecord);
                    rawColliderRecords = TextRecordParsing.GetSectionRecords(sourceRecords, "Colliders");
                    // Only try to read collider records from the root section if there is no version record (old collider-only CSV)
                    if (versionRecord == null)
                    {
                        if (rawColliderRecords == null || rawColliderRecords.Count == 0)
                        {
                            rawColliderRecords = TextRecordParsing.GetSectionRecords(sourceRecords, null);
                        }
                    }
                    rawDynamicsNullRecords = TextRecordParsing.GetSectionRecords(sourceRecords, "DynamicsNulls");
                    rawComponentRecords    = TextRecordParsing.GetSectionRecords(sourceRecords, "Components");
                }
                catch (System.Exception exception)
                {
                    Debug.LogError("SpringColliderSetup: 元のテキストデータを読み込めませんでした!\n\n" + exception.ToString());
                    return(null);
                }

                var errors              = new List <DynamicsSetup.ParseMessage>();
                var colliderRecords     = SerializeColliderRecords(rawColliderRecords, errors);
                var dynamicsNullRecords = SerializeTransformRecords(rawDynamicsNullRecords, errors);

                var validParentNames         = colliderRoot.GetComponentsInChildren <Transform>(true).Select(item => item.name).ToList();
                var validDynamicsNullRecords = new List <TransformSerializer>();

                VerifyTransformRecords(dynamicsNullRecords, validParentNames, validDynamicsNullRecords, errors);

                // Colliders get added after DynamicsNulls, so they can be added as children to them
                validParentNames.AddRange(validDynamicsNullRecords.Select(item => item.name));
                var validColliderRecords = new List <IColliderSerializer>();

                VerifyColliderRecords(colliderRecords, colliderRoot, validParentNames, validColliderRecords, errors);

                // Todo: Verify Component records

                return(new ParsedColliderSetup
                {
                    colliderRecords = validColliderRecords,
                    dynamicsNullRecords = validDynamicsNullRecords,
                    componentRecords = rawComponentRecords,
                    Errors = errors
                });
            }
Пример #2
0
        // For internal use

        public static int GetVersionFromSetupRecords
        (
            List <TextRecordParsing.Record> sourceRecords,
            out TextRecordParsing.Record versionRecord
        )
        {
            var          version      = UnknownVersion;
            const string VersionToken = "version";

            versionRecord = sourceRecords.FirstOrDefault(item => item.GetString(0).ToLowerInvariant() == VersionToken);
            if (versionRecord != null)
            {
                versionRecord.TryGetInt(1, ref version);
            }
            return(version);
        }
            public static ParsedSpringBoneSetup ReadSpringBoneSetupFromText
            (
                GameObject springBoneRoot,
                GameObject colliderRoot,
                string recordText,
                IEnumerable <string> inputValidColliderNames
            )
            {
                List <TextRecordParsing.Record> rawSpringBoneRecords = null;
                List <TextRecordParsing.Record> rawPivotRecords      = null;

                try
                {
                    var sourceRecords = TextRecordParsing.ParseRecordsFromText(recordText);
                    TextRecordParsing.Record versionRecord = null;
                    DynamicsSetup.GetVersionFromSetupRecords(sourceRecords, out versionRecord);
                    rawSpringBoneRecords = TextRecordParsing.GetSectionRecords(sourceRecords, "SpringBones");
                    if (rawSpringBoneRecords == null || rawSpringBoneRecords.Count == 0)
                    {
                        rawSpringBoneRecords = TextRecordParsing.GetSectionRecords(sourceRecords, null)
                                               .Where(item => item != versionRecord)
                                               .ToList();
                    }
                    rawPivotRecords = TextRecordParsing.GetSectionRecords(sourceRecords, "Pivots");
                }
                catch (System.Exception exception)
                {
                    Debug.LogError("SpringBoneSetup: 元のテキストデータを読み込めませんでした!\n\n" + exception.ToString());
                    return(null);
                }

                var errors            = new List <DynamicsSetup.ParseMessage>();
                var pivotRecords      = SerializePivotRecords(rawPivotRecords, errors);
                var springBoneRecords = SerializeSpringBoneRecords(rawSpringBoneRecords, errors);

                var validObjectNames = springBoneRoot.GetComponentsInChildren <Transform>(true)
                                       .Select(item => item.name).Distinct().ToList();
                var validPivotRecords = new List <PivotSerializer>();

                VerifyPivotRecords(pivotRecords, validObjectNames, validPivotRecords, errors);

                var validPivotNames = new List <string>(validObjectNames);

                validPivotNames.AddRange(validPivotRecords.Select(record => record.name));

                var validColliderNames = new List <string>();
                var colliderTypes      = SpringColliderSetup.GetColliderTypes();

                validColliderNames.AddRange(colliderTypes
                                            .SelectMany(type => colliderRoot.GetComponentsInChildren(type, true))
                                            .Select(item => item.name));
                if (inputValidColliderNames != null)
                {
                    validColliderNames.AddRange(inputValidColliderNames);
                }

                var  validSpringBoneRecords = new List <SpringBoneSerializer>();
                bool hasMissingColliders;

                VerifySpringBoneRecords(
                    springBoneRecords,
                    validObjectNames,
                    validPivotNames,
                    validColliderNames,
                    validSpringBoneRecords,
                    out hasMissingColliders,
                    errors);

                if (hasMissingColliders)
                {
                    Debug.LogWarning("スプリングボーンセットアップ:一部のコライダーが見つかりません");
                }

                return(new ParsedSpringBoneSetup
                {
                    pivotRecords = validPivotRecords,
                    springBoneRecords = validSpringBoneRecords,
                    Errors = errors
                });
            }