//----------------------------------------------------------- /// <summary> /// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) /// </summary> /// <param name="tOption"></param> override protected void OnBuild(string tOption = "") { SetAnchorToLeftStretch(); Vector2 tSize = GetCanvasSize(); if (tSize.x > 0 && tSize.y > 0) { _w = tSize.x * 0.5f; } SetPivot(0, 0); Image tImage = _image; tImage.color = new Color32(255, 255, 255, 32); isCanvasGroup = true; isEventTrigger = true; UIAtlasSprite tAtlas = UIAtlasSprite.Create("uGUIHelper/Textures/UISimpleJoystick"); UIImage tFrame = AddView <UIImage>("Frame"); tFrame.SetAnchorToLeftBottom(); tFrame.sprite = tAtlas["UISimpleJoystick_Frame_Type_0"]; tFrame.SetSize(frameWidth, frameWidth); frame = tFrame; float thumbWidth = frameWidth * thumbScale; UIImage tThumb = tFrame.AddView <UIImage>("Thumb"); tThumb.SetAnchorToCenter(); tThumb.sprite = tAtlas["UISimpleJoystick_Thumb_Type_0"]; tThumb.SetSize(thumbWidth, thumbWidth); thumb = tThumb; // DestroyImmediate( tAtlas ) ; }
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 }
//--------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string option = "") { Toggle toggle = _toggle; if (toggle == null) { toggle = gameObject.AddComponent <Toggle>(); } if (toggle == null) { // 異常 return; } //------------------------- Vector2 tSize = GetCanvasSize(); if (tSize.x > 0 && tSize.y > 0) { SetSize(tSize.y * 0.25f, tSize.y * 0.05f); } // Background background = AddView <UIImage>("Background"); background.SetAnchorToLeftMiddle(); background.SetPosition(_h * 0.5f, 0); background.SetSize(_h, _h); background.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame"); background.type = Image.Type.Sliced; background.fillCenter = true; background.raycastTarget = true; // 必須 if (isCanvasOverlay == true) { background.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } toggle.targetGraphic = background._image; // Checkmark checkmark = background.AddView <UIImage>("Checkmark"); checkmark.SetAnchorToCenter(); checkmark.SetSize(_h, _h); checkmark.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultCheck"); if (isCanvasOverlay == true) { checkmark.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } toggle.graphic = checkmark._image; // Label label = AddView <UIText>("Label"); label.SetAnchorToLeftMiddle(); label.SetPosition(_h * 1.2f, 0); label.SetPivot(0, 0.5f); // label.text = "Toggle" ; label.fontSize = ( int )(_h * 0.75f); if (isCanvasOverlay == true) { label.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } //---------------------------------------- // 親にグループがアタッチされていればグループとみなす ToggleGroup toggleGroup = GetComponentInParent <ToggleGroup>(); if (toggleGroup != null) { toggle.group = toggleGroup; } //---------------------------------------- ResetRectTransform(); }
//----------------------------------------------------- /// <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 ) ; }