예제 #1
0
        //----------------------------------------------------

        /// <summary>
        /// Thumb 更新
        /// </summary>
        private void UpdateThumb()
        {
            if (scope == null || thumb == null)
            {
                return;
            }

            if (m_DisplayType == DisplayType.Stretch)
            {
                if (m_Value <= 0)
                {
                    scope.SetActive(false);
                }
                else
                {
                    scope.SetActive(true);

                    scope.SetAnchorToStretch();
                    scope.SetAnchorMin(0, 0);
                    scope.SetAnchorMax(m_Value, 1);

                    thumb.SetAnchorToStretch();
                    thumb.SetMargin(0, 0, 0, 0);
                }
            }
            else
            if (m_DisplayType == DisplayType.Mask)
            {
                if (m_Value <= 0)
                {
                    scope.SetActive(false);
                }
                else
                {
                    scope.SetActive(true);
                    scope.SetAnchorToStretch();

                    float d = scope._w * (1.0f - m_Value);

                    scope.SetMargin(0, d, 0, 0);

                    thumb.SetAnchorToStretch();
                    thumb.SetMargin(0, -d, 0, 0);
                }
            }
        }
예제 #2
0
        private void Open_Private(string tText, string tTextPlaceholder, KeyboardType tKeyboardType, bool tIsMultiLine, bool tIsSecure, bool tHideInput, Action <State, string> tOnValueChaned)
        {
            // コールバックを登録する
            m_OnValueChanged = tOnValueChaned;

            // 初期の文字列を保存する
            m_InitialText = tText;

            // 現在の文字列を保存する
            m_ActiveText = tText;

            //-------------------------------------------------

#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS)
            // 実機
            TouchScreenKeyboardType tMobileKeyboardType = TouchScreenKeyboardType.Default;
            if (tKeyboardType == KeyboardType.Default)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.Default;
            }
            else
            if (tKeyboardType == KeyboardType.ASCIICapable)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.ASCIICapable;
            }
            else
            if (tKeyboardType == KeyboardType.NumbersAndPunctuation)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.NumbersAndPunctuation;
            }
            else
            if (tKeyboardType == KeyboardType.URL)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.URL;
            }
            else
            if (tKeyboardType == KeyboardType.NumberPad)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.NumberPad;
            }
            else
            if (tKeyboardType == KeyboardType.PhonePad)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.PhonePad;
            }
            else
            if (tKeyboardType == KeyboardType.NamePhonePad)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.NamePhonePad;
            }
            else
            if (tKeyboardType == KeyboardType.EmailAddress)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.EmailAddress;
            }

            TouchScreenKeyboard.hideInput = tHideInput;

            m_VirtualKeyboard = TouchScreenKeyboard.Open
                                (
                tText,
                tMobileKeyboardType,
                true,
                tIsMultiLine,
                tIsSecure,
                false,
                tTextPlaceholder
                                );
