private void BrowseAndLoadSpringSetup()
        {
            string checkErrorMessage;

            if (!IsOkayToSetup(out checkErrorMessage))
            {
                Debug.LogError(checkErrorMessage);
                return;
            }

            // var initialPath = "";
            var initialDirectory = ""; // System.IO.Path.GetDirectoryName(initialPath);
            var fileFilters      = new string[] { "CSV文件", "csv", "文本文件", "txt" };
            var path             = EditorUtility.OpenFilePanelWithFilters(
                "导入SpringBone", initialDirectory, fileFilters);

            if (path.Length == 0)
            {
                return;
            }

            var sourceText = FileUtil.ReadAllText(path);

            if (string.IsNullOrEmpty(sourceText))
            {
                return;
            }

            var parsedSetup = DynamicsSetup.ParseFromRecordText(springBoneRoot, springBoneRoot, sourceText, importSettings);

            if (parsedSetup.Setup != null)
            {
                var buildAction = new BuildDynamicsAction(parsedSetup.Setup, path, springBoneRoot);
                if (parsedSetup.HasErrors)
                {
                    SpringBoneSetupErrorWindow.ShowWindow(springBoneRoot, springBoneRoot, path, parsedSetup.Errors, buildAction);
                }
                else
                {
                    buildAction.Perform();
                }
            }
            else
            {
                const string ErrorFormat =
                    "SpringBone导入失败。\n"
                    + "原始数据中有错误,\n"
                    + "或数据与骨骼名称不匹配。\n"
                    + "详细信息请查看Console的日志。\n\n"
                    + "springBoneRoot: {0}\n\n"
                    + "Path: {1}";
                var resultErrorMessage = string.Format(ErrorFormat, springBoneRoot.name, path);
                EditorUtility.DisplayDialog("导入SpringBone", resultErrorMessage, "OK");
                Debug.LogError("SpringBone导入失败: " + springBoneRoot.name + "\n" + path);
            }
            Close();
        }
Exemplo n.º 2
0
        private void BrowseAndLoadSpringSetup()
        {
            string checkErrorMessage;

            if (!IsOkayToSetup(out checkErrorMessage))
            {
                Debug.LogError(checkErrorMessage);
                return;
            }

            // var initialPath = "";
            var initialDirectory = ""; // System.IO.Path.GetDirectoryName(initialPath);
            var fileFilters      = new string[] { "CSVファイル", "csv", "テキストファイル", "txt" };
            var path             = EditorUtility.OpenFilePanelWithFilters(
                "スプリングボーンセットアップを読み込む", initialDirectory, fileFilters);

            if (path.Length == 0)
            {
                return;
            }

            var sourceText = FileUtil.ReadAllText(path);

            if (string.IsNullOrEmpty(sourceText))
            {
                return;
            }

            var parsedSetup = DynamicsSetup.ParseFromRecordText(springBoneRoot, springBoneRoot, sourceText, importSettings);

            if (parsedSetup.Setup != null)
            {
                var buildAction = new BuildDynamicsAction(parsedSetup.Setup, path, springBoneRoot);
                if (parsedSetup.HasErrors)
                {
                    SpringBoneSetupErrorWindow.ShowWindow(springBoneRoot, springBoneRoot, path, parsedSetup.Errors, buildAction);
                }
                else
                {
                    buildAction.Perform();
                }
            }
            else
            {
                const string ErrorFormat =
                    "スプリングボーンセットアップが失敗しました。\n"
                    + "元データにエラーがあるか、もしくは\n"
                    + "キャラクターにデータが一致しません。\n"
                    + "詳しくはConsoleのログをご覧下さい。\n\n"
                    + "キャラクター: {0}\n\n"
                    + "パス: {1}";
                var resultErrorMessage = string.Format(ErrorFormat, springBoneRoot.name, path);
                EditorUtility.DisplayDialog("スプリングボーンセットアップ", resultErrorMessage, "OK");
                Debug.LogError("スプリングボーンセットアップ失敗: " + springBoneRoot.name + "\n" + path);
            }
            Close();
        }
Exemplo n.º 3
0
        public static void AutoLoad(SpringManager springManager)
        {
            var autoSavePath = GetAutoSavePath(springManager.name);

            if (System.IO.File.Exists(autoSavePath))
            {
                var sourceText = FileUtil.ReadAllText(autoSavePath);
                DynamicsSetup.BuildFromRecordText(springManager.gameObject, springManager.gameObject, sourceText);
            }
        }
 public BuildDynamicsAction
 (
     DynamicsSetup newSetup,
     string newPath,
     GameObject newSpringBoneRoot
 )
 {
     setup          = newSetup;
     path           = newPath;
     springBoneRoot = newSpringBoneRoot;
 }
Exemplo n.º 5
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
                });
            }
Exemplo n.º 6
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);
        }
            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
                });
            }
Exemplo n.º 9
0
        private static ParseResults InternalParseFromRecordText
        (
            GameObject springBoneRoot,
            GameObject colliderRoot,
            string recordText,
            ImportSettings importSettings
        )
        {
            if (recordText.Length == 0)
            {
                return(new ParseResults());
            }

            // Copy the source import settings in case we need to change them based on the source text
            var actualImportSettings = (importSettings != null)
                ? new ImportSettings(importSettings)
                : new ImportSettings();

            string errorMessage;

            if (!VerifyVersionAndDetectContents(recordText, actualImportSettings, out errorMessage))
            {
                return(ParseResults.Failure(errorMessage));
            }

            var errors = new List <ParseMessage>();

            SpringColliderSerialization.ParsedColliderSetup colliderSetup = null;
            if (actualImportSettings.ImportCollision)
            {
                colliderSetup = SpringColliderSerialization.ParsedColliderSetup.ReadColliderSetupFromText(
                    colliderRoot, recordText);
                if (colliderSetup == null)
                {
                    errors.Add(new ParseMessage("ダイナミクスセットアップが失敗しました:元データにエラーがあります"));
                    return(ParseResults.Failure(errors));
                }
                else
                {
                    errors.AddRange(colliderSetup.Errors);
                }
            }

            SpringBoneSerialization.ParsedSpringBoneSetup springBoneSetup = null;
            if (actualImportSettings.ImportSpringBones)
            {
                var validColliderNames = (colliderSetup != null) ? colliderSetup.GetColliderNames() : null;
                springBoneSetup = SpringBoneSerialization.ParsedSpringBoneSetup.ReadSpringBoneSetupFromText(
                    springBoneRoot, colliderRoot, recordText, validColliderNames);
                if (springBoneSetup == null)
                {
                    errors.Add(new ParseMessage("ダイナミクスセットアップが失敗しました:元データにエラーがあります"));
                    return(ParseResults.Failure(errors));
                }
                else
                {
                    errors.AddRange(springBoneSetup.Errors);
                }
            }

            var dynamicsSetup = new DynamicsSetup
            {
                importSettings  = actualImportSettings,
                springBoneRoot  = springBoneRoot,
                colliderRoot    = colliderRoot,
                springBoneSetup = springBoneSetup,
                colliderSetup   = colliderSetup
            };

            return(new ParseResults(dynamicsSetup, errors));
        }
Exemplo n.º 10
0
 public ParseResults(DynamicsSetup setup, IEnumerable <ParseMessage> errors)
 {
     Setup  = setup;
     Errors = errors.ToList();
 }