Example #1
0
        private static void AttachAnimationCurve(Transform targetRoot,
                                                 DynamicBoneDynamicsCsv.FieldType type)
        {
            var inline = _streamReader.ReadLine();

            while (!string.IsNullOrEmpty(inline))
            {
                var split = inline.Split(',');

                //この場合はエラー
                if (CiferTechUtils.FindSameNameTransformInChildren(split[0], targetRoot) == null)
                {
                    inline = _streamReader.ReadLine();
                    continue;
                }

                var target = CiferTechUtils.FindOrCreateT <DynamicBone>(split[0], targetRoot);

                var field = typeof(DynamicBone).GetField(type.ToString());
                if (field != null)
                {
                    field.SetValue(target, new AnimationCurve
                    {
                        keys = MoldKeyFrames(split)
                    });
                }

                inline = _streamReader.ReadLine();
            }
        }
        private static void WriteKeyFrames(DynamicBone db, DynamicBoneDynamicsCsv.FieldType type)
        {
            _streamWriter.Write($"{db.name}");

            var field = typeof(DynamicBone).GetField(type.ToString());

            if (field == null)
            {
                return;
            }

            var animationCurve = field.GetValue(db) as AnimationCurve;

            if (animationCurve != null)
            {
                foreach (var keyframe in animationCurve.keys)
                {
                    _streamWriter.Write(
                        $",{keyframe.time},{keyframe.value},{keyframe.inTangent},{keyframe.inWeight},{keyframe.outTangent},{keyframe.outWeight}");
                }
            }

            _streamWriter.Write(Environment.NewLine);
        }