我们UI自适应采用的是Canvas Scaler 设置 Expand模式。 那么UI可以很好的自适应屏幕,可是粒子特效就会出问题所以写下了这个脚本来自适应UI的粒子特效
usingUnityEngine;
usingSystem.Collections;
usingSystem.Collections.Generic;
publicclassUIParticleScale : MonoBehaviour {
privateList scaleDatas =null;
voidAwake()
{
scaleDatas =newList();
foreach( ParticleSystem pintransform.GetComponentsInChildren(true)){
scaleDatas.Add(newScaleData(){transform = p.transform,beginScale = p.transform.localScale});
}
}
voidStart ()
{
floatdesignWidth = 1136;//开发时分辨率宽
floatdesignHeight = 640;//开发时分辨率高
floatdesignScale = designWidth/designHeight;
floatscaleRate = (float)Screen.width/(float)Screen.height;
foreach(ScaleData scaleinscaleDatas)
{
if(scale.transform !=null){
if(scaleRate
{
floatscaleFactor = scaleRate / designScale;
scale.transform.localScale = scale.beginScale * scaleFactor;
}else{
scale.transform.localScale = scale.beginScale;
}
}
}
}
#if UNITY_EDITOR
voidUpdate () {
Start();//Editor下修改屏幕的大小实时预览缩放效果
}
#endif
classScaleData
{
publicTransform transform;
publicVector3 beginScale = Vector3.one;
}
}
转载自 雨松MOMO 传送门 http://www.manew.com/thread-98432-1-1.html