// override protected void DrawInspectorGUI() public override void OnInspectorGUI() { UICanvas tTarget = target as UICanvas; EditorGUILayout.Separator(); // 少し区切りスペース //------------------------------------------------------------------- // キャンバスグループを有効にするかどうか DrawCanvasGroup(tTarget); }
public static void AddCanvasOnCamera() { Transform tParent = null; GameObject tGameObject = Selection.activeGameObject; if (tGameObject != null) { if (WillLosePrefab(tGameObject) == false) { return; } tParent = tGameObject.transform; Undo.RecordObject(tGameObject, "Add a child UI Canvas On Camera"); // アンドウバッファに登録 } UICanvas tCanvas = UICanvas.CreateOnCamera(tParent, 800, 600); Selection.activeGameObject = tCanvas.gameObject; UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); }
/// <summary> /// キャンバスを生成する /// </summary> /// <param name="tParent"></param> /// <param name="w"></param> /// <param name="h"></param> /// <returns></returns> public static UICanvas Create(Transform tParent = null, float w = 0, float h = 0) { GameObject tCanvasGO = new GameObject("Canvas", typeof(RectTransform)); if (tParent != null) { tCanvasGO.transform.SetParent(tParent, false); } UICanvas tCanvas = tCanvasGO.AddComponent <UICanvas>(); tCanvas.SetDefault(); tCanvas.SetResolution(w, h); tCanvasGO.transform.localPosition = new Vector3(0, 0, -100); tCanvasGO.transform.localEulerAngles = new Vector3(0, 0, 0); tCanvasGO.transform.localScale = new Vector3(1, 1, 1); // 各 UIView は Canvas のターゲットレイヤーを元に自身のレイヤーを設定するので // Canvas だけは自身でレイヤーを設定しなければならない tCanvasGO.layer = 5; return(tCanvas); }
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 }
/// <summary> /// 親にカメラを持つ形でキャンバスを生成する /// </summary> /// <param name="tParent"></param> /// <param name="w"></param> /// <param name="h"></param> /// <returns></returns> public static UICanvas CreateOnCamera(Transform tParent = null, float w = 0, float h = 0, int tDepth = 0) { float rw = w; float rh = h; if (rw <= 0 && rh <= 0) { rw = Screen.width; rh = Screen.height; } else if (rw <= 0 && rh > 0) { rw = rh; } else if (rw > 0 && rh <= 0) { rh = rw; } Camera tCamera = null; if (tParent != null) { tCamera = tParent.GetComponent <Camera>(); } if (tCamera == null) { GameObject tCameraGO = new GameObject("Camera"); if (tParent != null) { tCameraGO.transform.SetParent(tParent, false); } tCameraGO.transform.localPosition = new Vector3(0, 0, 0); tCameraGO.transform.localEulerAngles = new Vector3(0, 0, 0); tCameraGO.transform.localScale = new Vector3(1, 1, 1); tCamera = tCameraGO.AddComponent <Camera>(); tCamera.clearFlags = CameraClearFlags.SolidColor; tCamera.backgroundColor = new Color(0, 0, 0, 0); tCamera.orthographic = true; tCamera.orthographicSize = rh * 0.5f; tCamera.nearClipPlane = 0.1f; tCamera.farClipPlane = 20000.0f; tCamera.cullingMask = 1 << 5; tCamera.depth = tDepth; tCamera.stereoTargetEye = StereoTargetEyeMask.None; } //------------------------ GameObject tCanvasGO = new GameObject("Canvas", typeof(RectTransform)); tCanvasGO.transform.SetParent(tCamera.transform, false); UICanvas tCanvas = tCanvasGO.AddComponent <UICanvas>(); tCanvas.SetDefault(); tCanvas.SetResolution(w, h); // 各 UIView は Canvas のターゲットレイヤーを元に自身のレイヤーを設定するので // Canvas だけは自身でレイヤーを設定しなければならない tCanvasGO.layer = 5; //------------------------ tCanvas._canvas.renderMode = RenderMode.ScreenSpaceCamera; tCanvas._canvas.pixelPerfect = true; tCanvas._canvas.worldCamera = tCamera; tCanvas._canvas.planeDistance = 100; //---------------------------------------------------------- tCanvasGO.transform.localPosition = new Vector3(0, 0, 0); tCanvasGO.transform.localEulerAngles = new Vector3(0, 0, 0); tCanvasGO.transform.localScale = new Vector3(1, 1, 1); return(tCanvas); }
// キャンバスグループの設定項目を描画する private void DrawCanvasGroup(UICanvas tTarget) { // キャンバスグループを有効にするかどうか EditorGUILayout.Separator(); // 少し区切りスペース UICanvas.AutomaticRenderMode tRenderMode = (UICanvas.AutomaticRenderMode)EditorGUILayout.EnumPopup("Effect Mode", tTarget.renderMode); if (tRenderMode != tTarget.renderMode) { Undo.RecordObject(tTarget, "UICanvas : Render Mode Change"); // アンドウバッファに登録 tTarget.renderMode = tRenderMode; EditorUtility.SetDirty(tTarget); } float tWidth = EditorGUILayout.FloatField(" Width", tTarget.width /*, GUILayout.Width( 120f ) */); if (tWidth != tTarget.width) { Undo.RecordObject(tTarget, "UICanvas : Width Change"); // アンドウバッファに登録 tTarget.width = tWidth; EditorUtility.SetDirty(tTarget); } float tHeight = EditorGUILayout.FloatField(" Height", tTarget.height /*, GUILayout.Width( 120f ) */); if (tHeight != tTarget.height) { Undo.RecordObject(tTarget, "UICanvas : Height Change"); // アンドウバッファに登録 tTarget.height = tHeight; EditorUtility.SetDirty(tTarget); } int tDepth = EditorGUILayout.IntField(" Depth", tTarget.depth /*, GUILayout.Width( 120f ) */); if (tDepth != tTarget.depth) { Undo.RecordObject(tTarget, "UICanvas : Depth Change"); // アンドウバッファに登録 tTarget.depth = tDepth; EditorUtility.SetDirty(tTarget); } Camera tRenderCamera = EditorGUILayout.ObjectField(" Render Camera", tTarget.renderCamera, typeof(Camera), true) as Camera; if (tRenderCamera != tTarget.renderCamera) { Undo.RecordObject(tTarget, "UICanvas : Render Camera Change"); // アンドウバッファに登録 tTarget.renderCamera = tRenderCamera; EditorUtility.SetDirty(tTarget); } float tVrDistance = EditorGUILayout.FloatField(" VR Distance", tTarget.vrDistance /*, GUILayout.Width( 120f ) */); if (tVrDistance != tTarget.vrDistance) { Undo.RecordObject(tTarget, "UICanvas : VR Distance Change"); // アンドウバッファに登録 tTarget.vrDistance = tVrDistance; EditorUtility.SetDirty(tTarget); } float tVrScale = EditorGUILayout.FloatField(" VR Scale", tTarget.vrScale /*, GUILayout.Width( 120f ) */); if (tVrScale != tTarget.vrScale) { Undo.RecordObject(tTarget, "UICanvas : VR Scale Change"); // アンドウバッファに登録 tTarget.vrScale = tVrScale; EditorUtility.SetDirty(tTarget); } EditorGUILayout.Separator(); // 少し区切りスペース GUILayout.BeginHorizontal(); // 横並び { bool tIsOverlay = EditorGUILayout.Toggle(tTarget.isOverlay, GUILayout.Width(16f)); if (tIsOverlay != tTarget.isOverlay) { Undo.RecordObject(tTarget, "UICanvas : Overlay Change"); // アンドウバッファに登録 tTarget.isOverlay = tIsOverlay; EditorUtility.SetDirty(tTarget); } GUILayout.Label("Overlay"); } GUILayout.EndHorizontal(); // 横並び終了 EditorGUILayout.Separator(); // 少し区切りスペース GUILayout.BeginHorizontal(); // 横並び { bool tIsCanvasGroup = EditorGUILayout.Toggle(tTarget.isCanvasGroup, GUILayout.Width(16f)); if (tIsCanvasGroup != tTarget.isCanvasGroup) { Undo.RecordObject(tTarget, "UICanvas : Canvas Group Change"); // アンドウバッファに登録 tTarget.isCanvasGroup = tIsCanvasGroup; EditorUtility.SetDirty(tTarget); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } GUILayout.Label("Canvas Group"); } GUILayout.EndHorizontal(); // 横並び終了 if (tTarget.isCanvasGroup == true) { EditorGUIUtility.labelWidth = 60f; EditorGUIUtility.fieldWidth = 40f; // スライダーでアルファをコントロール出来るようにする float tAlpha = EditorGUILayout.Slider("Alpha", tTarget._canvasGroup.alpha, 0.0f, 1.0f); if (tAlpha != tTarget._canvasGroup.alpha) { Undo.RecordObject(tTarget, "UIView : Alpha Change"); // アンドウバッファに登録 tTarget._canvasGroup.alpha = tAlpha; EditorUtility.SetDirty(tTarget); } EditorGUIUtility.labelWidth = 116f; EditorGUIUtility.fieldWidth = 40f; // スライダーでアルファをコントロール出来るようにする float tDisableRaycastUnderAlpha = EditorGUILayout.Slider("Disable Raycast Under Alpha", tTarget.disableRaycastUnderAlpha, 0.0f, 1.0f); if (tDisableRaycastUnderAlpha != tTarget.disableRaycastUnderAlpha) { Undo.RecordObject(tTarget, "UIView : Disable Raycast Under Alpha Change"); // アンドウバッファに登録 tTarget.disableRaycastUnderAlpha = tDisableRaycastUnderAlpha; EditorUtility.SetDirty(tTarget); } } }