Exemple #1
0
    void Update()
    {
        if (source)
        {
            int fc = 0;

            switch (source.datasource)
            {
            case MegaCacheData.Mesh: fc = source.meshes.Count - 1; break;

            case MegaCacheData.File: fc = source.framecount - 1; break;

            case MegaCacheData.Image:
                if (source.cacheimage && source.cacheimage.frames != null)
                {
                    fc = source.cacheimage.frames.Count - 1;
                }
                break;
            }

            if (fc > 0)
            {
                if (animate)
                {
                    looptime = fc / fps;
                    if (Application.isPlaying)
                    {
                        time += Time.deltaTime * speed;
                    }

                    float at = time;

                    switch (loopmode)
                    {
                    case MegaCacheRepeatMode.Loop:
                        at = Mathf.Repeat(time, Mathf.Abs(looptime));
                        if (looptime < 0.0f)
                        {
                            at = looptime - at;
                        }
                        break;

                    case MegaCacheRepeatMode.PingPong: at = Mathf.PingPong(time, looptime); break;

                    case MegaCacheRepeatMode.Clamp: at = Mathf.Clamp(time, 0.0f, looptime); break;
                    }

                    frame = (int)((at / looptime) * fc);
                }

                frame = Mathf.Clamp(frame, 0, fc);

                if (frame != currentframe)
                {
                    currentframe = frame;
                    if (source.datasource == MegaCacheData.Image && source.cacheimage)
                    {
                        if (imagemesh == null)
                        {
                            imagemesh = new Mesh();
                        }

                        if (mf.sharedMesh != imagemesh)
                        {
                            mf.sharedMesh = imagemesh;
                        }

                        source.cacheimage.GetMeshRef(imagemesh, frame, source);
                    }

                    if (source.datasource == MegaCacheData.File)
                    {
                        if (imagemesh == null)
                        {
                            imagemesh = new Mesh();
                        }

                        if (mf.sharedMesh != imagemesh)
                        {
                            mf.sharedMesh = imagemesh;
                        }

                        source.GetFrameRef(frame, imagemesh);
                    }

                    if (source.datasource == MegaCacheData.Mesh)
                    {
                        if (mf && source.meshes.Count > 0)
                        {
                            if (mf.sharedMesh != source.meshes[frame])
                            {
                                mf.sharedMesh = source.meshes[frame];
                            }
                        }
                    }

                    if (updatecollider)
                    {
                        if (meshCol == null)
                        {
                            meshCol = GetComponent <MeshCollider>();
                        }

                        if (meshCol != null)
                        {
                            meshCol.sharedMesh = null;
                            meshCol.sharedMesh = mf.sharedMesh;
                        }
                    }
                }
            }
        }
    }