[u3d]Unity3D:获取GameObject的size[zt]
        
     
    
    
    
 	 
    
		clq
		
        浏览(529) - 
        2020-02-06 22:13:25 发表
        
编辑
         
        
        
        
        关键字: u3d
        
 
        
        
        
            
                    
            [u3d]Unity3D:获取GameObject的size[zt]
https://www.cnblogs.com/makebetter/p/6734763.html
//--------------------------------------------------
1.Renderer:渲染尺寸,受缩放影响,受旋转影响。3D图像投影在2D平面上的尺寸
 
2.MeshFilter:原始尺寸,不受缩放影响
计算真实的size:需要乘以localScale
如:gameObject.GetComponent().mesh.bounds.size.x*gameObject.transform.localScale.x
 
3.Collider:碰撞体尺寸,受缩放影响,受旋转影响。3D图像投影在2D平面上的尺寸
 
复制代码
    void onClick_scale_percent(){
//        stlObjects [0].clingToBottom ();
        GameObject cube = GameObject.CreatePrimitive (PrimitiveType.Cube);
        Debug.LogError ("cube Renderer size:"+cube.GetComponent().bounds.size);//default:1,1,1
        Debug.LogError ("cube MeshFilter size:"+cube.GetComponent().mesh.bounds.size);
        Debug.LogError ("cube collider size:"+cube.GetComponent().bounds.size);
        cube.transform.parent = go_printCuber.transform;
        cube.transform.localPosition = new Vector3 (0, 0, 0);
        cube.transform.localScale = new Vector3 (0.5f, 0.5f, 0.5f);
        cube.transform.Rotate (0, 45, 0);
        Debug.LogError ("-------------------");
        Debug.LogError ("cube Renderer size:"+cube.GetComponent().bounds.size);
        Debug.LogError ("cube MeshFilter size:"+cube.GetComponent().mesh.bounds.size);
        Debug.LogError ("cube collider size:"+cube.GetComponent().bounds.size);
        Debug.LogError ("cube localScale:"+cube.transform.localScale);//default:1,1,1
    }
复制代码
 
 
    
分类: Unity3D
        
        
        
		
		        
                
                        
   
     
    
 
	
	
     
	
    
    
     
    
    
    
    
 
    NEWBT官方QQ群1: 276678893
    可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
    但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
    验证问题说明申请入群原因即可.