近期热门
在unity3d如何在一张png中截取一个个动作图片中??(已解决)

[U3D] 在unity3d如何在一张png中截取一个个动作图片中??(已解决)

 !heats_icon! [复制链接]
15711 7 0 0 13年前
我想先从做2D开始,但我的素材是一张各个动作合在一起的.png图片,比如行走,我怎么才能在unity 3d中使用?是建一个平面,然后通过程序导入一个个的动作形成动画?可怎么导入图片的一部分呢??还是在外面把行走的图片做成动画比如.gif然后再放到unity 3d 中呢?做成什么样的格式最好呢??还有一种方法就是,把里面的动作一个个做成一张单孤的图片,我会,可这样会花大量的时间而且看起来会非常乱!~!恳请大神指教!~谢谢谢谢,万分谢谢!~!{:soso_e183:}

补充内容 (2012-7-18 16:16):
请问下面的程序怎么用,那位懂程序的能说说么,我看了两天了,也没找出能连接图片的点儿!~怎么载入的图片呀??在UNITY 3D里怎么使用??急,急急@!@
0
点赞
0
打赏
0
添加到收藏夹

0

点击复制链接

使用微信扫码分享
一次扣10个券
全部评论10
您需要登录后才可以回帖 登录

看了教程有点晕。使用:里的有点牛头不对马嘴。可能是新手的原因吧。看不懂
12年前  ·  8楼
回复

使用道具 举报

看不懂,在学习
12年前  ·  7楼
回复

使用道具 举报

{:soso_e179:}
12年前  ·  6楼
回复

使用道具 举报

这个帖子不回对不起自己!
我觉得cgjoy游戏动画论坛是注册对了!
我自己找到了,献给和我遇到相同问题的朋友http://blog.csdn.net/blogke163/article/details/7705671
13年前  ·  5楼
回复

使用道具 举报

这个脚本动画纹理瓷砖动画。你可以给它一个帧率,以确定动画的速度,并设置有多少砖上的X,Y。

将这个脚本的对象,有一个平铺纹理的材料。为了避免失真,物体的比例必须是每瓦下面的表(如1:2)的比例相同。
下面是一个例子,如何奠定了一个纹理,它(感谢BigBrainz提供):
1.png
(利奥诺盖拉)用于测试目的和C#脚本的修改版本多行添加一个简单的图像:
2.png

JavaScript - AnimatedTextureUV.js

var uvAnimationTileX = 24; //Here you can place the number of columns of your sheet.
                           //The above sheet has 24

var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet.
                          //The above sheet has 1
var framesPerSecond = 10.0;

function Update () {

    // Calculate index
    var index : int = Time.time * framesPerSecond;
    // repeat when exhausting all frames
    index = index % (uvAnimationTileX * uvAnimationTileY);
   
    // Size of every tile
    var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
   
    // split into horizontal and vertical index
    var uIndex = index % uvAnimationTileX;
    var vIndex = index / uvAnimationTileX;

    // build offset
    // v coordinate is the bottom of the image in opengl so we need to invert.
    var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
   
    renderer.material.SetTextureOffset ("_MainTex", offset);
    renderer.material.SetTextureScale ("_MainTex", size);
}
CSharp - SpritSheet.cs

This is just a CSharp version of the AnimatedTextureUV.js above.
public class SpriteSheet : MonoBehaviour
{
    public int _uvTieX = 1;
    public int _uvTieY = 1;
    public int _fps = 10;
   
    private Vector2 _size;
    private Renderer _myRenderer;
    private int _lastIndex = -1;
   
    void Start ()
    {
        _size = new Vector2 (1.0f / _uvTieX , 1.0f / _uvTieY);
        _myRenderer = renderer;
        if(_myRenderer == null)
            enabled = false;
    }
    // Update is called once per frame
    void Update()
    {
        // Calculate index
        int index = (int)(Time.timeSinceLevelLoad * _fps) % (_uvTieX * _uvTieY);
        if(index != _lastIndex)
        {
            // split into horizontal and vertical index
            int uIndex = index % _uvTieX;
            int vIndex = index / _uvTieY;
      
            // build offset
            // v coordinate is the bottom of the image in opengl so we need to invert.
            Vector2 offset = new Vector2 (uIndex * _size.x, 1.0f - _size.y - vIndex * _size.y);
            
            _myRenderer.material.SetTextureOffset ("_MainTex", offset);
            _myRenderer.material.SetTextureScale ("_MainTex", _size);
            
            _lastIndex = index;
        }
    }
}
CSharp - SpritSheetNG.cs

The CSharp version of the script was not working with multiple rows so i made some changes.
public class SpriteSheetNG : MonoBehaviour
{   
    private float iX=0;
    private float iY=1;
    public int _uvTieX = 1;
    public int _uvTieY = 1;
    public int _fps = 10;
    private Vector2 _size;
    private Renderer _myRenderer;
    private int _lastIndex = -1;
   
    void Start ()
    {
        _size = new Vector2 (1.0f / _uvTieX ,
                             1.0f / _uvTieY);

        _myRenderer = renderer;

        if(_myRenderer == null) enabled = false;

        _myRenderer.material.SetTextureScale ("_MainTex", _size);
    }
   
   
   
    void Update()
    {
        int index = (int)(Time.timeSinceLevelLoad * _fps) % (_uvTieX * _uvTieY);
        
        if(index != _lastIndex)
        {
            Vector2 offset = new Vector2(iX*_size.x,
                                         1-(_size.y*iY));
            iX++;
            if(iX / _uvTieX == 1)
            {
                if(_uvTieY!=1)    iY++;
                iX=0;
                if(iY / _uvTieY == 1)
                {
                    iY=1;
                }
            }
   
            _myRenderer.material.SetTextureOffset ("_MainTex", offset);

           
            _lastIndex = index;
        }
    }
13年前  ·  4楼
回复

使用道具 举报

13年前  ·  3楼
回复

使用道具 举报

13年前  ·  2楼
回复

使用道具 举报

您当前使用的浏览器IE内核版本过低会导致网站显示错误

请使用高速内核浏览器或其他浏览器