• 【原】NGUI中的UIRoot脚本功能


    UIRoot是NGUI控件的根节点,使用是根据屏幕尺寸自动(或手动)调节节点下子控件的大小。

    这个组件声明了在编辑模式下运行:[ExecuteInEditMode],在Inspector编辑修改属性值时,可以直接影响控件。

    UIRoot有两个开放属性:

    Automatic: bool

    ManualHeight: float

    在Inspector中,如果Automatic为true,则自动调节;如果是false,则可以手工调节ManualHeight。

    调整时可以直接看到控制尺寸的变化。

    //----------------------------------------------
    //            NGUI: Next-Gen UI kit
    // Copyright © 2011-2012 Tasharen Entertainment
    //----------------------------------------------
    
    using UnityEngine;
    
    /// <summary>
    /// This is a script used to keep the game object scaled to 2/(Screen.height).
    /// If you use it, be sure to NOT use UIOrthoCamera at the same time.
    /// </summary>
    
    [ExecuteInEditMode]
    [AddComponentMenu("NGUI/UI/Root")]
    public class UIRoot : MonoBehaviour
    {
        public bool automatic = true;
        public int manualHeight = 800;
    
        Transform mTrans;
    
        void Start ()
        {
            mTrans = transform;
    
            UIOrthoCamera oc = GetComponentInChildren<UIOrthoCamera>();
            
            if (oc != null)
            {
                Debug.LogWarning("UIRoot should not be active at the same time as UIOrthoCamera. Disabling UIOrthoCamera.", oc);
                Camera cam = oc.gameObject.GetComponent<Camera>();
                oc.enabled = false;
                if (cam != null) cam.orthographicSize = 1f;
            }
        }
    
        void Update ()
        {
            manualHeight = Mathf.Max(2, automatic ? Screen.height : manualHeight);
    
            float size = 2f / manualHeight;
            Vector3 ls = mTrans.localScale;
    
            if (!Mathf.Approximately(ls.x, size) ||
                !Mathf.Approximately(ls.y, size) ||
                !Mathf.Approximately(ls.z, size))
            {
                mTrans.localScale = new Vector3(size, size, size);
            }
        }
    }
    View Code
  • 相关阅读:
    NSArray & NSDictionary
    copy&mutableCopy 浅拷贝(shallow copy)深拷贝 (deep copy)
    03-图形上下文栈, 图形的平移 旋转 缩放
    02- 画文字和图片-------------之前写的那个微博项目,可以试试用画图片的方式来处理,这样应该比UILabel 代码少点,一会试试
    Quartz 官网翻译(转载)
    01 画简单线的方法
    @property 修饰符
    SEL 类型
    Java 常用快捷键
    Java判断是否为数字
  • 原文地址:https://www.cnblogs.com/basecn/p/NGUI_UIRoot.html
Copyright © 2020-2023  润新知