51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CopyTextButton : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text textToCopy;
|
|
[SerializeField] private TMP_Text labelText;
|
|
[SerializeField] private TMP_Text actionNameText;
|
|
[SerializeField] Button button;
|
|
public void Awake()
|
|
{
|
|
button.onClick.AddListener(CopyText);
|
|
if (actionNameText != null)
|
|
{
|
|
var actionButton = actionNameText.GetComponent<Button>();
|
|
if (actionButton == null)
|
|
{
|
|
actionButton = actionNameText.gameObject.AddComponent<Button>();
|
|
actionButton.transition = Selectable.Transition.None;
|
|
actionButton.targetGraphic = actionNameText;
|
|
}
|
|
actionButton.onClick.AddListener(CopyActionName);
|
|
}
|
|
}
|
|
|
|
public void CopyText()
|
|
{
|
|
GUIUtility.systemCopyBuffer = textToCopy.text;
|
|
}
|
|
|
|
public void CopyActionName()
|
|
{
|
|
var text = actionNameText.text;
|
|
if (string.IsNullOrEmpty(text) || text == "—")
|
|
return;
|
|
GUIUtility.systemCopyBuffer = text;
|
|
}
|
|
public void SetText(string labeltext, string text, bool? inAddressables = null, string actionName = null)
|
|
{
|
|
labelText.text = labeltext;
|
|
textToCopy.text = text;
|
|
if (actionNameText != null)
|
|
actionNameText.text = actionName ?? "—";
|
|
if (inAddressables == null)
|
|
labelText.color = Color.white;
|
|
else
|
|
labelText.color = inAddressables.Value ? Color.green : Color.red;
|
|
}
|
|
|
|
} |