コード例 #1
0
    private void Update()
    {
        var rate = m_canvasScaler.referenceResolution.y / Screen.height;
        var pos  = m_rectTransform.anchoredPosition;

        pos.y = SoftwareKeyboardArea.GetHeight(true) * rate;
        m_rectTransform.anchoredPosition = pos;
    }
コード例 #2
0
    private void OnGUI()
    {
        //GUILayout.Label();
        GUIStyle style = new GUIStyle();

        style.fontSize = 100;
        GUI.Label(new Rect(100, 100, 200, 100), SoftwareKeyboardArea.GetHeight(true).ToString(), style);
        GUI.Label(new Rect(100, 200, 200, 100), "decord:  " + SoftwareKeyboardArea.mDecorHeight.ToString(), style);
    }
コード例 #3
0
    void Start()
    {
#if UNITY_IOS && !UNITY_EDITOR
        submitButton.OnPointerEnterAsObservable()
        .Subscribe(_ => { _keyboard = TouchScreenKeyboard.Open(string.Empty, TouchScreenKeyboardType.Search); })
        .AddTo(this);
        submitButton.OnPointerUpAsObservable()
        .Subscribe(_ =>
        {
            // ボタンを押さずに離した場合にフォーカスを戻す
            EventSystem.current.SetSelectedGameObject(chatInput.gameObject);
        }).AddTo(this);
#endif

        submitButton.onClick.AsObservable()
        .Subscribe(unit => Send())
        .AddTo(this);

#if !UNITY_EDITOR
        // keyboardの参照を取得
        chatInput.OnSelectAsObservable()
        .Subscribe(_ => { _keyboard = TouchScreenKeyboard.Open(string.Empty, TouchScreenKeyboardType.Search); })
        .AddTo(this);

        // keyboardステータスを監視
        Observable.EveryUpdate()
        .Where(_ => _keyboard != null)
        .Select(_ => _keyboard.status)
        .DistinctUntilChanged()
        .Subscribe(status =>
        {
            switch (status)
            {
            case TouchScreenKeyboard.Status.Visible:
#if UNITY_ANDROID
                // Androidではキーボード表示中にUI要素をタッチできない
                submitButton.interactable = false;
#endif
                break;

            case TouchScreenKeyboard.Status.Done:
                Send();
                submitButton.interactable = true;
                break;

            case TouchScreenKeyboard.Status.Canceled:
            case TouchScreenKeyboard.Status.LostFocus:
                submitButton.interactable = true;
                break;
            }
        })
        .AddTo(this);
#endif

        Observable.EveryUpdate()
        .Select(_ => SoftwareKeyboardArea.GetHeight())
        .DistinctUntilChanged()
        .Subscribe(height =>
        {
            var safeAreaBottom   = Screen.safeArea.y;
            var resolutionHeight = chatContainer
                                   .GetComponentInParent <CanvasScaler>()
                                   .GetComponent <RectTransform>().sizeDelta.y;
            var rate = resolutionHeight / Screen.height;

            var margin = (int)(height <= 0 ? 0 : (height - safeAreaBottom) * rate);
            chatContainer.sizeDelta = new Vector2(0, -margin);
        }).AddTo(this);
    }