zoukankan      html  css  js  c++  java
  • Unity3D 给模型偏移纹理

    给模型偏移纹理

    using UnityEngine;
    using System.Collections;
    
    [RequireComponent(typeof(Renderer))]
    public class ModelTextureAnimation : MonoBehaviour {
    
    	//材质索引
    	public int MaterialIndex;
    
    	//材质主纹理名字
    	public string TextureName = "_MainTex";
    
    	//行数
    	public int Column = 1;
    
    	//列数
    	public int Row = 1;
    
    	//每帧间隔
    	public float Inverval = 0.333f;
    
    	//当前帧索引
    	public int Index = 0;
    
    	private Renderer mRenderer;
    	private Material mMaterial;
    
    	// Use this for initialization
    	void Start () {
    		mRenderer = renderer;
    		mMaterial = mRenderer.sharedMaterials[MaterialIndex];
    
    		mMaterial.SetTextureScale(TextureName, new Vector2(1.0f / Column, 1.0f / Row));
    		
    		StartCoroutine(Animate());
    	}
    
    	IEnumerator Animate()
    	{
    		SetTextureOffset();
     		while(true)
    		{
    			yield return new WaitForSeconds(Inverval);
    
    			if (true == mRenderer.active)
    			{
    				Index++;
    				Index %= (Column * Row);
    				SetTextureOffset();
    			}
    		}
    	}
    
    
    	//根据帧数算出Offset
    	void SetTextureOffset()
    	{
    		float x = (1.0f / Column) * (Index % Column);
    		float y = (1.0f / Row) * (Index / Column);
    		mMaterial.SetTextureOffset(TextureName, new Vector2(x,y));
    	}
    
    	// Update is called once per frame
    #if UNITY_EDITOR
    	void Update () {
    		mMaterial.SetTextureScale(TextureName, new Vector2(1.0f / Column, 1.0f / Row));
    	}
    #endif
    }
    

      

  • 相关阅读:
    线性回归
    [C0] 引言(Introduction)
    [C5W2] Sequence Models
    [C5W3] Sequence Models
    [C4W4] Convolutional Neural Networks
    [C4W3] Convolutional Neural Networks
    [C4W2] Convolutional Neural Networks
    折腾ELK+kafka+zk
    helm 安装prometheus operator 并监控ingress
    练习calico的网络policy
  • 原文地址:https://www.cnblogs.com/mrblue/p/4597639.html
Copyright © 2011-2022 走看看