public static void CsvSave(DynamicBoneDynamicsCsv.Data data)
        {
            _streamWriter = new StreamWriter(data.FilePath, false, Encoding.UTF8);

            if (data.IsColliderSaveLoad)
            {
                WriteFieldType(DynamicBoneDynamicsCsv.FieldType.ColliderBase);
                var collider = data.TargetRoot.GetComponentsInChildren <DynamicBoneColliderBase>();
                foreach (var cb in collider)
                {
                    WriteColliderBase(cb);
                }
            }

            if (data.IsDynamicBoneSaveLoad)
            {
                WriteFieldType(DynamicBoneDynamicsCsv.FieldType.DynamicBone);
                var dynamicBones = data.TargetRoot.GetComponentsInChildren <DynamicBone>();
                foreach (var db in dynamicBones)
                {
                    WriteDynamicBone(db);
                }

                for (var type = DynamicBoneDynamicsCsv.FieldType.m_DampingDistrib;
                     type <= DynamicBoneDynamicsCsv.FieldType.m_RadiusDistrib;
                     type++)
                {
                    WriteFieldType(type);
                    foreach (var db in dynamicBones)
                    {
                        WriteKeyFrames(db, type);
                    }
                }

                WriteFieldType(DynamicBoneDynamicsCsv.FieldType.m_Colliders);
                foreach (var db in dynamicBones)
                {
                    WriteDynamicBoneFieldT <DynamicBoneColliderBase>(db);
                }

                WriteFieldType(DynamicBoneDynamicsCsv.FieldType.m_Exclusions);
                foreach (var db in dynamicBones)
                {
                    WriteDynamicBoneFieldT <Transform>(db);
                }
            }

            _streamWriter.Close();
            _streamWriter = null;
            Debug.Log($"{typeof(DynamicBoneDynamicsCsvSaver).ToString().Split('.').Last()}: セーブしました!");
        }
Beispiel #2
0
        public static void CsvLoad(DynamicBoneDynamicsCsv.Data data)
        {
            _streamReader = new StreamReader(data.FilePath, Encoding.UTF8);
            while (!_streamReader.EndOfStream)
            {
                var line        = _streamReader.ReadLine();
                var isFieldLine = line != null && FieldRegex.IsMatch(line);

                if (!isFieldLine)
                {
                    continue;
                }

                DynamicBoneDynamicsCsv.FieldType lineFieldType;
                Enum.TryParse(line.Trim('[', ']'), out lineFieldType);

                switch (lineFieldType)
                {
                case DynamicBoneDynamicsCsv.FieldType.DynamicBone:
                    if (data.IsDynamicBoneSaveLoad)
                    {
                        AttachDynamicBone(data.TargetRoot);
                    }
                    break;

                case DynamicBoneDynamicsCsv.FieldType.m_DampingDistrib:
                case DynamicBoneDynamicsCsv.FieldType.m_ElasticityDistrib:
                case DynamicBoneDynamicsCsv.FieldType.m_StiffnessDistrib:
                case DynamicBoneDynamicsCsv.FieldType.m_InertDistrib:
                case DynamicBoneDynamicsCsv.FieldType.m_FrictionDistrib:
                case DynamicBoneDynamicsCsv.FieldType.m_RadiusDistrib:
                    if (data.IsDynamicBoneSaveLoad)
                    {
                        AttachAnimationCurve(data.TargetRoot, lineFieldType);
                    }
                    break;

                case DynamicBoneDynamicsCsv.FieldType.m_Colliders:
                    if (data.IsDynamicBoneSaveLoad)
                    {
                        AttachDynamicBoneFieldT <DynamicBoneColliderBase>(data.TargetRoot);
                    }
                    break;

                case DynamicBoneDynamicsCsv.FieldType.m_Exclusions:
                    if (data.IsDynamicBoneSaveLoad)
                    {
                        AttachDynamicBoneFieldT <Transform>(data.TargetRoot);
                    }
                    break;

                case DynamicBoneDynamicsCsv.FieldType.ColliderBase:
                    if (data.IsColliderSaveLoad)
                    {
                        CreateDynamicBoneColliders(data.TargetRoot);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _streamReader.Close();
            _streamReader = null;
            Debug.Log($"{typeof(DynamicBoneDynamicsCsvSaver).ToString().Split('.').Last()}: ロードしました!");
        }
Beispiel #3
0
        private void OnGUI()
        {
            _targetRoot =
                EditorGUILayout.ObjectField("DynamicBoneのルート", _targetRoot, typeof(Transform), true) as Transform;

            if (GUILayout.Button("選択からルートを取得"))
            {
                _targetRoot = GetRootBone();
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("設定", new GUIStyle
            {
                alignment = TextAnchor.MiddleCenter
            });

            _isDynamicBoneSaveLoad = EditorGUILayout.ToggleLeft("DynamicBone", _isDynamicBoneSaveLoad);
            _isColliderSaveLoad    = EditorGUILayout.ToggleLeft("コライダー", _isColliderSaveLoad);

            GUILayout.FlexibleSpace();

            //エラー、警告判定
            if (_targetRoot == null)
            {
                EditorGUILayout.HelpBox("ルートオブジェクトを選択してください。", MessageType.Error);
                return;
            }

            EditorGUILayout.BeginHorizontal();
            {
                //セーブ
                if (GUILayout.Button("セーブ"))
                {
                    var filePath = EditorUtility.SaveFilePanel(
                        "DynamicBoneセットアップを保存", "", $"{_targetRoot.name}_DynamicBone_Dynamics.csv", "csv");
                    if (filePath.Length <= 0)
                    {
                        return;
                    }

                    var copyData = new DynamicBoneDynamicsCsv.Data
                    {
                        TargetRoot            = _targetRoot,
                        IsDynamicBoneSaveLoad = _isDynamicBoneSaveLoad,
                        IsColliderSaveLoad    = _isColliderSaveLoad,
                        FilePath = filePath
                    };
                    DynamicBoneDynamicsCsvSaver.CsvSave(copyData);
                }

                //ロード
                if (GUILayout.Button("ロード"))
                {
                    var filePath = EditorUtility.OpenFilePanelWithFilters(
                        "DynamicBoneセットアップを読み込む", "", new[] { "CSVファイル", "csv", "テキストファイル", "txt" });
                    if (filePath.Length <= 0)
                    {
                        return;
                    }

                    var copyData = new DynamicBoneDynamicsCsv.Data()
                    {
                        TargetRoot            = _targetRoot,
                        IsDynamicBoneSaveLoad = _isDynamicBoneSaveLoad,
                        IsColliderSaveLoad    = _isColliderSaveLoad,
                        FilePath = filePath,
                    };
                    DynamicBoneDynamicsCsvLoader.CsvLoad(copyData);
                }
            }
            EditorGUILayout.EndHorizontal();
        }