예제 #1
0
    /// <summary>
    /// Draw some selectable gizmos.
    /// </summary>

    void OnDrawGizmos()
    {
        if (isVisible && NGUITools.IsActive(this))
        {
            if (UnityEditor.Selection.activeGameObject == gameObject && showHandles)
            {
                return;
            }

            Color outline = new Color(1f, 1f, 1f, 0.2f);

            Vector2 offset = pivotOffset;
            Vector3 center = new Vector3(mWidth * (0.5f - offset.x), mHeight * (0.5f - offset.y), -mDepth * 0.25f);
            Vector3 size   = new Vector3(mWidth, mHeight, 1f);

            // Draw the gizmo
            Gizmos.matrix = cachedTransform.localToWorldMatrix;
            Gizmos.color  = (UnityEditor.Selection.activeGameObject == cachedTransform) ? Color.white : outline;
            Gizmos.DrawWireCube(center, size);

            // Make the widget selectable
            size.z       = 0.01f;
            Gizmos.color = Color.clear;
            Gizmos.DrawCube(center, size);
        }
    }
예제 #2
0
    /// <summary>
    /// Notification of the input field losing selection.
    /// </summary>

    protected void OnDeselectEvent()
    {
        if (mDoInit)
        {
            Init();
        }

        if (label != null && NGUITools.IsActive(this))
        {
            mValue = value;
#if MOBILE
            if (mKeyboard != null)
            {
                mKeyboard.active = false;
                mKeyboard        = null;
            }
#else
            mEditor = null;
#endif
            if (string.IsNullOrEmpty(mValue))
            {
                label.text  = mDefaultText;
                label.color = mDefaultColor;
            }
            else
            {
                label.text = mValue;
            }

            Input.imeCompositionMode = IMECompositionMode.Off;
            RestoreLabelPivot();
        }

        selection = null;
    }
예제 #3
0
    void Update()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif
        if (isSelected && NGUITools.IsActive(this))
        {
            if (mDoInit)
            {
                Init();
            }

            if (selectOnTab != null && Input.GetKeyDown(KeyCode.Tab))
            {
                UICamera.selectedObject = selectOnTab;
                return;
            }

            // Process input
            Append(Input.inputString);

            if (mLastIME != Input.compositionString)
            {
                mLastIME = Input.compositionString;
                UpdateLabel();
                ExecuteOnChange();
            }
        }
    }
예제 #4
0
    /// <summary>
    /// Adjust the widget's collider size to match the widget's dimensions.
    /// </summary>

    public void ResizeCollider()
    {
        if (NGUITools.IsActive(this))
        {
            BoxCollider box = collider as BoxCollider;
            if (box != null)
            {
                NGUITools.UpdateWidgetCollider(box, true);
            }
        }
    }
예제 #5
0
    /// <summary>
    /// Submit the input field's text.
    /// </summary>

    protected void Submit()
    {
        if (NGUITools.IsActive(this))
        {
            current = this;
            mValue  = value;
            EventDelegate.Execute(onSubmit);
            SaveToPlayerPrefs(mValue);
            current = null;
        }
    }
예제 #6
0
    /// <summary>
    /// Adjust the widget's collider size to match the widget's dimensions.
    /// </summary>

    void ResizeCollider()
    {
        if (NGUITools.IsActive(this))
        {
            BoxCollider box = GetComponent <Collider>() as BoxCollider;
            if (box != null)
            {
                NGUITools.UpdateWidgetCollider(box, true);
            }
        }
    }
예제 #7
0
    /// <summary>
    /// Update the text based on input.
    /// </summary>

#if MOBILE
    void Update()
    {
        if (mKeyboard != null && isSelected && NGUITools.IsActive(this))
        {
            string val = mKeyboard.text;

            if (mValue != val)
            {
                mValue = "";

                for (int i = 0; i < val.Length; ++i)
                {
                    char c = val[i];
                    if (onValidate != null)
                    {
                        c = onValidate(mValue, mValue.Length, c);
                    }
                    else if (validation != Validation.None)
                    {
                        c = Validate(mValue, mValue.Length, c);
                    }
                    if (c != 0)
                    {
                        mValue += c;
                    }
                }

                if (characterLimit > 0 && mValue.Length > characterLimit)
                {
                    mValue = mValue.Substring(0, characterLimit);
                }

                UpdateLabel();
                ExecuteOnChange();

                if (mValue != val)
                {
                    mKeyboard.text = mValue;
                }
            }

            if (mKeyboard.done)
            {
#if !UNITY_3_5
                if (!mKeyboard.wasCanceled)
#endif
                Submit();
                mKeyboard  = null;
                isSelected = false;
            }
        }
    }
