Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        X2DTools.DrawPosMark(gameObject, transform.position, gameObject.layer);

#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            EditorUpdateClipArray();
            for (int i = 0; i < clipArray.Length; i++)
            {
                clipArray[i].transform.localPosition = Vector3.zero;                //保持为(0, 0, 0),这样改变朝向时不会出错,见X2DAniamtion.isFacingRight
            }
            return;
        }
#endif

        if (!isPlaying)
        {
            return;
        }

        timer += Time.deltaTime;
        for (int i = 0; i < clipArray.Length; i++)
        {
            X2DEffectClip clip = clipArray[i];
            if (!clip.isPlaying)
            {
                if (timer > clip.startTime && timer < clip.endTime)
                {
                    clip.gameObject.SetActive(true);
                    clip.Play();
                }
            }
            else if (clip.endTime > 0 && timer >= clip.endTime)
            {
                clip.Stop();
                stoppedClipCount++;

                //循环播
                if (loop && stoppedClipCount == clipArray.Length)
                {
                    isPlaying = false;
                    Play();
                }
            }
        }

        if (stoppedClipCount == clipArray.Length && timer >= duration)
        {
            isPlaying = false;
            return;
        }
    }
    void Update()
    {
        X2DTools.DrawPosMark(gameObject, transform.position, gameObject.layer);

                #if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            EditorPlayFirstFrame();
            return;
        }
                #endif

        if (!isPlaying)
        {
            return;
        }
        if (curClip == null)
        {
            isPlaying = false;
            return;
        }

        float deltaTime = Time.deltaTime;
        if (isForward)
        {
            timer += deltaTime;
        }
        else
        {
            timer -= deltaTime;
        }

        //根据当前所处的时间获得应该播放的帧
        //如果是播一帧然后等这一帧播放后继续下帧,累计误差问题不好处理
        int nextFrame = curClip.GetCurFrame(timer, curFrame, isForward, accelerate);
        if (nextFrame != -1)
        {
            if (nextFrame != curFrame)
            {
                PlayFrame(curClip, nextFrame);
                curFrame = nextFrame;
            }
        }
        else
        {
            //播完了一溜
            if (playMode == EmX2DAnimationPlayMode.Once)
            {
                isPlaying = false;
            }
            else
            {
                if (playMode == EmX2DAnimationPlayMode.Pingpong)
                {
                    isForward = !isForward;
                }

                int firstFrame = 0;
                timer = 0f;
                if (!isForward)
                {
                    firstFrame = curClip.frameList.Count - 1;
                    timer      = curClip.duration;
                }

                if (playMode == EmX2DAnimationPlayMode.Loop)
                {
                    curFrame = firstFrame;
                }
                else if (playMode == EmX2DAnimationPlayMode.Pingpong)
                {
                    float t = curClip.frameList[curFrame].duration;
                    if (isForward)
                    {
                        timer += t;                        //不再在最后一帧做停留
                        curFrame++;
                    }
                    else
                    {
                        timer -= t;                        //不再在最后一帧做停留
                        curFrame--;
                    }
                }
                PlayFrame(curClip, curFrame);
            }

            //预览全部
            if (previewClipPlayEndCallbabck != null)
            {
                previewClipPlayEndCallbabck();
            }
        }

        if (curClip.hasPosCurve)
        {
            if (actorContainer != null)
            {
                actorContainer.objectbase.realLocalPos = GetCurAnimationPos();
            }
            if (normalContainer != null)
            {
                normalContainer.localPosition = GetCurAnimationPos();
            }
        }
    }
Exemple #3
0
 protected void Update()
 {
     //Debug.Log("Update");
     Create3DMirror();
     X2DTools.DrawPosMark(gameObject, transform.position, gameObject.layer);
 }