Exemple #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
                });
            }
        // Version and CSV content detection
        // If version 3, import settings will be changed to reflect whether the file is bone-only or collider-only
        private static bool VerifyVersionAndDetectContents(string recordText, ImportSettings importSettings, out string errorMessage)
        {
            errorMessage = "";
            var version = UnknownVersion;

            try
            {
                var sourceRecords = TextRecordParsing.ParseRecordsFromText(recordText);
                version = GetVersionFromSetupRecords(sourceRecords);
            }
            catch (System.Exception exception)
            {
                errorMessage = string.Format("SpringBoneSetup: ���̃e�L�X�g�f�[�^��ǂݍ��߂܂���ł����I\n\n{0}", exception.ToString());
                return(false);
            }

            const int VersionSpringBonesOnly = 3;
            const int MinSupportedVersion    = VersionSpringBonesOnly;
            const int MaxSupportedVersion    = 4;

            if (version == UnknownVersion)
            {
                // No version means it's probably colliders-only, but check if there are SpringBones just in case
                if (!recordText.ToLowerInvariant().Contains("[springbones]"))
                {
                    importSettings.ImportSpringBones = false;
                }
            }
            else
            {
                if (version < MinSupportedVersion ||
                    version > MaxSupportedVersion)
                {
                    errorMessage = string.Format("SpringBoneSetup: �f�[�^�̃o�[�W�����͑Ή����Ă��܂���I\nVersion: {0}", version);
                    return(false);
                }

                if (version <= VersionSpringBonesOnly)
                {
                    importSettings.ImportCollision = false;
                }
            }

            return(true);
        }
 public bool TryGetVector3(int startIndex, ref Vector3 output)
 {
     return(TextRecordParsing.GetVector3(items, startIndex, ref output));
 }
 public bool TryGetFloat(int index, ref float output)
 {
     return(TextRecordParsing.GetFloat(items, index, ref output));
 }
 public bool GetBool(int index)
 {
     return(TextRecordParsing.GetBool(items, index));
 }
 public string GetString(int index)
 {
     return(TextRecordParsing.GetString(items, index));
 }
Exemple #7
0
            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
                });
            }