using TMPro; using UnityEditor; using UnityEngine; using UnityEngine.UI; using UnityEditor.Presets; using UnityEngine.EventSystems; using UnityEditor.SceneManagement; namespace RTLTMPro { public class ContextMenu : Editor { private const string kUILayerName = "UI"; private const string kStandardSpritePath = "UI/Skin/UISprite.psd"; private const string kBackgroundSpritePath = "UI/Skin/Background.psd"; private const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd"; private const string kKnobPath = "UI/Skin/Knob.psd"; private const string kCheckmarkPath = "UI/Skin/Checkmark.psd"; private const string kDropdownArrowPath = "UI/Skin/DropdownArrow.psd"; private const string kMaskPath = "UI/Skin/UIMask.psd"; private static RTLDefaultControls.Resources s_StandardResources; /// /// Create a TextMeshPro object that works with the CanvasRenderer /// /// [MenuItem("GameObject/UI/Text - RTLTMP", false, 2001)] private static void CreateTextMeshProGuiObjectPerform(MenuCommand command) { // Check if there is a Canvas in the scene var canvas = FindObjectOfType(); if (canvas == null) { // Create new Canvas since none exists in the scene. var canvasObject = new GameObject("Canvas"); canvas = canvasObject.AddComponent(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; // Add a Graphic Raycaster Component as well canvas.gameObject.AddComponent(); canvas.gameObject.AddComponent(); Undo.RegisterCreatedObjectUndo(canvasObject, "Create " + canvasObject.name); } // Create the RTLTextMeshPro Object var go = new GameObject("Text - RTLTMP"); var goRectTransform = go.AddComponent(); Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); // Check if object is being create with left or right click var contextObject = command.context as GameObject; if (contextObject == null) { //goRectTransform.sizeDelta = new Vector2(200f, 50f); GameObjectUtility.SetParentAndAlign(go, canvas.gameObject); var textMeshPro = go.AddComponent(); textMeshPro.text = ""; textMeshPro.alignment = TextAlignmentOptions.TopRight; } else { if (contextObject.GetComponent