#else
            // PC

            // フルスクリーンのキャンバスを生成する
            UICanvas tCanvas = UICanvas.CreateWithCamera(transform, 0, 0);


            // キャンバスのカメラを取得する
            Camera tCamera = tCanvas.GetCanvasCamera();

            // キャンバスのカメラをかなり手前に設定する
            tCamera.depth = 32767;

            // カメラを塗りつぶさないようにする
            tCamera.clearFlags = CameraClearFlags.Nothing;

            // 全画面用のイメージを追加する
            UIImage tScreen = tCanvas.AddView <UIImage>("Virtaul Keyboard Screen");
            tScreen.SetAnchorToStretch();               // 全画面表示にする
            tScreen.isMask = true;
            tScreen._mask.showMaskGraphic = false;

            Vector2 tCanvasSize = tScreen.GetCanvasSize();

            float cw = tCanvasSize.x;              // tCanvas._w ;
            float ch = tCanvasSize.y;              // tCanvas._h ;

            // 最も基本的な縦の長さ
            float bw = cw;
            float bh = ch * 0.1f;

            int tFontSize = ( int )(bh * 0.4f);

            //---------------------------------------------------------

            // 土台部分を作る
            UIImage tBase = tScreen.AddView <UIImage>("Base");
            tBase.SetAnchorToStretchBottom();
            tBase.SetPivotToCenterBottom();

            if (tIsMultiLine == false)
            {
                // シングル
                tBase._h = bh * 2;
            }
            else
            {
                // マルチ
                tBase._h = bh * 6;
            }

            // テキスト入力部を作る
            string tOption = "";
            if (tIsMultiLine == true)
            {
                tOption = "MultiLine";
            }
            UIInputField tInputField = tBase.AddView <UIInputField>("Input", tOption);
            tInputField.SetAnchorToStretchTop();
            tInputField.SetPivotToCenterTop();
            tInputField.SetMarginX(2, 2);
            tInputField._y = -2;

            tInputField.text             = tText;
            tInputField.placeholder.text = tTextPlaceholder;

            if (tIsMultiLine == false)
            {
                tInputField._h = (bh * 1) - 4;
            }
            else
            {
                tInputField._h = (bh * 5) - 4;

                // デフォルトでニューラインになっているのでサブミットに変える
                tInputField.lineType = UnityEngine.UI.InputFieldPlus.LineType.MultiLineSubmit;
            }
            tInputField.SetFontSize(tFontSize);

            if (tKeyboardType == KeyboardType.Default)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Standard;
            }
            else
            if (tKeyboardType == KeyboardType.ASCIICapable)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Alphanumeric;
            }
            else
            if (tKeyboardType == KeyboardType.NumbersAndPunctuation)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.IntegerNumber;
            }
            else
            if (tKeyboardType == KeyboardType.URL)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Autocorrected;
            }
            else
            if (tKeyboardType == KeyboardType.NumberPad)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.DecimalNumber;
            }
            else
            if (tKeyboardType == KeyboardType.PhonePad)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Pin;
            }
            else
            if (tKeyboardType == KeyboardType.NamePhonePad)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Name;
            }
            else
            if (tKeyboardType == KeyboardType.EmailAddress)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.EmailAddress;
            }

            if (tIsSecure == true)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Password;
            }

            // 状態が変化した際に呼び出される
            tInputField.SetOnValueChanged(OnValueChanged);

            // リターンキーによる決定時に呼び出される
            //	tInputField.SetOnEndEditDelegate( OnEndEdit ) ;
            tInputField.SetOnEnterKeyPressed(OnEndEdit);


            // OKボタンを作る
            UIButton tButton_OK = tBase.AddView <UIButton>("OK");
            tButton_OK.SetAnchorToLeftBottom();
            tButton_OK.SetSize(bw * 0.5f - 4, bh - 4);
            tButton_OK.SetPosition(bw * 0.25f, bh * 0.5f);
            tButton_OK.AddLabel("OK", 0xFFFFFFFF, tFontSize);
            tButton_OK.SetOnButtonClick(OnClick);

            // CANCELボタンを作る
            UIButton tButton_Cancel = tBase.AddView <UIButton>("Cancel");
            tButton_Cancel.SetAnchorToRightBottom();
            tButton_Cancel.SetSize(bw * 0.5f - 4, bh - 4);
            tButton_Cancel.SetPosition(-bw * 0.25f, bh * 0.5f);
            tButton_Cancel.AddLabel("CANCEL", 0xFFFFFFFF, tFontSize);
            tButton_Cancel.SetOnButtonClick(OnClick);

            float tH = tBase._h;

            UITween tTweenUp = tBase.AddTween("Up");
            tTweenUp.delay            = 0;
            tTweenUp.duration         = 0.25f;
            tTweenUp.positionEnabled  = true;
            tTweenUp.positionEaseType = UITween.EaseType.easeOutQuad;
            tTweenUp.positionFromY    = -tH;
            tTweenUp.playOnAwake      = false;

            UITween tTweenDown = tBase.AddTween("Down");
            tTweenDown.delay            = 0;
            tTweenDown.duration         = 0.25f;
            tTweenDown.positionEnabled  = true;
            tTweenDown.positionEaseType = UITween.EaseType.easeOutQuad;
            tTweenDown.positionToY      = -tH;
            tTweenDown.playOnAwake      = false;

            tTweenDown.SetOnFinished((string tIdentity, UITween tTween) =>
            {
                Destroy(gameObject);
            });

            tBase.PlayTween("Up");

            m_Base = tBase;
#endif
        }
예제 #3
0
        //-----------------------------------------------------

        /// <summary>
        /// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        /// </summary>
        /// <param name="tOption"></param>
        override protected void OnBuild(string tOption = "")
        {
            Vector2 tSize = GetCanvasSize();

            if (tSize.x > 0 && tSize.y > 0)
            {
                float s;
                if (tSize.x <= tSize.y)
                {
                    s = tSize.x;
                }
                else
                {
                    s = tSize.y;
                }
                SetSize(s * 0.5f, s * 0.05f);
            }


            Sprite tDefaultFrameSprite = null;
            Sprite tDefaultThumbSprite = null;

#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                // メニューから操作した場合のみ自動設定を行う
                DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings");
                if (tDS != null)
                {
                    tDefaultFrameSprite = tDS.progressbarFrame;
                    tDefaultThumbSprite = tDS.progressbarThumb;
                }
            }