예제 #8
0
    /// <summary>
    /// Notification of the input field gaining selection.
    /// </summary>

    protected void OnSelectEvent()
    {
        selection = this;

        if (mDoInit)
        {
            Init();
        }

        if (label != null && NGUITools.IsActive(this))
        {
            label.color = activeTextColor;
#if MOBILE
            if (Application.platform == RuntimePlatform.IPhonePlayer ||
                Application.platform == RuntimePlatform.Android
#if UNITY_WP8
                || Application.platform == RuntimePlatform.WP8Player
#endif
#if UNITY_BLACKBERRY
                || Application.platform == RuntimePlatform.BB10Player
#endif
                )
            {
                mKeyboard = (inputType == InputType.Password) ?
                            TouchScreenKeyboard.Open(mValue, TouchScreenKeyboardType.Default, false, false, true) :
                            TouchScreenKeyboard.Open(mValue, (TouchScreenKeyboardType)((int)keyboardType), inputType == InputType.AutoCorrect);
            }
            else
#endif
            {
                Input.imeCompositionMode   = IMECompositionMode.On;
                Input.compositionCursorPos = (UICamera.current != null && UICamera.current.cachedCamera != null) ?
                                             UICamera.current.cachedCamera.WorldToScreenPoint(label.worldCorners[0]) :
                                             label.worldCorners[0];
#if !MOBILE
                mEditor         = new TextEditor();
                mEditor.content = new GUIContent(mValue);
                mEditor.OnFocus();
                mEditor.MoveTextEnd();
#endif
                mDrawStart = 0;
                mDrawEnd   = 0;
            }
            UpdateLabel();
        }
    }
예제 #9
0
    /// <summary>
    /// Notification of the input field losing selection.
    /// </summary>

    protected void OnDeselectEvent()
    {
        if (mDoInit)
        {
            Init();
        }

        if (label != null && NGUITools.IsActive(this))
        {
            mValue = value;
#if MOBILE
            if (mKeyboard != null)
            {
                mKeyboard.active = false;
                mKeyboard        = null;
            }
#else
            mEditor = null;
#endif
            if (string.IsNullOrEmpty(mValue))
            {
                label.text  = mDefaultText;
                label.color = mDefaultColor;
            }
            else
            {
                label.text = mValue;
            }

            Input.imeCompositionMode = IMECompositionMode.Off;
            RestoreLabelPivot();
        }

        selection = null;

        if (inputType == InputType.Password)
        {
            string password = "";
            for (int i = 0, imax = value.Length; i < imax; ++i)
            {
                password += "*";
            }
            label.text = password;
        }
    }
예제 #10
0
    /// <summary>
    /// Play the specified audio clip with the specified volume and pitch.
    /// </summary>

    static public AudioSource PlaySound(AudioClip clip, float volume, float pitch)
    {
        volume *= soundVolume;

        if (clip != null && volume > 0.01f)
        {
            if (mListener == null || !NGUITools.IsActive(mListener))
            {
                mListener = GameObject.FindObjectOfType(typeof(AudioListener)) as AudioListener;

                if (mListener == null)
                {
                    Camera cam = Camera.main;
                    if (cam == null)
                    {
                        cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
                    }
                    if (cam != null)
                    {
                        mListener = cam.gameObject.AddComponent <AudioListener>();
                    }
                }
            }

            if (mListener != null && mListener.enabled && NGUITools.GetActive(mListener.gameObject))
            {
                AudioSource source = mListener.GetComponent <AudioSource>();
                if (source == null)
                {
                    source = mListener.gameObject.AddComponent <AudioSource>();
                }
                source.pitch = pitch;
                source.PlayOneShot(clip, volume);
                return(source);
            }
        }
        return(null);
    }