NGUI_Panel(clipped panels must have a uniform scale)
来源:互联网 发布:淘宝网退货地址怎么改 编辑:程序博客网 时间:2024/05/22 13:21
使用NGUI,通过更改父物体的scale来适配屏幕时,如果子panel使用softclip,子panel会出现错误:clipped panels must have a uniform scale, 出错原因是子panel的scale的x,y,z不一致,因此解决方法就是把panel物体的transform的scale的xyz换算成(1,1,1),通过改变所有子物体的,但改变后为了裁剪会出问题,因此通过修改panel 的clipping下面的offset, center, size值。
先讲一下NGUI的适配:UIRoot的ScallingStyle设置为FixedSize,
ManualHeight 设置为480, 我按800*480制作UI资源
设置完成后,NGUI会按照 screenHeight/480.0f 对UI进行高度适配,由于大部分手机厂商制作的机型宽高比不一致, 因此待NGUI完成适配后,我们需要针对宽做二次适配,屏幕适配的代码如下
public class MyWidgetScale : MonoBehaviour { static bool g_bInit = true; public static float g_fAdaptedX; void Awake () { if (g_bInit) { float ration1 = 800f / 480f; float ration2 = Screen.width * 1.0f / Screen.height; g_fAdaptedX = ration2 / ration1; g_bInit = false; } transform.localScale = new Vector3(g_fAdaptedX, 1, 1); }}
由于上边的适配导致子panel的scale不一致了,因此调整子panel的scale和裁剪区域
基本讲清楚了,下边是代码部分:
子panel没有scrollview
public class AdjustSubPanel : MonoBehaviour { void Start () { float baseScale = 1; if(Screen.width > Screen.height) { baseScale = transform.lossyScale.x; } else { baseScale = transform.lossyScale.y; } transform.localScale = new Vector3(baseScale / transform.lossyScale.x, baseScale / transform.lossyScale.y, baseScale / transform.lossyScale.z); UIPanel panel = transform.GetComponent<UIPanel>(); panel.baseClipRegion = new Vector4(panel.baseClipRegion.x / transform.localScale.x, panel.baseClipRegion.y / transform.localScale.y , panel.baseClipRegion.z / transform.localScale.x, panel.baseClipRegion.w / transform.localScale.y); panel.clipOffset = new Vector2(panel.clipOffset.x / transform.localScale.x, panel.clipOffset.y / transform.localScale.y); for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).localScale = new Vector3(1 / transform.localScale.x, 1 / transform.localScale.y, 1 / transform.localScale.z); } }}
子panel上挂在scrollview时
关于localScale和lossyScale的注解:
当GameObject对象A为GameObject对象B的父物体时,父物体A的各个分量放缩值x、y、z的大小应该保持1:1:1的比例,否则当子物体B的Rotation值比例不为1:1:1时,B物体将会发生变形。
设GameObject对象A为B的父物体,当A物体各个分量的放缩值保持1:1:1的比例时,子物体B的lossyScale返回值即为B物体相对世界坐标系的放缩值,关系为B.localScale = B.lossyScale/A.localScale。
public class AdjustSubPanelWithScrollView : MonoBehaviour { void Start() { UIScrollView scrollView = transform.GetComponent<UIScrollView>(); float baseScale = 1; if (scrollView.movement == UIScrollView.Movement.Vertical) { baseScale = transform.lossyScale.y; } else if (scrollView.movement == UIScrollView.Movement.Horizontal) { baseScale = transform.lossyScale.x; } else { Debug.LogError("Unsupported UIScrollView Movement"); return; } Debug.Log(baseScale); transform.localScale = new Vector3(baseScale / transform.lossyScale.x, baseScale / transform.lossyScale.y, baseScale / transform.lossyScale.z); UIPanel panel = transform.GetComponent<UIPanel>(); panel.baseClipRegion = new Vector4(panel.baseClipRegion.x / transform.localScale.x, panel.baseClipRegion.y / transform.localScale.y , panel.baseClipRegion.z / transform.localScale.x, panel.baseClipRegion.w / transform.localScale.y); panel.clipOffset = new Vector2(panel.clipOffset.x / transform.localScale.x, panel.clipOffset.y / transform.localScale.y); for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).localScale = new Vector3(1 / transform.localScale.x, 1 / transform.localScale.y, 1 / transform.localScale.z); } }}
- NGUI_Panel(clipped panels must have a uniform scale)
- Unity使用UIStretch做屏幕自适应遇到clipped panels must have a uniform scale
- do not have a clipped shader version for SoftClip
- 20060509-A Lab-based uniform color scale
- you must have a uni
- unity3d 解决doesn't have a clipped shader version for SoftClip 和 (AlphaClip)
- Unity3d NGUI doesn't have a clipped shader version for SoftClip 和 AlphaClip错误的解决方法
- ViewStub must have a valid layoutResource
- Transformer入门教程(十)(TR2310/TR2309) A level in a time dimension must have a time rank
- sudo: sorry, you must have a tty to run sudo
- sudo: sorry, you must have a tty to run sudo
- sudo: sorry, you must have a tty to run sudo
- A Couple of Must-have PeopleCode Coding Standards
- sudo: sorry, you must have a tty to run sudo
- sudo: sorry, you must have a tty to run sudo
- sudo: sorry, you must have a tty to run sudo
- sudo: sorry, you must have a tty to run sudo
- ViewStub报错:must have a valid layoutResource解决
- 微软面试100题2010年版全部答案集锦(含下载地址)
- 【吹B不如多学习】android系统目录
- Windows 批处理文件 (.bat) 复制命令怎么写?
- 阻止a标签事件冒泡
- 内存5大区
- NGUI_Panel(clipped panels must have a uniform scale)
- leetcode 551. Student Attendance Record I
- PLSQL使用中的一些小问题
- 2017.7.20随笔
- 纯真IP数据库QQWry.dat格式详解
- [Hadoop]Hdfs-创建文件过程详解
- MY_Swift_Generators 与 Sequences 浅析
- 一款火爆整个夏天的棋牌游戏,招代理啦!
- android 内存优化