//-------------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { Text tText = _text; if (tText == null) { tText = gameObject.AddComponent <Text>(); } if (tText == null) { // 異常 return; } //---------------------------- Color tDefaultTextColor = Color.white; Font tDefaultFont = null; int tDefaultFontSize = 0; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tDefaultTextColor = tDS.textColor; tDefaultFont = tDS.font; tDefaultFontSize = tDS.fontSize; } } #endif tText.color = tDefaultTextColor; if (tDefaultFont == null) { tText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; } else { tText.font = tDefaultFont; } if (tDefaultFontSize <= 0) { tText.fontSize = 32; } else { tText.fontSize = tDefaultFontSize; } tText.alignment = TextAnchor.MiddleLeft; tText.horizontalOverflow = HorizontalWrapMode.Overflow; tText.verticalOverflow = VerticalWrapMode.Overflow; ResetRectTransform(); //---------------------------------- if (isCanvasOverlay == true) { tText.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } tText.raycastTarget = false; }
//----------------------------------------------------- /// <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 ) ; }
//----------------------------------------------------------- //-------------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { TextMeshProUGUI tTextMesh = _textMesh; if (tTextMesh == null) { tTextMesh = gameObject.AddComponent <TextMeshProUGUI>(); } if (tTextMesh == null) { // 異常 return; } //---------------------------- Color tDefaultTextColor = Color.white; TMP_FontAsset tDefaultFontAsset = null; Material tDefaultFontMaterial = null; int tDefaultFontSize = 0; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tDefaultTextColor = tDS.textColor; tDefaultFontAsset = tDS.fontAsset; tDefaultFontMaterial = tDS.fontMaterial; tDefaultFontSize = tDS.fontSize; } } #endif tTextMesh.color = tDefaultTextColor; if (tDefaultFontAsset == null) { tTextMesh.font = Resources.Load <TMP_FontAsset>("Fonts & Materials/LiberationSans SDF"); } else { tTextMesh.font = tDefaultFontAsset; } if (tDefaultFontMaterial != null) { tTextMesh.fontMaterial = tDefaultFontMaterial; } if (tDefaultFontSize <= 0) { tTextMesh.fontSize = 32; } else { tTextMesh.fontSize = tDefaultFontSize; } tTextMesh.alignment = TextAlignmentOptions.TopLeft; tTextMesh.enableWordWrapping = false; tTextMesh.overflowMode = TextOverflowModes.Overflow; ResetRectTransform(); //---------------------------------- tTextMesh.raycastTarget = false; }
//----------------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { Button tButton = _button; if (tButton == null) { tButton = gameObject.AddComponent <Button>(); } if (tButton == null) { // 異常 return; } Image tImage = _image; //--------------------------------- Vector2 tSize = GetCanvasSize(); if (tSize.x > 0 && tSize.y > 0) { SetSize(tSize.y * 0.25f, tSize.y * 0.075f); } ColorBlock tColorBlock = tButton.colors; tColorBlock.fadeDuration = 0.2f; tButton.colors = tColorBlock; // Image Sprite tDefaultSprite = null; Color tDefaultColor = tButton.colors.disabledColor; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tDefaultSprite = tDS.buttonFrame; tDefaultColor = tDS.buttonDisabledColor; } } #endif if (tDefaultSprite == null) { tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultButton"); } else { tImage.sprite = tDefaultSprite; } ColorBlock tCB = tButton.colors; tCB.disabledColor = tDefaultColor; tButton.colors = tCB; tImage.color = Color.white; tImage.type = Image.Type.Sliced; //---------------------------------- if (isCanvasOverlay == true) { tImage.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } //---------------------------------- // トランジションを追加 isTransition = true; // イベントトリガーは不要 // isEventTrigger = false ; ResetRectTransform(); }
/// <summary> /// ラベルを追加する /// </summary> /// <param name="tText">ラベルの文字列</param> /// <param name="tColor">ラベルのカラー</param> /// <returns>UIText のインスタンス</returns> public UITextMesh AddLabelMesh(string tText, uint tColor = 0xFFFFFFFF, int tFontSize = 0) { if (labelMesh == null) { labelMesh = AddView <UITextMesh>(); } UITextMesh tLabel = labelMesh; //---------------------------------- if (tFontSize <= 0) { tFontSize = ( int )(size.y * 0.6f); } tLabel.alignment = TMPro.TextAlignmentOptions.Center; tLabel.text = tText; // Font tDefaultFont = null ; int tDefaultFontSize = 0; Color tDefaultColor = ARGB(tColor); bool tDefaultShadow = false; bool tDefaultOutline = true; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { // tDefaultFont = tDS.font ; tDefaultFontSize = tDS.buttonLabelFontSize; tDefaultColor = tDS.buttonLabelColor; tDefaultShadow = tDS.buttonLabelShadow; tDefaultOutline = tDS.buttonLabelOutline; } } #endif // TextMeshPro ではフォントは設定できない // if( tDefaultFont == null ) // { // tLabel.font = Resources.GetBuiltinResource( typeof( Font ), "Arial.ttf" ) as Font ; // } // else // { // tLabel.font = tDefaultFont ; // } if (tDefaultFontSize == 0) { tLabel.fontSize = tFontSize; } else { tLabel.fontSize = tDefaultFontSize; } tLabel.color = tDefaultColor; tLabel.isShadow = tDefaultShadow; tLabel.isOutline = tDefaultOutline; return(tLabel); }
/// <summary> /// ラベルを追加する /// </summary> /// <param name="tText">ラベルの文字列</param> /// <param name="tColor">ラベルのカラー</param> /// <returns>UIText のインスタンス</returns> public UIRichText AddRichLabel(string tText, uint tColor = 0xFFFFFFFF, int tFontSize = 0) { if (richLabel == null) { richLabel = AddView <UIRichText>(); } UIRichText tLabel = richLabel; //---------------------------------- if (tFontSize <= 0) { tFontSize = ( int )(size.y * 0.6f); } tLabel.alignment = TextAnchor.MiddleCenter; tLabel.text = tText; Font tDefaultFont = null; int tDefaultFontSize = 0; Color tDefaultColor = ARGB(tColor); bool tDefaultShadow = false; bool tDefaultOutline = true; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tDefaultFont = tDS.font; tDefaultFontSize = tDS.buttonLabelFontSize; tDefaultColor = tDS.buttonLabelColor; tDefaultShadow = tDS.buttonLabelShadow; tDefaultOutline = tDS.buttonLabelOutline; } } #endif if (tDefaultFont == null) { tLabel.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; } else { tLabel.font = tDefaultFont; } if (tDefaultFontSize == 0) { tLabel.fontSize = tFontSize; } else { tLabel.fontSize = tDefaultFontSize; } tLabel.color = tDefaultColor; tLabel.isShadow = tDefaultShadow; tLabel.isOutline = tDefaultOutline; //---------------------------------- if (isCanvasOverlay == true) { tLabel.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } return(tLabel); }
//------------------------------------------------------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { InputFieldPlus tInputField = _inputField; if (tInputField == null) { tInputField = gameObject.AddComponent <InputFieldPlus>(); } if (tInputField == null) { // 異常 return; } Image tImage = _image; if (tImage != null) { tInputField.targetGraphic = tImage; } //------------------------------- bool tIsMultiLine = false; if (string.IsNullOrEmpty(tOption) == false && tOption.ToLower() == "multiline") { // マルチ tIsMultiLine = true; } Vector2 tSize = GetCanvasSize(); int tFontSize = 16; if (tSize.x > 0 && tSize.y > 0) { if (tIsMultiLine == false) { // シングル SetSize(tSize.y * 0.5f, tSize.y * 0.1f); } else { // マルチ SetSize(tSize.y * 0.5f, tSize.y * 0.5f); } tFontSize = ( int )(tSize.y * 0.1f * 0.6f); } // Image tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame"); tImage.type = Image.Type.Sliced; if (isCanvasOverlay == true) { tImage.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } ResetRectTransform(); // Text UIText tTextComponent = AddView <UIText>("Text", "SIMPLE"); tTextComponent.isContentSizeFitter = false; tTextComponent.fontSize = tFontSize; tTextComponent.supportRichText = false; tTextComponent.color = new Color32(50, 50, 50, 255); tTextComponent.SetAnchorToStretch(); tTextComponent.SetMargin(12, 12, 12, 12); // tText.position = new Vector2( 0, -2 ) ; // tText.SetSize( -24, -28 ) ; // tText.resizeTextForBestFit = true ; tInputField.textComponent = tTextComponent._text; if (tIsMultiLine == false) { tTextComponent.alignment = TextAnchor.MiddleLeft; } else { tTextComponent.alignment = TextAnchor.UpperLeft; } if (isCanvasOverlay == true) { tTextComponent.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } // TextColorModifier tTextComponent.AddComponent <TextColorModifier>(); // Placeholder UIText tPlaceholder = AddView <UIText>("Placeholder", "SIMPLE"); tPlaceholder.fontSize = tFontSize; tPlaceholder.fontStyle = FontStyle.Italic; tPlaceholder.text = "Enter text..."; tPlaceholder.color = new Color32(50, 50, 50, 128); tPlaceholder.SetAnchorToStretch(); tPlaceholder.SetMargin(12, 12, 12, 12); // tPlaceholder.position = new Vector2( 0, -2 ) ; // tPlaceholder.SetSize( -24, -28 ) ; // tPlaceholder.resizeTextForBestFit = true ; tInputField.placeholder = tPlaceholder._text; if (tIsMultiLine == false) { tPlaceholder.alignment = TextAnchor.MiddleLeft; } else { tPlaceholder.alignment = TextAnchor.UpperLeft; } if (isCanvasOverlay == true) { tPlaceholder.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } if (tIsMultiLine == true) { // マルチラインで生成する tInputField.lineType = InputFieldPlus.LineType.MultiLineNewline; tInputField.textComponent.horizontalOverflow = HorizontalWrapMode.Wrap; } tInputField.caretWidth = 4; tInputField.customCaretColor = true; tInputField.caretColor = Color.blue; //---------------------------------------------------------- FontFilter tFontFilter = null; char tFontAlternateCode = '?'; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tFontFilter = tDS.fontFilter; tFontAlternateCode = tDS.fontAlternateCode; } } #endif if (tFontFilter == null) { } else { fontFilter = tFontFilter; } if (tFontAlternateCode == 0) { fontAlternateCode = '?'; } else { fontAlternateCode = tFontAlternateCode; } }
// レイアウトを描画する private void OnGUI() { string tPath = null; string[] tId = AssetDatabase.FindAssets("DefaultSettings"); if (tId != null) { int i, l = tId.Length; for (i = 0; i < l; i++) { tPath = AssetDatabase.GUIDToAssetPath(tId[i]); if (Directory.Exists(tPath) == true) { break; } } if (i >= l) { tPath = null; } } if (string.IsNullOrEmpty(tPath) == true) { EditorGUILayout.HelpBox("状態が異常です", MessageType.Warning); return; } tPath = tPath + "/Resources/uGUIHelper"; if (Directory.Exists(tPath) == false) { EditorGUILayout.HelpBox("保存フォルダが存在しません", MessageType.Warning); return; } DefaultSettings tDS = null; tPath = tPath + "/DefaultSettings.asset"; if (File.Exists(tPath) == false) { // ファイルが存在しない tDS = ScriptableObject.CreateInstance <DefaultSettings>(); tDS.name = "DefaultSettings"; AssetDatabase.CreateAsset(tDS, tPath); AssetDatabase.Refresh(); } else { // ファイルが存在する tDS = AssetDatabase.LoadAssetAtPath <DefaultSettings>(tPath); } Selection.activeObject = tDS; //---------------------------------------------------------- bool tDirty = false; // ボタンの下地 Sprite tButtonFrame = EditorGUILayout.ObjectField("Button", tDS.buttonFrame, typeof(Sprite), false) as Sprite; if (tButtonFrame != tDS.buttonFrame) { tDS.buttonFrame = tButtonFrame; tDirty = true; } // ボタン無効化時の色 Color c; c.r = tDS.buttonDisabledColor.r; c.g = tDS.buttonDisabledColor.g; c.b = tDS.buttonDisabledColor.b; c.a = tDS.buttonDisabledColor.a; tDS.buttonDisabledColor = EditorGUILayout.ColorField("Button Disabled Color", tDS.buttonDisabledColor); if (tDS.buttonDisabledColor.Equals(c) == false) { tDirty = true; } // ボタンラベルのフォントサイズ int tButtonLabelFontSize = EditorGUILayout.IntField("Button Label Font Size", tDS.buttonLabelFontSize); if (tButtonLabelFontSize != tDS.buttonLabelFontSize) { tDS.buttonLabelFontSize = tButtonLabelFontSize; tDirty = true; } // ボタンラベルの色 c.r = tDS.buttonLabelColor.r; c.g = tDS.buttonLabelColor.g; c.b = tDS.buttonLabelColor.b; c.a = tDS.buttonLabelColor.a; tDS.buttonLabelColor = EditorGUILayout.ColorField("Button Label Color", tDS.buttonLabelColor); if (tDS.buttonLabelColor.Equals(c) == false) { tDirty = true; } bool tButtonLabelShadow = EditorGUILayout.Toggle("Button Label Shadow", tDS.buttonLabelShadow); if (tButtonLabelShadow != tDS.buttonLabelShadow) { tDS.buttonLabelShadow = tButtonLabelShadow; tDirty = true; } bool tButtonLabelOutline = EditorGUILayout.Toggle("Button Label Outline", tDS.buttonLabelOutline); if (tButtonLabelOutline != tDS.buttonLabelOutline) { tDS.buttonLabelOutline = tButtonLabelOutline; tDirty = true; } //---------------------------------- // プログレスバーの下地 Sprite tProgressbarFrame = EditorGUILayout.ObjectField("ProgressbarFrame", tDS.progressbarFrame, typeof(Sprite), false) as Sprite; if (tProgressbarFrame != tDS.progressbarFrame) { tDS.progressbarFrame = tProgressbarFrame; tDirty = true; } // プログレスバーの前景 Sprite tProgressbarThumb = EditorGUILayout.ObjectField("ProgressbarThumb", tDS.progressbarThumb, typeof(Sprite), false) as Sprite; if (tProgressbarThumb != tDS.progressbarThumb) { tDS.progressbarThumb = tProgressbarThumb; tDirty = true; } //---------------------------------- // テキストの色 c.r = tDS.textColor.r; c.g = tDS.textColor.g; c.b = tDS.textColor.b; c.a = tDS.textColor.a; tDS.textColor = EditorGUILayout.ColorField("Text Color", tDS.textColor); if (tDS.textColor.Equals(c) == false) { tDirty = true; } // フォント Font tFont = EditorGUILayout.ObjectField("Font", tDS.font, typeof(Font), false) as Font; if (tFont != tDS.font) { tDS.font = tFont; tDirty = true; } // フォントサイズ int tFontSize = EditorGUILayout.IntField("Font Size", tDS.fontSize); if (tFontSize != tDS.fontSize) { tDS.fontSize = tFontSize; tDirty = true; } //---------------------------------- // インプットフィールド関係 FontFilter tFontFilter = EditorGUILayout.ObjectField("Font Filter", tDS.fontFilter, typeof(FontFilter), false) as FontFilter; if (tFontFilter != tDS.fontFilter) { tDS.fontFilter = tFontFilter; tDirty = true; } string tFontAlternateCodeOld = "" + tDS.fontAlternateCode; string tFontAlternateCodeNew = EditorGUILayout.TextField("Font Alternate Code", tFontAlternateCodeOld); if (string.IsNullOrEmpty(tFontAlternateCodeNew) == false && (tFontAlternateCodeNew[0] != tFontAlternateCodeOld[0])) { tDS.fontAlternateCode = tFontAlternateCodeNew[0]; tDirty = true; } //---------------------------------- // 更新判定 if (tDirty == true) { EditorUtility.SetDirty(tDS); // 更新実行 // AssetDatabase.Refresh() ; } }