示例#1
0
        private void AddPPtrKeyframe(PPtrCurve curve, AnimationClipBindingConstant bindings, float time, int index)
        {
            if (!m_pptrs.TryGetValue(curve, out List <PPtrKeyframe> pptrCurve))
            {
                pptrCurve = new List <PPtrKeyframe>();
                m_pptrs.Add(curve, pptrCurve);
                AddPPtrKeyframe(curve, bindings, 0.0f, index - 1);
            }

            PPtr <Object> value   = bindings.PPtrCurveMapping[index];
            PPtrKeyframe  pptrKey = new PPtrKeyframe(time, value);

            pptrCurve.Add(pptrKey);
        }
示例#2
0
        public static Animation Parse(string path)
        {
            string data = FileHelper.ReadFileIntoString(path);

            List <PPtrCurve> pPtrCurves = new List <PPtrCurve>();
            int pptrIndex;
            int lastIndex = 0;

            while ((pptrIndex = data.IndexOf("m_PPtrCurves", lastIndex)) != -1)
            {
                lastIndex = pptrIndex + 1;
                int pptrEndIndex = data.IndexOf("  m_", pptrIndex);

                int curveIndex;
                int lastCurveIndex = pptrIndex;
                //find all curves
                while ((curveIndex = data.IndexOf("  - curve:", lastCurveIndex, pptrEndIndex - lastCurveIndex)) != -1)
                {
                    lastCurveIndex = curveIndex + 1;
                    int curveEndIndex = data.IndexOf("    script: ", curveIndex);

                    PPtrCurve           curve     = new PPtrCurve();
                    List <PPtrKeyframe> keyframes = new List <PPtrKeyframe>();

                    int keyFrameIndex;
                    int lastKeyFrameIndex = curveIndex;
                    while ((keyFrameIndex = data.IndexOf("    - time:", lastKeyFrameIndex, curveEndIndex - lastKeyFrameIndex)) != -1)
                    {
                        lastKeyFrameIndex = keyFrameIndex + 1;
                        int keyFrameEndIndex = data.IndexOf("}", keyFrameIndex);

                        PPtrKeyframe keyframe = new PPtrKeyframe();
                        keyframe.time = float.Parse(data.Substring(keyFrameIndex, data.IndexOf("\n", keyFrameIndex, keyFrameEndIndex)));
                        keyframes.Add(keyframe);
                    }

                    curve.curveType = data.IndexOf("    attribute: m_Materials", lastKeyFrameIndex, curveEndIndex - lastKeyFrameIndex) != -1 ? PPtrType.Material : PPtrType.None;
                    curve.keyframes = keyframes.ToArray();
                    pPtrCurves.Add(curve);
                }
            }
            Animation animation = new Animation();

            animation.pPtrCurves = pPtrCurves.ToArray();
            Debug.Log(Parser.Serialize(animation));
            return(animation);
        }
示例#3
0
        private void AddCustomCurve(AnimationClipBindingConstant bindings, GenericBinding binding, string path, float time, float value)
        {
            switch (binding.CustomType)
            {
            case BindingCustomType.AnimatorMuscle:
                AddAnimatorMuscleCurve(binding, time, value);
                break;

            default:
                string attribute = m_customCurveResolver.ToAttributeName(Layout, binding.CustomType, binding.Attribute, path);
                if (binding.IsPPtrCurve)
                {
                    PPtrCurve curve = new PPtrCurve(path, attribute, binding.ClassID, binding.Script.CastTo <MonoScript>());
                    AddPPtrKeyframe(curve, bindings, time, (int)value);
                }
                else
                {
                    FloatCurve curve = new FloatCurve(path, attribute, binding.ClassID, binding.Script.CastTo <MonoScript>());
                    AddFloatKeyframe(curve, time, value);
                }
                break;
            }
        }