public static void AddTextMesh() { GameObject tGameObject = Selection.activeGameObject; if (tGameObject == null) { return; } if (WillLosePrefab(tGameObject) == false) { return; } Undo.RecordObject(tGameObject, "Add a child UI TextMesh"); // アンドウバッファに登録 GameObject tChild = new GameObject(GetName <UITextMesh>(), typeof(RectTransform)); Transform tTransform = tChild.transform; tTransform.SetParent(tGameObject.transform, false); tTransform.localPosition = Vector3.zero; tTransform.localRotation = Quaternion.identity; tTransform.localScale = Vector3.one; UITextMesh tText = tChild.AddComponent <UITextMesh>(); tText.SetDefault(); tText.text = "TextMesh"; Selection.activeGameObject = tChild; UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); }
override protected void DrawInspectorGUI() { UITextMesh tTarget = target as UITextMesh; EditorGUILayout.Separator(); // 少し区切りスペース //------------------------------------------------------------------- EditorGUILayout.Separator(); // 少し区切りスペース bool tAutoSizeFitting = EditorGUILayout.Toggle("Auto Size Fitting", tTarget.autoSizeFitting); if (tAutoSizeFitting != tTarget.autoSizeFitting) { Undo.RecordObject(tTarget, "UITextMesh : Auto Size Fitting Change"); // アンドウバッファに登録 tTarget.autoSizeFitting = tAutoSizeFitting; EditorUtility.SetDirty(tTarget); } //------------------------------------------------------------------- EditorGUILayout.Separator(); // 少し区切りスペース bool tIsCustomized = EditorGUILayout.Toggle("Customize", tTarget.isCustomized); if (tIsCustomized != tTarget.isCustomized) { Undo.RecordObject(tTarget, "UITextMesh : Customize Change"); // アンドウバッファに登録 tTarget.isCustomized = tIsCustomized; EditorUtility.SetDirty(tTarget); } if (tTarget.isCustomized == true) { Color tOutlineColor_Old = CloneColor(tTarget.outlineColor); Color tOutlineColor_New = EditorGUILayout.ColorField("Outline Color", tOutlineColor_Old); if (CheckColor(tOutlineColor_Old, tOutlineColor_New) == false) { Undo.RecordObject(tTarget, "UITextMesh : Outline Color Change"); // アンドウバッファに登録 tTarget.outlineColor = tOutlineColor_New; EditorUtility.SetDirty(tTarget); } } bool tRaycastTarget = EditorGUILayout.Toggle("Raycast Target", tTarget.raycastTarget); if (tRaycastTarget != tTarget.raycastTarget) { Undo.RecordObject(tTarget, "UITextMesh : RaycastTarget Change"); // アンドウバッファに登録 tTarget.raycastTarget = tRaycastTarget; EditorUtility.SetDirty(tTarget); } //------------------------------------------------------------------- }
/// <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); }
override protected void DrawInspectorGUI() { UIButton tTarget = target as UIButton; EditorGUILayout.Separator(); // 少し区切りスペース //------------------------------------------------------------------- // アトラススプライトの表示 DrawAtlas(tTarget); // マテリアル選択 DrawMaterial(tTarget); //------------------------------------------------------------------- EditorGUILayout.Separator(); // 少し区切りスペース UIText tLabel = EditorGUILayout.ObjectField("Label", tTarget.label, typeof(UIText), true) as UIText; if (tLabel != tTarget.label) { Undo.RecordObject(tTarget, "UIButton : Label Change"); // アンドウバッファに登録 tTarget.label = tLabel; EditorUtility.SetDirty(tTarget); } UIRichText tRichLabel = EditorGUILayout.ObjectField("RichLabel", tTarget.richLabel, typeof(UIRichText), true) as UIRichText; if (tRichLabel != tTarget.richLabel) { Undo.RecordObject(tTarget, "UIButton : Rich Label Change"); // アンドウバッファに登録 tTarget.richLabel = tRichLabel; EditorUtility.SetDirty(tTarget); } //#if TextMeshPro UITextMesh tLabelMesh = EditorGUILayout.ObjectField("LabelMesh", tTarget.labelMesh, typeof(UITextMesh), true) as UITextMesh; if (tLabelMesh != tTarget.labelMesh) { Undo.RecordObject(tTarget, "UIButton : Label Mesh Change"); // アンドウバッファに登録 tTarget.labelMesh = tLabelMesh; EditorUtility.SetDirty(tTarget); } //#endif UIImage tDisableMask = EditorGUILayout.ObjectField("DisableMask", tTarget.disableMask, typeof(UIImage), true) as UIImage; if (tDisableMask != tTarget.disableMask) { Undo.RecordObject(tTarget, "UIButton : Disable Mask Change"); // アンドウバッファに登録 tTarget.disableMask = tDisableMask; EditorUtility.SetDirty(tTarget); } bool tClickTransitionEnabled = EditorGUILayout.Toggle("Click Transition Enabled", tTarget.clickTransitionEnabled); if (tClickTransitionEnabled != tTarget.clickTransitionEnabled) { Undo.RecordObject(tTarget, "UIButton : Click Transition Enabled Change"); // アンドウバッファに登録 tTarget.clickTransitionEnabled = tClickTransitionEnabled; EditorUtility.SetDirty(tTarget); } bool tWaitForTransition = EditorGUILayout.Toggle("Wait For Transition", tTarget.waitForTransition); if (tWaitForTransition != tTarget.waitForTransition) { Undo.RecordObject(tTarget, "UIButton : Wait For Transition Change"); // アンドウバッファに登録 tTarget.waitForTransition = tWaitForTransition; EditorUtility.SetDirty(tTarget); } bool tColorTransmission = EditorGUILayout.Toggle("Color Transmission", tTarget.colorTransmission); if (tColorTransmission != tTarget.colorTransmission) { Undo.RecordObject(tTarget, "UIButton : Color Transmission Change"); // アンドウバッファに登録 tTarget.colorTransmission = tColorTransmission; EditorUtility.SetDirty(tTarget); } EditorGUILayout.Separator(); // 少し区切りスペース bool tSetPivotToCenter = EditorGUILayout.Toggle("Set Pivot To Center", tTarget.setPivotToCenter); if (tSetPivotToCenter != tTarget.setPivotToCenter) { Undo.RecordObject(tTarget, "UIButton : Set Pivot To Center Change"); // アンドウバッファに登録 tTarget.setPivotToCenter = tSetPivotToCenter; EditorUtility.SetDirty(tTarget); } }