protected new void OnRectTransformDimensionsChange() { base.OnRectTransformDimensionsChange(); if (m_SizeCheckRequired) { int maxWidth = m_RefMaximumSize.x; int maxHeight = m_RefMaximumSize.y; var layoutElement = m_MessagesLabel.GetComponent <LayoutElement>(); if (maxWidth > 0 && (transform as RectTransform).sizeDelta.x > maxWidth) { layoutElement.preferredWidth = maxWidth; } else { layoutElement.preferredWidth = -1; } if (maxHeight > 0 && (transform as RectTransform).sizeDelta.y > maxHeight) { layoutElement.preferredHeight = maxHeight; } else { layoutElement.preferredHeight = -1; } } }
private void SpawnPercentText(int count) { GameObject textInstance = Instantiate <GameObject>(percentPrefab); RectTransform textRectTransform = textInstance.GetComponent <RectTransform>(); textRectTransform.SetParent(canvasTransform, false); textRectTransform.anchoredPosition = Services?.ViewService.Utils.WorldPosToCanvasPos(Camera.main, canvas, playerTransform.position) ?? Vector2.zero; TMPro.TextMeshProUGUI txt = textRectTransform.GetComponent <TMPro.TextMeshProUGUI>(); txt.text = $"+{count}%"; FloatAnimator floatAnimator = txt.GetComponent <FloatAnimator>(); Vector3Animator vec3Animator = txt.GetComponent <Vector3Animator>(); FloatAnimationData alphaAnimData = new FloatAnimationData { StartValue = 1, EndValue = 0, Duration = 0.4f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = textRectTransform.gameObject, OnStart = (a, o) => { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, a); }, OnUpdate = (a, t, o) => txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, a), OnEnd = (a, o) => { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, a); Destroy(textRectTransform.gameObject); } }; Vector3AnimationData scaleAnimData = new Vector3AnimationData { StartValue = Vector3.one, EndValue = 1.4f * Vector3.one, Duration = 0.3f, AnimationMode = BosAnimationMode.Single, EaseType = EaseType.EaseInOutQuad, Target = textRectTransform.gameObject, OnStart = (s, o) => textRectTransform.localScale = s, OnUpdate = (s, t, o) => textRectTransform.localScale = s, OnEnd = (s, o) => { textRectTransform.localScale = s; floatAnimator.StartAnimation(alphaAnimData); } }; vec3Animator.StartAnimation(scaleAnimData); }
void Awake() { defaultScoreCol = scoreText.color; displayedScoreCol = unsatisfiedScoreCol; scoreIcon.enabled = false; scoreRT = scoreText.GetComponent <RectTransform>(); }
void Start() { Debug.AssertFormat(ShortcutText != null, "ButtonWithShortcut behavior is missing ShortcutText reference."); if (ShortcutDisplayedText.Length > 0) { ShortcutText.text = ShortcutDisplayedText; } else { ShortcutText.text = Shortcut.ToString(); } ShortcutTextTransform = ShortcutText.GetComponent <RectTransform>(); Debug.AssertFormat(ShortcutTextTransform != null, "ButtonWithShortcut behavior is missing RectTransform."); NormalShortcutAnchoredPosition = ShortcutTextTransform.anchoredPosition; if (Shortcut == KeyCode.None) { ShortcutText.gameObject.SetActive(false); } Button = GetComponent <Button>(); Debug.AssertFormat(Button != null, "ButtonWithShortcut behavior should be coupled with Button behavior on the same game object."); Button.PressOffsetApplied += Button_PressOffsetApplied; Button.PressOffsetRemoved += Button_PressOffsetRemoved; UnityButton = GetComponent <UnityEngine.UI.Button>(); Debug.AssertFormat(UnityButton != null, "ButtonWithShortcut behavior should be coupled with Unity's Button behavior on the same game object."); }
/// <summary> /// Sets the subtitle. /// </summary> /// <param name='subtitle'> /// Subtitle. /// </param> public override void SetSubtitle(Subtitle subtitle) { if ((subtitle != null) && !string.IsNullOrEmpty(subtitle.formattedText.text)) { if (portraitImage != null) { portraitImage.sprite = UITools.CreateSprite(subtitle.GetSpeakerPortrait()); } if (portraitName != null) { portraitName.text = subtitle.speakerInfo.Name; TextMeshProSendTextChangeMessage(portraitName); } if (line != null) { var typewriterEffect = line.GetComponent <TextMeshProTypewriterEffect>(); if (typewriterEffect != null && typewriterEffect.enabled) { typewriterEffect.Stop(); } SetFormattedText(line, subtitle.formattedText); if (typewriterEffect != null && typewriterEffect.enabled) { typewriterEffect.OnEnable(); } } Show(); if (alwaysVisible && line != null) { var typewriterEffect = line.GetComponent <TextMeshProTypewriterEffect>(); if (typewriterEffect != null) { typewriterEffect.OnEnable(); } } } else { if ((line != null) && (subtitle != null)) { SetFormattedText(line, subtitle.formattedText); } Hide(); } }
private static void CreateModButton(HeaderNavigationController self, out MPButton button, out TMPro.TextMeshProUGUI text, out GameObject root) { button = Object.Instantiate(self.headers[0].headerButton, self.headers[0].headerButton.transform.parent); //copy button text = Object.Instantiate(self.headers[0].tmpHeaderText, button.transform); //copy textmesh field text.name = "Text, Custom"; //button internal name text.GetComponent <LanguageTextMeshController>().token = "Mods"; //button text root = Object.Instantiate(self.headers[0].headerRoot, self.headers[0].headerRoot.transform.parent); //copy headerRoot }
public void setPosition(Vector2 position, Vector2 offset) { Vector2 relativePos = new Vector2( ((position.x * canvasRect.sizeDelta.x) - (canvasRect.sizeDelta.x * 0.5f)), ((position.y * canvasRect.sizeDelta.y) - (canvasRect.sizeDelta.y * 0.5f))); relativePos += offset; textObject.GetComponent <RectTransform>().anchoredPosition = relativePos; }
public void SetMessage(string message, int maxWidth = -1, int maxHeight = -1) { _messagesLabel.SetText(message); var preferedSize = _messagesLabel.GetPreferredValues(); var layoutElement = _messagesLabel.GetComponent <LayoutElement>(); layoutElement.preferredWidth = Mathf.Min(maxWidth, preferedSize.x); layoutElement.preferredHeight = Mathf.Min(maxHeight, preferedSize.y); }
void Start() { Debug.AssertFormat(UnityButton != null, "Button behavior is missing UnityButton reference."); Interactible = UnityButton.interactable; Debug.AssertFormat(ButtonText != null, "Button behavior is missing ButtonText reference."); ButtonTextTransform = ButtonText.GetComponent <RectTransform>(); Debug.AssertFormat(ButtonTextTransform != null, "Button behavior is missing RectTransform on ButtonText reference."); NormalButtonTextAnchoredPosition = ButtonTextTransform.anchoredPosition; PressedButtonTextAnchoredPosition = new Vector2(NormalButtonTextAnchoredPosition.x, NormalButtonTextAnchoredPosition.y - PressedOffset); }