NGUI panel使用soft clip时,屏幕缩放问题

我发现把那个panel的LocalScale的x,y,z的改成一样的就行了。我把他们的LocalScale.x和z都等于了y。再改一下Clipping的大小。效果不是最佳的,先将就着吧,呵呵~~~
对了,代码里面在Start里面运行SetPanel()时,最好用StartCoroutine或者Invoke,或者先yield一秒,我怕UI还没缩放就运行了就不好了,呵呵~~~我这里没写,你们自己写哈,呵呵~~~

  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class SubPanelPosition : MonoBehaviour {  
  5.     public ScreenDirection screenDirection;  
  6.     //horizontal表示水平滑动;vertical表示垂直滑动。  
  7.     public enum ScreenDirection   
  8.     {  
  9.         horizontal,  
  10.         vertical  
  11.     }  
  12.     public float size;  
  13.     private Transform parent;  
  14.     private Transform child;  
  15.     private float ScaleSize;  
  16.     private float rateX;  
  17.     private float rateY;  
  18.     UIPanel PanelScript;  
  19.     void Start()  
  20.     {  
  21.         Invoke("SetPanel",0.5f);  
  22.     }  
  23.     void SetPanel()  
  24.     {  
  25.         parent = transform.parent;  
  26.         child = transform.GetChild(0);  
  27.         PanelScript = transform.GetComponent<UIPanel>();  
  28.           
  29.         transform.parent = null;  
  30.         child.parent = null;  
  31.       
  32.           
  33.         if(screenDirection == ScreenDirection.vertical)  
  34.         {  
  35.             rateX =  Screen.width/size;  
  36.             rateY = 1;  
  37.             ScaleSize = transform.localScale.y;  
  38.         }  
  39.         else if(screenDirection == ScreenDirection.horizontal)  
  40.         {  
  41.             rateX = 1;  
  42.             rateY = Screen.height/size;  
  43.             ScaleSize = transform.localScale.x;  
  44.         }  
  45.           
  46.         transform.localScale = new Vector4(ScaleSize,ScaleSize,ScaleSize,ScaleSize);      
  47.         transform.parent = parent;  
  48.         child.parent = transform;  
  49.         PanelScript.clipRange = new Vector4(PanelScript.clipRange.x,PanelScript.clipRange.y,PanelScript.clipRange.z * rateX,PanelScript.clipRange.w * rateY);   
  50.     }  
  51.       
  52. }  
using UnityEngine;
using System.Collections;

public class SubPanelPosition : MonoBehaviour {
	public ScreenDirection screenDirection;
	//horizontal表示水平滑动;vertical表示垂直滑动。
	public enum ScreenDirection 
	{
		horizontal,
		vertical
	}
	public float size;
	private Transform parent;
	private Transform child;
	private float ScaleSize;
	private float rateX;
	private float rateY;
	UIPanel PanelScript;
	void Start()
	{
		Invoke("SetPanel",0.5f);
	}
	void SetPanel()
	{
		parent = transform.parent;
		child = transform.GetChild(0);
		PanelScript = transform.GetComponent<UIPanel>();
		
		transform.parent = null;
		child.parent = null;
	
		
		if(screenDirection == ScreenDirection.vertical)
		{
		    rateX =  Screen.width/size;
			rateY = 1;
			ScaleSize = transform.localScale.y;
		}
		else if(screenDirection == ScreenDirection.horizontal)
		{
			rateX = 1;
            rateY = Screen.height/size;
			ScaleSize = transform.localScale.x;
		}
		
		transform.localScale = new Vector4(ScaleSize,ScaleSize,ScaleSize,ScaleSize);	
		transform.parent = parent;
		child.parent = transform;
		PanelScript.clipRange = new Vector4(PanelScript.clipRange.x,PanelScript.clipRange.y,PanelScript.clipRange.z * rateX,PanelScript.clipRange.w * rateY); 
	}
	
}

 

注:其中Screen Direction表示水平还是垂直滑动,如果是水平的话Size就是你当前发布时的Screen.width,如果是垂直的话,size就是Screen.height。

 

看看第二种方法,和前面差不多,改了一点~~~

  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class SubPanelPosition : MonoBehaviour {  
  5.     public ScreenDirection screenDirection;  
  6.     //horizontal表示水平滑动;vertical表示垂直滑动。  
  7.     public enum ScreenDirection   
  8.     {  
  9.         horizontal,  
  10.         vertical  
  11.     }  
  12.     private Transform parent;  
  13.     private Transform child;  
  14.     private float ScaleSize;  
  15.     private float rateX;  
  16.     private float rateY;  
  17.     UIPanel PanelScript;  
  18.     void Start()  
  19.     {  
  20.         parent = transform.parent;  
  21.         child = transform.GetChild(0);  
  22.         PanelScript = transform.GetComponent<UIPanel>();  
  23.     }  
  24.     void SetPanel()  
  25.     {         
  26.         transform.parent = null;  
  27.         child.parent = null;  
  28.       
  29.           
  30.         if(screenDirection == ScreenDirection.vertical)  
  31.         {  
  32.             ScaleSize = transform.localScale.y;  
  33.             rateX = ScaleSize/transform.localScale.x;  
  34.             rateY = 1;  
  35.         }  
  36.         else if(screenDirection == ScreenDirection.horizontal)  
  37.         {  
  38.             ScaleSize = transform.localScale.x;  
  39.             rateX = 1;  
  40.             rateY = ScaleSize/transform.localScale.y;  
  41.         }  
  42.           
  43.         transform.localScale = new Vector4(ScaleSize,ScaleSize,ScaleSize,ScaleSize);      
  44.         transform.parent = parent;  
  45.         child.parent = transform;  
  46.         PanelScript.clipRange = new Vector4(PanelScript.clipRange.x,PanelScript.clipRange.y,PanelScript.clipRange.z * rateX,PanelScript.clipRange.w * rateY);   
  47.     }  
  48.       
  49. }  
using UnityEngine;
using System.Collections;

public class SubPanelPosition : MonoBehaviour {
	public ScreenDirection screenDirection;
	//horizontal表示水平滑动;vertical表示垂直滑动。
	public enum ScreenDirection 
	{
		horizontal,
		vertical
	}
	private Transform parent;
	private Transform child;
	private float ScaleSize;
	private float rateX;
	private float rateY;
	UIPanel PanelScript;
	void Start()
	{
		parent = transform.parent;
		child = transform.GetChild(0);
		PanelScript = transform.GetComponent<UIPanel>();
	}
	void SetPanel()
	{		
		transform.parent = null;
		child.parent = null;
	
		
		if(screenDirection == ScreenDirection.vertical)
		{
			ScaleSize = transform.localScale.y;
			rateX = ScaleSize/transform.localScale.x;
			rateY = 1;
		}
		else if(screenDirection == ScreenDirection.horizontal)
		{
			ScaleSize = transform.localScale.x;
			rateX = 1;
			rateY = ScaleSize/transform.localScale.y;
		}
		
		transform.localScale = new Vector4(ScaleSize,ScaleSize,ScaleSize,ScaleSize);	
		transform.parent = parent;
		child.parent = transform;
		PanelScript.clipRange = new Vector4(PanelScript.clipRange.x,PanelScript.clipRange.y,PanelScript.clipRange.z * rateX,PanelScript.clipRange.w * rateY); 
	}
	
}


注:手机上如果不行的话就只能用摄像机的方法了~~~~
 转载:http://blog.csdn.net/dlnuchunge/article/details/8518276

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值