unity3D总结的一些细节,不注意有些要折腾非常多天!

1. 注意!!ps保存图片时,若保存为ps格式,若关闭最大兼容将会导致unity导入失败!(n天)

2.switch 推断NGUI popuplist传来的value字符串时一定要trim一下去掉空格!

3. 获取子物体时,方法不同得到的结果不同!

foreach(Transform tr in transform) 返回的是下一级子物体,通俗点就是“儿子”。

Transform []  allModel = GetComponentsInChildren<Transform>(); 返回的是全部层级子物体,包含儿子、孙子、重孙...

4.注意resources.load和Instantiate方法后面都要用到as,由于他们一个是Object类型,一个是泛型!

GameObject o =Resources.Load("Machine_Small/" + str) as GameObject;
GameObject temp = Instantiate(o) as GameObject;



5.NGUI 的grid 和table组件没有详细形状,在场景中看不到实际大小,解决的方法:再加一个widget组件
6.NGUI3.X版本号以上,事件系统要注意:
有的要用到新的事件系统,比方OnChange:
EventDelegate.Add(voiceVolume.onChange,delegate (){
            Globle.voiceVolume = UISlider.current.value;
            Debug.Log(Globle.voiceVolume);
        });
有的要用老的,如OnDragFinished:
bkMisicVolume.onDragFinished  = showMessage;
void showMessage()
    {
        //Globle.bkMusicVolume = UISlider.current.value;
        Debug.Log(bkMisicVolume.value);
    }
7.NGUI 的 UICamera.eventReceiverMask的值,设为0,不接受不论什么事件,设为-1,生效


原文地址:https://www.cnblogs.com/blfshiye/p/3781691.html