Example #1
0
    /// <summary>
    /// Load the specified text file and activate the localization.
    /// </summary>

    void Load(string fileName)
    {
        mLanguage = fileName;
        PlayerPrefs.SetString("Language", mLanguage);

        string[] itemList = ResourceManager.LoadText(fileName);
        if (itemList != null)
        {
            char[] separator = new char[] { '=' };

            mDictionary.Clear();

            int l = itemList.Length;
            for (int i = 0; i < l; ++i)
            {
                if (itemList[i].StartsWith("//"))
                {
                    continue;
                }

                string[] split = itemList[i].Split(separator, System.StringSplitOptions.RemoveEmptyEntries);
                if (split.Length == 2)
                {
                    string key = split[0].Trim();
                    string val = split[1].Trim().Replace("\\n", "\n");
                    mDictionary[key] = val;
                }
            }
        }

        NGUIRoot.Broadcast("OnLocalize", this);
        forceUpdate = false;
    }
Example #2
0
 void Start()
 {
     if (uiCamera == null)
     {
         uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
     }
     mRoot = NGUITools.FindInParents <NGUIRoot>(gameObject);
 }
Example #3
0
    /// <summary>
    /// Draw a visible pink outline for the clipped area.
    /// </summary>

    void OnDrawGizmos()
    {
        if (mDebugInfo == DebugInfo.Gizmos)
        {
            bool    clip = (mClipping != NGUIDrawCall.Clipping.None);
            Vector2 size = clip ? new Vector2(mClipRange.z, mClipRange.w) : Vector2.zero;

            GameObject go       = UnityEditor.Selection.activeGameObject;
            bool       selected = (go != null) && (NGUITools.FindInParents <NGUIPanel>(go) == this);

            if (selected || clip || (mCam != null && mCam.isOrthoGraphic))
            {
                if (size.x == 0f)
                {
                    size.x = mScreenSize.x;
                }
                if (size.y == 0f)
                {
                    size.y = mScreenSize.y;
                }

                if (!clip)
                {
                    NGUIRoot root = NGUITools.FindInParents <NGUIRoot>(gameObject);
                    if (root != null)
                    {
                        size *= root.GetPixelSizeAdjustment(mScreenHeight);
                    }
                }

                Transform t = clip ? transform : (mCam != null ? mCam.transform : null);

                if (t != null)
                {
                    Vector3 pos = new Vector2(mClipRange.x, mClipRange.y);

                    Gizmos.matrix = t.localToWorldMatrix;

                    if (go != gameObject)
                    {
                        Gizmos.color = clip ? Color.magenta : new Color(0.5f, 0f, 0.5f);
                        Gizmos.DrawWireCube(pos, size);

                        // Make the panel selectable
                        //Gizmos.color = Color.clear;
                        //Gizmos.DrawCube(pos, size);
                    }
                    else
                    {
                        Gizmos.color = Color.green;
                        Gizmos.DrawWireCube(pos, size);
                    }
                }
            }
        }
    }
Example #4
0
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    void Load(TextAsset asset)
    {
        mLanguage = asset.name;
        PlayerPrefs.SetString("Language", mLanguage);
        ByteReader reader = new ByteReader(asset);

        mDictionary = reader.ReadDictionary();
        NGUIRoot.Broadcast("OnLocalize", this);
        forceUpdate = false;
    }
