Пример #1
0
        //!
        //! updates the rendered line (animation path)
        //!
        private void updateLine()
        {
            print("updateLine");
            if (animData.getAnimationClips(animationTarget) != null)
            {
                foreach (AnimationClip clip in animData.getAnimationClips(animationTarget))
                {
                    //! AnimationCurves for X, Y and Z Translation of this clip
                    AnimationCurve transXcurve = animData.getAnimationCurve(clip, "m_LocalPosition.x");
                    AnimationCurve transYcurve = animData.getAnimationCurve(clip, "m_LocalPosition.y");
                    AnimationCurve transZcurve = animData.getAnimationCurve(clip, "m_LocalPosition.z");

                    int pointCount = 0;
                    List <Vector3[]> pointArraysList = new List <Vector3[]>(0);

                    for (int i = 0; i <= transXcurve.keys.Length - 1; i++)
                    {
                        if (i != transXcurve.keys.Length - 1)
                        {
                            Vector3[] pointArray = getHermiteInterpolationLine(transXcurve.keys[i], transYcurve.keys[i], transZcurve.keys[i], transXcurve.keys[i + 1], transYcurve.keys[i + 1], transZcurve.keys[i + 1]);
                            pointArraysList.Add(pointArray);
                            pointCount += pointArray.Length;
                        }
                        if (i < keyframeSpheres.Count)
                        {
                            keyframeSpheres[i].transform.position = new Vector3(transXcurve.keys[i].value, transYcurve.keys[i].value, transZcurve.keys[i].value);
                        }
                        else
                        {
                            GameObject sphere = GameObject.Instantiate <GameObject>(keySpherePrefab);
                            sphere.transform.position   = new Vector3(transXcurve.keys[i].value, transYcurve.keys[i].value, transZcurve.keys[i].value);
                            sphere.transform.localScale = new Vector3(keyHandleScale, keyHandleScale, keyHandleScale);
                            sphere.transform.parent     = frameSphereContainer.transform;
                            sphere.layer = 13;
                            sphere.name  = i.ToString();
                            keyframeSpheres.Add(sphere);
                        }
                    }
                    if (transXcurve.keys.Length < keyframeSpheres.Count)
                    {
                        for (int i = transXcurve.keys.Length; i < keyframeSpheres.Count; i++)
                        {
                            Destroy(keyframeSpheres[i], 0);
                        }
                        keyframeSpheres.RemoveRange(transXcurve.keys.Length, keyframeSpheres.Count - transXcurve.keys.Length);
                    }

                    lineRenderer.SetVertexCount(pointCount);
                    int     currentPosition = 0;
                    Vector3 lastPoint       = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

                    for (int i = 0; i < pointArraysList.Count; i++)
                    {
                        for (int j = 0; j < pointArraysList[i].Length; j++)
                        {
                            if (lastPoint != pointArraysList[i][j])
                            {
                                lineRenderer.SetPosition(currentPosition, pointArraysList[i][j]);
                                lastPoint = pointArraysList[i][j];
                                currentPosition++;
                            }
                            else
                            {
                                pointCount--;
                                lineRenderer.SetVertexCount(pointCount);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        //!
        //! update the animation curves
        //! normally called after the animation curve has changed
        //!
        public void updateAnimationCurves()
        {
            if (animData.getAnimationClips(target.gameObject) != null)
            {
                transCurves[0] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalPosition.x");
                transCurves[1] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalPosition.y");
                transCurves[2] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalPosition.z");

                rotationCurves[0] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.x");
                rotationCurves[1] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.y");
                rotationCurves[2] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.z");
                rotationCurves[3] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.w");

                scaleCurves[0] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalScale.x");
                scaleCurves[1] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalScale.y");
                scaleCurves[2] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalScale.z");

                // TODO: fix one length for all curves
                animationDuration = animData.getAnimationClips(target.gameObject)[0].length;
                setAnimationState(animationController.currentAnimationTime);
            }
        }