#endif

            UIAtlasSprite tAtlas = UIAtlasSprite.Create("uGUIHelper/Textures/UIProgressbar");

            // Frame
            Image tFrame = _image;

            if (tDefaultFrameSprite == null)
            {
                tFrame.sprite = tAtlas["UIProgressbar_Frame"];
            }
            else
            {
                tFrame.sprite = tDefaultFrameSprite;
            }
            tFrame.type       = Image.Type.Sliced;
            tFrame.fillCenter = true;

            if (isCanvasOverlay == true)
            {
                tFrame.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            UIView tFillArea = AddView <UIView>("Fill Area");
            tFillArea.SetAnchorToStretch();

            // Mask
            scope = tFillArea.AddView <UIImage>("Scope");
            scope.SetAnchorToStretch();
            scope.SetMargin(0, 0, 0, 0);

            scope.isMask          = true;
            scope.showMaskGraphic = false;

            if (isCanvasOverlay == true)
            {
                scope.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            // Thumb
            thumb = scope.AddView <UIImage>("Thumb");
            thumb.SetAnchorToStretch();
            thumb.SetMargin(0, 0, 0, 0);

            if (tDefaultThumbSprite == null)
            {
                thumb.sprite = tAtlas["UIProgressbar_Thumb"];
            }
            else
            {
                thumb.sprite = tDefaultThumbSprite;
            }
            thumb.type       = Image.Type.Sliced;
            thumb.fillCenter = true;

            if (isCanvasOverlay == true)
            {
                thumb.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            UpdateThumb();

            // Label
            label           = AddView <UINumber>("Label");
            label.fontSize  = ( int )(_h * 0.6f);
            label.isOutline = true;
            label.percent   = true;

            if (isCanvasOverlay == true)
            {
                label.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            UpdateLabel();

//			DestroyImmediate( tAtlas ) ;
        }
예제 #4
0
        //-----------------------------------------------------------

        // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        override protected void OnBuild(string tOption = "")
        {
            Scrollbar tScrollbar = _scrollbar;

            if (tScrollbar == null)
            {
                tScrollbar = gameObject.AddComponent <Scrollbar>();
            }
            if (tScrollbar == null)
            {
                // 異常
                return;
            }

            //----------------------------------

            Direction tDirection = Direction.Unknown;

            if (tOption.ToLower() == "h")
            {
                tDirection = Direction.Horizontal;
            }
            else
            if (tOption.ToLower() == "v")
            {
                tDirection = Direction.Vertical;
            }

            Vector2 tSize = GetCanvasSize();

            if (tSize.x > 0 && tSize.y > 0)
            {
                float s;
                if (tSize.x <= tSize.y)
                {
                    s = tSize.x;
                }
                else
                {
                    s = tSize.y;
                }

                if (tDirection == Direction.Horizontal)
                {
                    SetSize(s * 0.4f, s * 0.075f);
                    tScrollbar.direction = Scrollbar.Direction.LeftToRight;
                }
                else
                if (tDirection == Direction.Vertical)
                {
                    SetSize(s * 0.075f, s * 0.4f);
                    tScrollbar.direction = Scrollbar.Direction.BottomToTop;
                }
            }

            ColorBlock tColorBlock = tScrollbar.colors;

            tColorBlock.fadeDuration = 0.2f;
            tScrollbar.colors        = tColorBlock;

            Image tImage = _image;

            tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame");
            tImage.color  = Color.white;
            tImage.type   = Image.Type.Sliced;


//			UIImage tFrame = AddView<UIImage>( "Frame" ) ;
//			tFrame.SetAnchorToStretch() ;
//			tFrame.SetMargin(  0,  0,  0,  0 ) ;
//			tFrame.sprite = Resources.Load<Sprite>( "uGUIHelper/Textures/UIDefaultFrame" ) ;
//			tFrame.color = Color.white ;
//			tFrame.type = Image.Type.Sliced ;


            UIView tSlidingArea = AddView <UIView>("Sliding Area");

            tSlidingArea.SetAnchorToStretch();
            tSlidingArea.SetMargin(10, 10, 10, 10);

            UIImage tHandle = tSlidingArea.AddView <UIImage>("Handle");

            if (tDirection == Direction.Horizontal)
            {
                tHandle.SetAnchorToStretch();
            }
            else
            if (tDirection == Direction.Vertical)
            {
                tHandle.SetAnchorToStretch();
            }
            tHandle.SetMargin(-10, -10, -10, -10);

            tHandle.sprite     = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultButton");
            tHandle.type       = Image.Type.Sliced;
            tHandle.fillCenter = true;

            tScrollbar.targetGraphic = tHandle._image;
            tScrollbar.handleRect    = tHandle._rectTransform;

            ResetRectTransform();
        }