| 3d物体的仅Quad可用。 如果用其他3D物体,会报错 Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array. ...
/// <summary>
    /// Sets the frame.
    /// </summary>
    /// <param name="frame">Frame.</param>
    public void SetFrame(int frame)
    {
        if (this._framesCount == 1)
        {
            return;
        }
        float xUnitSize = 1.0f / this._tilesX;
        float yUnitSize = 1.0f / this._tilesY;
 
        int xIndex = frame % this._tilesX;
        int yIndex = frame / this._tilesX;
        yIndex = this._tilesY - yIndex - 1;
        Vector2[] uv = new Vector2[] {
			//正常朝向右
			/*new Vector2(xIndex * xUnitSize, yIndex * yUnitSize),//左下
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(xUnitSize, 0),//右下
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(0, yUnitSize),//左上
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(xUnitSize, yUnitSize),//右上*/
			
			//正常朝向左,与原图 水平翻转
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(xUnitSize, 0),//右下
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize),//左下
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(xUnitSize, yUnitSize),//右上
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(0, yUnitSize),//左上
		};
        this.MeshFilter.mesh.uv = uv;
        this._currentFrame = frame;
    }
...
 完整代码在参考资料1。 参考资料: 1.[Unity]代码控制在3D物体上播放帧动画 2.Unity Shader UV动画(序列帧动画 3.Untiy网格编程篇(一)包围盒效果 4.Unity网格编程篇(二) 非常详细的Mesh编程入门文章 5.Unity网格编程篇(三) 温度图、热力图 6.Unity网格编程篇(四) 三维温度图、热力图 7. |