Example #5
0
    /// <summary>
    /// Broadcast the specified message to the entire UI.
    /// </summary>

    static public void Broadcast(string funcName)
    {
        for (int i = 0, imax = mRoots.Count; i < imax; ++i)
        {
            NGUIRoot root = mRoots[i];
            if (root != null)
            {
                root.BroadcastMessage(funcName, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Example #6
0
    /// <summary>
    /// Broadcast the specified message to the entire UI.
    /// </summary>

    static public void Broadcast(string funcName, object param)
    {
        if (param == null)
        {
            // More on this: http://answers.unity3d.com/questions/55194/suggested-workaround-for-sendmessage-bug.html
            Debug.LogError("SendMessage is bugged when you try to pass 'null' in the parameter field. It behaves as if no parameter was specified.");
        }
        else
        {
            for (int i = 0, imax = mRoots.Count; i < imax; ++i)
            {
                NGUIRoot root = mRoots[i];
                if (root != null)
                {
                    root.BroadcastMessage(funcName, param, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }
Example #7
0
        private void LoadDependRoot()
        {
            mRootPanel = NGUITools.CreateUI(null, false, LayerMask.NameToLayer("NGUI"));

            if (UIRoot.list.Count > 0)
            {
                NGUIRoot   = UIRoot.list[0];
                WindowRoot = UITools.CreateObject("WndRoot", NGUIRoot.gameObject);
            }

            NGUIRoot.tag = "NGUIRoot";

            NGUICamera             = NGUIRoot.GetComponentInChildren <Camera>();
            NGUICamera.cullingMask = 1 << LayerMask.NameToLayer("NGUI");
            NGUICamera.clearFlags  = CameraClearFlags.Depth;

            NGUIRoot.manualWidth  = 960;
            NGUIRoot.manualHeight = 640;
            NGUIRoot.fitHeight    = true;
            NGUIRoot.scalingStyle = UIRoot.Scaling.ConstrainedOnMobiles;

            isLoadDependObject = true;
        }
Example #8
0
    /// <summary>
    /// Automatically find the camera responsible for drawing the widgets under this object.
    /// </summary>

    void Start()
    {
        mRoot = NGUITools.FindInParents <NGUIRoot>(gameObject);
        mNeedsHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer ||
                                 Application.platform == RuntimePlatform.XBOX360 ||
                                 Application.platform == RuntimePlatform.WindowsWebPlayer ||
                                 Application.platform == RuntimePlatform.WindowsEditor);

        // Only DirectX 9 needs the half-pixel offset
        if (mNeedsHalfPixelOffset)
        {
            mNeedsHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40);
        }

        if (uiCamera == null)
        {
            uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
        }
        if (uiCamera == null)
        {
            uiCamera = GameObject.Find("UI/GUI Camera").GetComponent <Camera>();
        }
        Update();
    }
Example #9
0
    /// <summary>
    /// Helper function that figures out the pixel size adjustment for the specified game object.
    /// </summary>

    static public float GetPixelSizeAdjustment(GameObject go)
    {
        NGUIRoot root = NGUITools.FindInParents <NGUIRoot>(go);

        return((root != null) ? root.pixelSizeAdjustment : 1f);
    }
 /// <summary>
 /// Cache the root.
 /// </summary>
 void Start()
 {
     mRoot = NGUITools.FindInParents<NGUIRoot>(gameObject);
 }
Example #11
0
 void Start()
 {
     if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
     mRoot = NGUITools.FindInParents<NGUIRoot>(gameObject);
 }
Example #12
0
    /// <summary>
    /// Cache the root.
    /// </summary>

    void Start()
    {
        mRoot = NGUITools.FindInParents <NGUIRoot>(gameObject);
    }
Example #13
0
    /// <summary>
    /// Automatically find the camera responsible for drawing the widgets under this object.
    /// </summary>
    void Start()
    {
        mRoot = NGUITools.FindInParents<NGUIRoot>(gameObject);
        mNeedsHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer ||
            Application.platform == RuntimePlatform.XBOX360 ||
            Application.platform == RuntimePlatform.WindowsWebPlayer ||
            Application.platform == RuntimePlatform.WindowsEditor);

        // Only DirectX 9 needs the half-pixel offset
        if (mNeedsHalfPixelOffset) mNeedsHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40);

        if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
        if (uiCamera == null) uiCamera = GameObject.Find("UI/GUI Camera").GetComponent<Camera>();
        Update();
    }