2470 lines
78 KiB
C#
2470 lines
78 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text.RegularExpressions;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.InputSystem;
|
||
using UnityEngine.InputSystem.EnhancedTouch;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TankAndHealerStudioAssets
|
||
{
|
||
[ExecuteAlways]
|
||
[RequireComponent(typeof(CanvasGroup))]
|
||
public class UltimateChatBox : MonoBehaviour
|
||
{
|
||
[Serializable]
|
||
public class ChatInformation
|
||
{
|
||
public UltimateChatBox chatBox;
|
||
|
||
public TextMeshProUGUI chatText;
|
||
|
||
public Rect usernameRect;
|
||
|
||
public float contentSpace;
|
||
|
||
public Vector2 anchoredPosition = Vector2.zero;
|
||
|
||
public float usernameWidth;
|
||
|
||
public float lineHeight;
|
||
|
||
public int lineCount;
|
||
|
||
public ChatStyle chatBoxStyle;
|
||
|
||
public bool IsVisible { get; private set; }
|
||
|
||
public string Username { get; set; }
|
||
|
||
public string DisplayUsername { get; set; }
|
||
|
||
public string Message { get; set; }
|
||
|
||
public string DisplayMessage { get; set; }
|
||
|
||
public void UpdateText()
|
||
{
|
||
if (!(chatText == null) && chatBoxStyle != null)
|
||
{
|
||
chatText.text = chatBoxStyle.FormatMessage(DisplayUsername, DisplayMessage);
|
||
}
|
||
}
|
||
|
||
public void UpdateVisibility()
|
||
{
|
||
if (chatBox.chatBoxVisiblityRect.Contains(anchoredPosition * -1f))
|
||
{
|
||
IsVisible = true;
|
||
}
|
||
else if (chatBox.chatBoxVisiblityRect.Contains(anchoredPosition * -1f + new Vector2(0f, contentSpace - 0.01f)))
|
||
{
|
||
IsVisible = true;
|
||
}
|
||
else if (contentSpace > chatBox.visibleChatBoundingBox.sizeDelta.y)
|
||
{
|
||
float num = chatBox.visibleChatBoundingBox.sizeDelta.y / contentSpace;
|
||
for (float num2 = 0f; num2 < 1f; num2 += num)
|
||
{
|
||
if (chatBox.chatBoxVisiblityRect.Contains(anchoredPosition * -1f + new Vector2(0f, contentSpace * num2)))
|
||
{
|
||
IsVisible = true;
|
||
return;
|
||
}
|
||
}
|
||
IsVisible = false;
|
||
}
|
||
else
|
||
{
|
||
IsVisible = false;
|
||
}
|
||
}
|
||
|
||
public void RemoveChat()
|
||
{
|
||
if (chatText != null)
|
||
{
|
||
chatBox.SendTextToPool(chatText);
|
||
}
|
||
chatBox.ChatInformations.Remove(this);
|
||
chatBox.isDirty = true;
|
||
}
|
||
}
|
||
|
||
[Serializable]
|
||
public class ChatStyle
|
||
{
|
||
public bool usernameBold;
|
||
|
||
public bool usernameItalic;
|
||
|
||
public bool usernameUnderlined;
|
||
|
||
public Color usernameColor = Color.clear;
|
||
|
||
public bool disableInteraction;
|
||
|
||
public bool noUsernameFollowupText;
|
||
|
||
public bool messageBold;
|
||
|
||
public bool messageItalic;
|
||
|
||
public bool messageUnderlined;
|
||
|
||
public Color messageColor = Color.clear;
|
||
|
||
public string FormatMessage(string username, string message)
|
||
{
|
||
if (username != string.Empty)
|
||
{
|
||
if (usernameBold)
|
||
{
|
||
username = "<b>" + username + "</b>";
|
||
}
|
||
if (usernameItalic)
|
||
{
|
||
username = "<i>" + username + "</i>";
|
||
}
|
||
if (usernameUnderlined)
|
||
{
|
||
username = "<u>" + username + "</u>";
|
||
}
|
||
if (usernameColor != Color.clear)
|
||
{
|
||
username = "<color=#" + ColorUtility.ToHtmlStringRGB(usernameColor) + ">" + username + "</color>";
|
||
}
|
||
}
|
||
if (messageBold)
|
||
{
|
||
message = "<b>" + message + "</b>";
|
||
}
|
||
if (messageItalic)
|
||
{
|
||
message = "<i>" + message + "</i>";
|
||
}
|
||
if (messageUnderlined)
|
||
{
|
||
message = "<u>" + message + "</u>";
|
||
}
|
||
if (messageColor != Color.clear)
|
||
{
|
||
message = "<color=#" + ColorUtility.ToHtmlStringRGB(messageColor) + ">" + message + "</color>";
|
||
}
|
||
return username + message;
|
||
}
|
||
|
||
public string FormatUsernameOnly(string username)
|
||
{
|
||
if (username.Contains("#"))
|
||
{
|
||
username = username.Split('#')[0];
|
||
}
|
||
if (usernameBold)
|
||
{
|
||
username = "<b>" + username + "</b>";
|
||
}
|
||
if (usernameItalic)
|
||
{
|
||
username = "<i>" + username + "</i>";
|
||
}
|
||
if (usernameUnderlined)
|
||
{
|
||
username = "<u>" + username + "</u>";
|
||
}
|
||
return username;
|
||
}
|
||
}
|
||
|
||
private List<TextMeshProUGUI> UnusedTextPool = new List<TextMeshProUGUI>();
|
||
|
||
private RectTransform parentCanvasRectTrans;
|
||
|
||
private Vector3 parentCanvasScale = Vector3.one;
|
||
|
||
private Vector2 parentCanvasSize = Vector2.zero;
|
||
|
||
private float totalContentSpace;
|
||
|
||
private bool isDraggingScrollHandle;
|
||
|
||
private Vector3 previousInputPosition = Vector2.zero;
|
||
|
||
private float scrollValue;
|
||
|
||
private int inputFieldStringPosition = -1;
|
||
|
||
private bool isDirty;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private CanvasGroup chatBoxCanvasGroup;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the chat box calculate any touch input on it?")]
|
||
private bool allowTouchInput;
|
||
|
||
private bool isDraggingWithTouch;
|
||
|
||
private int currentTouchId = -1;
|
||
|
||
private bool customInputRecieved;
|
||
|
||
private Vector2 customScreenPosition = Vector2.zero;
|
||
|
||
private bool customGetButtonDown;
|
||
|
||
private bool customGetButton;
|
||
|
||
private RectTransform baseTransform;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The ratio of the chat box.")]
|
||
private Vector2 chatBoxSizeRatio = new Vector2(1f, 0.5f);
|
||
|
||
[SerializeField]
|
||
[Tooltip("The overall size of the chat box.")]
|
||
private float chatBoxSize = 5f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The position of the chat box on the screen. These values are calculated as percentages, so they are divided by 100 and calculated off the canvas size so that it will be consistent across all screen sizes.")]
|
||
private Vector2 chatBoxPosition = new Vector2(5f, 10f);
|
||
|
||
[SerializeField]
|
||
[Tooltip("The visible bounding box for the chat in the chat box.")]
|
||
private RectTransform visibleChatBoundingBox;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The horizontal bounds for the content of the chat box.")]
|
||
private RectTransform chatContentBox;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The horizontal spacing for the left and right of the content box.")]
|
||
[Range(0f, 50f)]
|
||
private float horizontalSpacing = 2f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The vertical spacing for the top and bottom of the bounding box.")]
|
||
[Range(0f, 50f)]
|
||
private float verticalSpacing = 2f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The position of the content within the chat box.")]
|
||
private Vector2 contentPosition = Vector2.zero;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect chatBoxScreenRect;
|
||
|
||
private Rect chatBoxVisiblityRect;
|
||
|
||
private bool chatBoxPositionCustom;
|
||
|
||
private Vector2 bottomContentPosition;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The TextMeshPro GameObject to use as base settings for all the chats in the chat box.")]
|
||
private TextMeshProUGUI textObject;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The color of the text in the chat box.")]
|
||
private Color textColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The maximum number of chats in the chat box before the old ones will be filtered out.")]
|
||
private int maxTextInChatBox = 500;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Determines if the players should be able to use custom rich text in the input field or if the chat box should filter out the rich text.")]
|
||
private bool disableRichTextFromPlayers = true;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The string to add at the end of a username.")]
|
||
private string usernameFollowup = ": ";
|
||
|
||
[SerializeField]
|
||
[Tooltip("The space between each chat registered to the chat box.")]
|
||
[Range(0f, 1f)]
|
||
private float spaceBetweenChats;
|
||
|
||
[SerializeField]
|
||
[Range(0f, 0.2f)]
|
||
[Tooltip("The relative size of the font to the chat box height.")]
|
||
private float smartFontSize = 0.1f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the usernames of the chats registered by interactable?")]
|
||
private bool useInteractableUsername;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The image used in association with highlighting the username.")]
|
||
private Image interactableUsernameImage;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The color of the highlight image when the input is hovering over the username.")]
|
||
private Color interactableUsernameColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The percentage of the line height to add as a modifier to the username highlight image.")]
|
||
[Range(0f, 1f)]
|
||
private float interactableUsernameWidthModifier;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the chat box fade the alpha of the CanvasGroup when enabling/disabling the chat box?")]
|
||
private bool fadeWhenDisabled;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The speed for the chat box to fade in.")]
|
||
private float fadeInSpeed = 4f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The speed for the chat box to fade out.")]
|
||
private float fadeOutSpeed = 4f;
|
||
|
||
[SerializeField]
|
||
[Range(0f, 1f)]
|
||
[Tooltip("The alpha to apply to the chat box when it is disabled.")]
|
||
private float toggledAlpha = 0.25f;
|
||
|
||
private bool fadeIn;
|
||
|
||
private bool fadeOut;
|
||
|
||
private float fadeLerpValue;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the chat box collapse when enabling/disabling the chat box?")]
|
||
private bool collapseWhenDisabled;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The speed for the chat box to expand.")]
|
||
private float expandSpeed = 4f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The speed for the chat box to collapse.")]
|
||
private float collapseSpeed = 4f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("How many lines of chat should be visible when the chat box is in a collapsed state?")]
|
||
private int visibleLineCount = 3;
|
||
|
||
private Vector2 baseTransformSize = Vector2.zero;
|
||
|
||
private Vector2 baseTransformCollapsedSize = Vector2.zero;
|
||
|
||
private Vector2 visibleBoundingBoxSize = Vector2.zero;
|
||
|
||
private Vector2 boundingBoxCollapsedSize = Vector2.zero;
|
||
|
||
private bool expandChatBox;
|
||
|
||
private bool collapseChatBox;
|
||
|
||
private float collapseLerpValue;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should emojis be allowed in chat?")]
|
||
private bool useTextEmoji;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The emoji asset to assign to all the chats.")]
|
||
private TMP_SpriteAsset emojiAsset;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the chat box display a vertical scrollbar to help navigate chat?")]
|
||
private bool useScrollbar;
|
||
|
||
[SerializeField]
|
||
private RectTransform scrollbarBase;
|
||
|
||
[SerializeField]
|
||
private RectTransform scrollbarHandle;
|
||
|
||
[SerializeField]
|
||
private Image scrollbarHandleImage;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The default color for the scrollbar handle.")]
|
||
private Color scrollbarHandleNormalColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The color for when the input is hovering the scrollbar handle.")]
|
||
private Color scrollbarHandleHoverColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The color of the scrollbar handle when the input is active.")]
|
||
private Color scrollbarHandleActiveColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the player be able to use the scroll wheel on their mouse to navigate the chat box?")]
|
||
private bool useScrollWheel = true;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The speed that the chat box will navigate using the scroll wheel.")]
|
||
private float mouseScrollSpeed = 1f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The minimum size that the scrollbar handle will get when the chat box is filled with chats.")]
|
||
[Range(0.01f, 0.25f)]
|
||
private float scrollbarMinimumSize = 0.15f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The width of the scrollbar relative to the chat box width.")]
|
||
[Range(0.01f, 0.25f)]
|
||
private float scrollbarWidth = 0.02f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The horizontal position of the scrollbar relative to the chat box center.")]
|
||
private float scrollbarHorizontalPosition = 49f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the scrollbar only be visible when hovering input over the chat box?")]
|
||
private bool visibleOnlyOnHover;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The speed to apply for the scrollbar to toggle visually.")]
|
||
private float scrollbarToggleSpeed = 4f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The time in seconds that the input has NOT been in the chat box for the scrollbar to disable itself.")]
|
||
private float scrollbarInactiveTime = 1f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should clicking on the base of the scrollbar to navigate be disabled?")]
|
||
private bool disableBaseNavigation;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect scrollbarBaseRect;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect scrollbarHandleRect;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private CanvasGroup scrollbarCanvasGroup;
|
||
|
||
private Vector2 scrollbarHandleInputStart = Vector2.zero;
|
||
|
||
private Vector2 scrollbarBottomPosition;
|
||
|
||
private float scrollbarToggleLerpValue;
|
||
|
||
private float _inactiveTime;
|
||
|
||
private bool scrollbarToggle;
|
||
|
||
private bool scrollbarHandleHovered;
|
||
|
||
private bool scrollbarHandleActive;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Determines if you want to have navigation arrows at the top and bottom of the scrollbar to help navigate the chat box.")]
|
||
private bool useNavigationArrows;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The image component to use for the up arrow.")]
|
||
private Image navigationArrowUp;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The image component to use for the down arrow.")]
|
||
private Image navigationArrowDown;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The default color for the navigation arrows to be.")]
|
||
private Color navigationNormalColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The color to apply when the navigation arrows are hovered.")]
|
||
private Color navigationHoverColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The color to apply when the input is active on the navigation arrows.")]
|
||
private Color navigationActiveColor = Color.white;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The time in seconds before the navigation arrows will repeat the navigation when the input is held.")]
|
||
private float navigationInitialHoldDelay = 0.25f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The time in seconds between repeating navigation from holding the input on the navigation arrows.")]
|
||
private float navigationIntervalDelay = 0.1f;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect scrollbarNavigationArrowUpRect;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect scrollbarNavigationArrowDownRect;
|
||
|
||
private bool scrollbarNavigationArrowUpHovered;
|
||
|
||
private bool scrollbarNavigationArrowUpActivated;
|
||
|
||
private bool scrollbarNavigationArrowDownHovered;
|
||
|
||
private bool scrollbarNavigationArrowDownActivated;
|
||
|
||
private float navigationIntervalTime;
|
||
|
||
private float navigationInitialHoldTime;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should an input field be available for players to use?")]
|
||
private bool useInputField;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The input field component to use for the chat box.")]
|
||
private TMP_InputField inputField;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The size of the input field relative to the chat box.")]
|
||
private Vector2 inputFieldSize = new Vector2(100f, 12.5f);
|
||
|
||
[SerializeField]
|
||
[Tooltip("The position of the input field relative to the chat box.")]
|
||
private Vector2 inputFieldPosition = new Vector2(0f, -2f);
|
||
|
||
[SerializeField]
|
||
[Range(0f, 1f)]
|
||
[Tooltip("The relative size of the font to the input field height.")]
|
||
private float inputFieldSmartFontSize = 1f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The size of the input field text area relative to the input field transform.")]
|
||
private Vector2 inputFieldTextAreaSize = new Vector2(95f, 95f);
|
||
|
||
[SerializeField]
|
||
[Range(-50f, 50f)]
|
||
private float inputFieldTextHorizontalPosition;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private RectTransform inputFieldTransform;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect inputFieldRect;
|
||
|
||
private string inputFieldValue = string.Empty;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should an extra image be used inside the input field?")]
|
||
private bool useExtraImage;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The image component to use as the extra image.")]
|
||
private Image extraImage;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect extraImageRect;
|
||
|
||
[SerializeField]
|
||
[Range(0f, 100f)]
|
||
[Tooltip("The height of the input field extra image.")]
|
||
private float extraImageHeight = 100f;
|
||
|
||
[SerializeField]
|
||
[Range(0f, 100f)]
|
||
[Tooltip("The width of the input field extra image.")]
|
||
private float extraImageWidth = 10f;
|
||
|
||
[SerializeField]
|
||
[Range(-50f, 50f)]
|
||
[Tooltip("The horizontal position in relation to the input field.")]
|
||
private float extraImageHorizontalPosition = -50f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("Should the players be able to add emojis through a provided window?")]
|
||
private bool useEmojiWindow;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The image component to be used as a button to open the emoji window.")]
|
||
private Image emojiButtonImage;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The size of the button.")]
|
||
private float emojiButtonSize = 0.9f;
|
||
|
||
[SerializeField]
|
||
[Range(0f, 150f)]
|
||
[Tooltip("The horizontal position of the emoji button in relation to the left side of the input field.")]
|
||
private float emojiButtonHorizontalPosition = 99f;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The image component used as the background of the emoji window.")]
|
||
private Image emojiWindowImage;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The overall size of the emoji window.")]
|
||
private Vector2 emojiWindowSize = new Vector2(25f, 25f);
|
||
|
||
[SerializeField]
|
||
[Tooltip("The position of the emoji window in relation to the bottom right of the input field.")]
|
||
private Vector2 emojiWindowPosition = Vector2.zero;
|
||
|
||
[SerializeField]
|
||
[Tooltip("The text to display all the available emojis.")]
|
||
private TextMeshProUGUI emojiText;
|
||
|
||
[SerializeField]
|
||
[Range(0f, 0.2f)]
|
||
[Tooltip("The padding to add to the edges of the emoji window text.")]
|
||
private float emojiTextEdgePadding;
|
||
|
||
[SerializeField]
|
||
[Tooltip("How many emojis should be displayed in a row inside the window?")]
|
||
private int emojiPerRow = 5;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private List<Rect> emojiRects = new List<Rect>();
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect emojiButtonRect;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private Rect emojiWindowRect;
|
||
|
||
[SerializeField]
|
||
[HideInInspector]
|
||
private CanvasGroup emojiWindowCanvasGroup;
|
||
|
||
public List<ChatInformation> ChatInformations { get; private set; } = new List<ChatInformation>();
|
||
|
||
public List<TextMeshProUGUI> AllTextObjects { get; private set; } = new List<TextMeshProUGUI>();
|
||
|
||
public Canvas ParentCanvas { get; private set; }
|
||
|
||
public bool Interactable { get; set; } = true;
|
||
|
||
public bool IsEnabled { get; private set; }
|
||
|
||
public bool InputOnChatBox { get; private set; }
|
||
|
||
public float LineHeight { get; private set; }
|
||
|
||
public Vector3 InputPosition { get; private set; }
|
||
|
||
public bool GetButtonDown { get; private set; }
|
||
|
||
public bool GetButton { get; private set; }
|
||
|
||
public float ScrollValue
|
||
{
|
||
set
|
||
{
|
||
scrollValue = value;
|
||
}
|
||
}
|
||
|
||
public Vector2 TotalChatBoxSize { get; private set; }
|
||
|
||
public RectTransform BaseTransform
|
||
{
|
||
get
|
||
{
|
||
if (baseTransform == null)
|
||
{
|
||
baseTransform = GetComponent<RectTransform>();
|
||
}
|
||
return baseTransform;
|
||
}
|
||
}
|
||
|
||
public RectTransform VisibleChatBoundingBox
|
||
{
|
||
get
|
||
{
|
||
if (visibleChatBoundingBox == null)
|
||
{
|
||
Debug.LogError(FormatDebug("There is no bounding box assigned to this chat box", "Please exit play mode and click on the Ultimate Chat Box in your scene. This will ensure that the bounding box object is created", base.gameObject.name));
|
||
}
|
||
return visibleChatBoundingBox;
|
||
}
|
||
}
|
||
|
||
public RectTransform ChatContentBox
|
||
{
|
||
get
|
||
{
|
||
if (chatContentBox == null)
|
||
{
|
||
Debug.LogError(FormatDebug("There is no content box assigned to this chat box", "Please exit play mode and click on the Ultimate Chat Box in your scene. This will ensure that the content box object is created", base.gameObject.name));
|
||
}
|
||
return chatContentBox;
|
||
}
|
||
}
|
||
|
||
public TextMeshProUGUI TextObject => textObject;
|
||
|
||
public Color TextColor
|
||
{
|
||
get
|
||
{
|
||
return textColor;
|
||
}
|
||
set
|
||
{
|
||
textColor = value;
|
||
for (int i = 0; i < AllTextObjects.Count; i++)
|
||
{
|
||
AllTextObjects[i].color = textColor;
|
||
}
|
||
}
|
||
}
|
||
|
||
public float CalculatedFontSize
|
||
{
|
||
get
|
||
{
|
||
if (textObject == null)
|
||
{
|
||
return 0f;
|
||
}
|
||
return textObject.fontSize;
|
||
}
|
||
}
|
||
|
||
public Image InteractableUsernameImage => interactableUsernameImage;
|
||
|
||
public Color InteractableUsernameColor
|
||
{
|
||
get
|
||
{
|
||
return interactableUsernameColor;
|
||
}
|
||
set
|
||
{
|
||
interactableUsernameColor = value;
|
||
if (UsernameHighlighted && interactableUsernameImage != null)
|
||
{
|
||
interactableUsernameImage.color = interactableUsernameColor;
|
||
}
|
||
}
|
||
}
|
||
|
||
public bool UsernameHighlighted { get; private set; }
|
||
|
||
public int CurrentHoveredChatIndex { get; private set; }
|
||
|
||
public bool LeaveTextVisible
|
||
{
|
||
get
|
||
{
|
||
return visibleChatBoundingBox.GetComponent<CanvasGroup>().ignoreParentGroups;
|
||
}
|
||
set
|
||
{
|
||
visibleChatBoundingBox.GetComponent<CanvasGroup>().ignoreParentGroups = value;
|
||
}
|
||
}
|
||
|
||
public TMP_SpriteAsset EmojiAsset => emojiAsset;
|
||
|
||
public bool ScrollbarActive { get; private set; }
|
||
|
||
public TMP_InputField InputField => inputField;
|
||
|
||
public bool InputFieldEnabled { get; private set; }
|
||
|
||
public string InputFieldValue
|
||
{
|
||
get
|
||
{
|
||
return inputFieldValue;
|
||
}
|
||
set
|
||
{
|
||
inputFieldValue = value;
|
||
inputField.text = inputFieldValue;
|
||
inputField.caretPosition = inputFieldValue.Length;
|
||
}
|
||
}
|
||
|
||
public bool InputFieldContainsCommand { get; private set; }
|
||
|
||
public Sprite ExtraImageSprite
|
||
{
|
||
get
|
||
{
|
||
if (!useExtraImage || extraImage == null)
|
||
{
|
||
return null;
|
||
}
|
||
return extraImage.sprite;
|
||
}
|
||
set
|
||
{
|
||
if (useExtraImage && extraImage != null)
|
||
{
|
||
extraImage.sprite = value;
|
||
}
|
||
}
|
||
}
|
||
|
||
public Color ExtraImageColor
|
||
{
|
||
get
|
||
{
|
||
if (!useExtraImage || extraImage == null)
|
||
{
|
||
return Color.clear;
|
||
}
|
||
return extraImage.color;
|
||
}
|
||
set
|
||
{
|
||
if (useExtraImage && extraImage != null)
|
||
{
|
||
extraImage.color = value;
|
||
}
|
||
}
|
||
}
|
||
|
||
public bool EmojiWindowEnabled { get; private set; } = true;
|
||
|
||
public Sprite EmojiButtonSprite
|
||
{
|
||
get
|
||
{
|
||
if (!useEmojiWindow || emojiButtonImage == null)
|
||
{
|
||
return null;
|
||
}
|
||
return emojiButtonImage.sprite;
|
||
}
|
||
set
|
||
{
|
||
if (useEmojiWindow && emojiButtonImage != null)
|
||
{
|
||
emojiButtonImage.sprite = value;
|
||
}
|
||
}
|
||
}
|
||
|
||
public Color EmojiButtonColor
|
||
{
|
||
get
|
||
{
|
||
if (!useEmojiWindow || emojiButtonImage == null)
|
||
{
|
||
return Color.clear;
|
||
}
|
||
return emojiButtonImage.color;
|
||
}
|
||
set
|
||
{
|
||
if (useEmojiWindow && emojiButtonImage != null)
|
||
{
|
||
emojiButtonImage.color = value;
|
||
}
|
||
}
|
||
}
|
||
|
||
public event Action<ChatInformation> OnChatRegistered;
|
||
|
||
public event Action<Vector2, ChatInformation> OnUsernameHover;
|
||
|
||
public event Action<Vector2, ChatInformation> OnUsernameInteract;
|
||
|
||
public event Action OnInputFieldEnabled;
|
||
|
||
public event Action OnInputFieldDisabled;
|
||
|
||
public event Action<string> OnInputFieldUpdated;
|
||
|
||
public event Action<string> OnInputFieldSubmitted;
|
||
|
||
public event Action<string, string> OnInputFieldCommandUpdated;
|
||
|
||
public event Action<string, string> OnInputFieldCommandSubmitted;
|
||
|
||
public event Action OnExtraImageInteract;
|
||
|
||
private void Start()
|
||
{
|
||
if (!Application.isPlaying)
|
||
{
|
||
return;
|
||
}
|
||
if (useInteractableUsername && interactableUsernameImage != null)
|
||
{
|
||
interactableUsernameImage.color = Color.clear;
|
||
}
|
||
if (useScrollbar && scrollbarBase != null)
|
||
{
|
||
scrollbarCanvasGroup.alpha = 0f;
|
||
scrollbarHandleHovered = false;
|
||
}
|
||
if (textObject != null)
|
||
{
|
||
if (textObject.alignment != TextAlignmentOptions.TopLeft)
|
||
{
|
||
textObject.alignment = TextAlignmentOptions.TopLeft;
|
||
}
|
||
if (!textObject.maskable)
|
||
{
|
||
textObject.maskable = true;
|
||
}
|
||
if (textObject.raycastTarget)
|
||
{
|
||
textObject.raycastTarget = false;
|
||
}
|
||
if (textObject.textWrappingMode != TextWrappingModes.Normal)
|
||
{
|
||
textObject.textWrappingMode = TextWrappingModes.Normal;
|
||
}
|
||
if (textObject.enableAutoSizing)
|
||
{
|
||
textObject.enableAutoSizing = false;
|
||
}
|
||
if (useTextEmoji)
|
||
{
|
||
textObject.spriteAsset = emojiAsset;
|
||
for (int i = 0; i < AllTextObjects.Count; i++)
|
||
{
|
||
AllTextObjects[i].spriteAsset = emojiAsset;
|
||
}
|
||
if (useInputField)
|
||
{
|
||
inputField.textComponent.spriteAsset = emojiAsset;
|
||
if (useEmojiWindow && emojiText != null)
|
||
{
|
||
emojiText.spriteAsset = emojiAsset;
|
||
emojiText.text = "";
|
||
for (int j = 0; j < emojiAsset.spriteCharacterTable.Count; j++)
|
||
{
|
||
if (j > 0 && j % emojiPerRow == 0)
|
||
{
|
||
emojiText.text += "\n";
|
||
}
|
||
emojiText.text += $"<sprite={j}>";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
UpdatePositioning();
|
||
if (allowTouchInput)
|
||
{
|
||
EnhancedTouchSupport.Enable();
|
||
}
|
||
if (!allowTouchInput || !useInputField || !(inputField != null))
|
||
{
|
||
return;
|
||
}
|
||
inputField.onTouchScreenKeyboardStatusChanged.AddListener(delegate(TouchScreenKeyboard.Status status)
|
||
{
|
||
if (status == TouchScreenKeyboard.Status.Done)
|
||
{
|
||
DisableInputField();
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
base.enabled = false;
|
||
Debug.LogError(FormatDebug("No Text Object has been created. Disabling Ultimate Chat Box component to avoid errors.", "Go to the Text Settings section of the Ultimate Chat Box and click the Generate Text Object button.", base.gameObject.name));
|
||
}
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (!Application.isPlaying)
|
||
{
|
||
UpdatePositioning();
|
||
return;
|
||
}
|
||
if (isDirty)
|
||
{
|
||
isDirty = false;
|
||
RepositionAllChats();
|
||
}
|
||
GetButtonDown = false;
|
||
Mouse device = InputSystem.GetDevice<Mouse>();
|
||
if (device != null)
|
||
{
|
||
InputPosition = device.position.ReadValue();
|
||
GetButtonDown = device.leftButton.wasPressedThisFrame;
|
||
GetButton = device.leftButton.isPressed;
|
||
if (!device.enabled && !allowTouchInput && Touchscreen.current != null && Touchscreen.current.enabled)
|
||
{
|
||
Debug.LogWarning(FormatDebug("Mouse device is disabled by Unity", "Please disable the Simulated Touchscreen option. To do this, go to Window > Analysis > Input Debugger. In this window, disable the Simulated Touchscreen by going to Options > Simulate Touch Input From Mouse Or Pen", "NA"));
|
||
}
|
||
}
|
||
if (allowTouchInput)
|
||
{
|
||
for (int i = 0; i < UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches.Count; i++)
|
||
{
|
||
int touchId = UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches[i].touchId;
|
||
bool flag = UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches[i].phase == UnityEngine.InputSystem.TouchPhase.Began;
|
||
Vector2 screenPosition = UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches[i].screenPosition;
|
||
if (currentTouchId < 0 && flag && (chatBoxScreenRect.Contains(screenPosition) || (useEmojiWindow && (emojiButtonRect.Contains(screenPosition) || (EmojiWindowEnabled && emojiWindowRect.Contains(screenPosition))))))
|
||
{
|
||
InputPosition = screenPosition;
|
||
GetButtonDown = true;
|
||
currentTouchId = touchId;
|
||
previousInputPosition = InputPosition;
|
||
if (useScrollbar)
|
||
{
|
||
isDraggingWithTouch = true;
|
||
}
|
||
break;
|
||
}
|
||
if (touchId == currentTouchId)
|
||
{
|
||
InputPosition = screenPosition;
|
||
GetButton = true;
|
||
}
|
||
}
|
||
}
|
||
if (customInputRecieved)
|
||
{
|
||
if (allowTouchInput && isDraggingWithTouch)
|
||
{
|
||
isDraggingWithTouch = false;
|
||
}
|
||
InputPosition = customScreenPosition;
|
||
GetButtonDown = customGetButtonDown;
|
||
GetButton = customGetButton;
|
||
customInputRecieved = false;
|
||
}
|
||
if (allowTouchInput && isDraggingWithTouch)
|
||
{
|
||
if (GetButton)
|
||
{
|
||
chatContentBox.anchoredPosition -= new Vector2(0f, chatContentBox.transform.InverseTransformDirection(previousInputPosition).y - chatContentBox.transform.InverseTransformDirection(InputPosition).y);
|
||
previousInputPosition = InputPosition;
|
||
ConstrainContentBox();
|
||
}
|
||
else
|
||
{
|
||
isDraggingWithTouch = false;
|
||
currentTouchId = -1;
|
||
}
|
||
}
|
||
if (parentCanvasSize != parentCanvasRectTrans.sizeDelta)
|
||
{
|
||
UpdatePositioning();
|
||
}
|
||
if (!Interactable)
|
||
{
|
||
ProcessToggle();
|
||
ProcessCollapse();
|
||
ProcessScrollbarToggle();
|
||
return;
|
||
}
|
||
InputOnChatBox = chatBoxScreenRect.Contains(InputPosition);
|
||
ProcessNavigationSections();
|
||
if (useScrollbar && chatContentBox.sizeDelta.y > visibleChatBoundingBox.sizeDelta.y && visibleOnlyOnHover)
|
||
{
|
||
if (scrollbarInactiveTime <= 0f && ScrollbarActive && !InputOnChatBox && !isDraggingScrollHandle)
|
||
{
|
||
DisableScrollbar();
|
||
}
|
||
else if (InputOnChatBox && (!ScrollbarActive || _inactiveTime < scrollbarInactiveTime))
|
||
{
|
||
ScrollbarActive = true;
|
||
scrollbarCanvasGroup.alpha = 1f;
|
||
scrollbarToggle = false;
|
||
scrollbarToggleLerpValue = 0f;
|
||
if (_inactiveTime > 0f)
|
||
{
|
||
_inactiveTime = 0f;
|
||
}
|
||
}
|
||
else if (ScrollbarActive && !InputOnChatBox && !isDraggingScrollHandle)
|
||
{
|
||
_inactiveTime += Time.deltaTime;
|
||
if (_inactiveTime >= scrollbarInactiveTime)
|
||
{
|
||
_inactiveTime = 0f;
|
||
DisableScrollbar();
|
||
}
|
||
}
|
||
}
|
||
if (useInteractableUsername)
|
||
{
|
||
Vector2 point = InputPosition - chatContentBox.position;
|
||
bool flag2 = false;
|
||
for (int j = 0; j < ChatInformations.Count; j++)
|
||
{
|
||
if (isDraggingWithTouch)
|
||
{
|
||
break;
|
||
}
|
||
if (isDraggingScrollHandle)
|
||
{
|
||
break;
|
||
}
|
||
if (!ChatInformations[j].IsVisible)
|
||
{
|
||
if (j > 0 && ChatInformations[j - 1].IsVisible)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (ChatInformations[j].DisplayUsername == string.Empty || ChatInformations[j].chatBoxStyle == null || ChatInformations[j].chatBoxStyle.disableInteraction || !ChatInformations[j].usernameRect.Contains(point))
|
||
{
|
||
continue;
|
||
}
|
||
flag2 = true;
|
||
if (CurrentHoveredChatIndex != j)
|
||
{
|
||
CurrentHoveredChatIndex = j;
|
||
if (interactableUsernameImage != null)
|
||
{
|
||
if (!UsernameHighlighted)
|
||
{
|
||
UsernameHighlighted = true;
|
||
interactableUsernameImage.color = interactableUsernameColor;
|
||
}
|
||
interactableUsernameImage.rectTransform.sizeDelta = (ChatInformations[j].usernameRect.size + new Vector2(LineHeight * interactableUsernameWidthModifier, 0f)) / parentCanvasScale;
|
||
interactableUsernameImage.rectTransform.anchoredPosition = ChatInformations[j].usernameRect.center / parentCanvasScale;
|
||
}
|
||
}
|
||
this.OnUsernameHover?.Invoke(InputPosition, ChatInformations[j]);
|
||
if (device != null && (device.leftButton.wasPressedThisFrame || device.rightButton.wasPressedThisFrame))
|
||
{
|
||
this.OnUsernameInteract?.Invoke(InputPosition, ChatInformations[j]);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
if (!flag2 && CurrentHoveredChatIndex >= 0)
|
||
{
|
||
CurrentHoveredChatIndex = -1;
|
||
if (UsernameHighlighted)
|
||
{
|
||
UsernameHighlighted = false;
|
||
interactableUsernameImage.color = Color.clear;
|
||
}
|
||
}
|
||
}
|
||
ProcessToggle();
|
||
ProcessCollapse();
|
||
ProcessScrollbarToggle();
|
||
ProcessInputField();
|
||
if (useInputField && inputField != null)
|
||
{
|
||
inputFieldStringPosition = inputField.stringPosition;
|
||
}
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
UpdatePositioning();
|
||
}
|
||
|
||
private void ProcessNavigationSections()
|
||
{
|
||
if (!useScrollbar || chatContentBox.sizeDelta.y < visibleChatBoundingBox.sizeDelta.y)
|
||
{
|
||
return;
|
||
}
|
||
if (useScrollWheel)
|
||
{
|
||
if (!isDraggingScrollHandle && InputOnChatBox)
|
||
{
|
||
scrollValue += InputSystem.GetDevice<Mouse>().scroll.ReadValue().normalized.y;
|
||
}
|
||
if (scrollValue != 0f)
|
||
{
|
||
chatContentBox.anchoredPosition -= new Vector2(0f, LineHeight) * scrollValue * mouseScrollSpeed;
|
||
ConstrainContentBox();
|
||
scrollValue = 0f;
|
||
return;
|
||
}
|
||
}
|
||
if (allowTouchInput && isDraggingWithTouch)
|
||
{
|
||
if (GetButton)
|
||
{
|
||
chatContentBox.anchoredPosition -= new Vector2(0f, chatContentBox.transform.InverseTransformDirection(previousInputPosition).y - chatContentBox.transform.InverseTransformDirection(InputPosition).y);
|
||
previousInputPosition = InputPosition;
|
||
ConstrainContentBox();
|
||
}
|
||
else
|
||
{
|
||
isDraggingWithTouch = false;
|
||
currentTouchId = -1;
|
||
}
|
||
}
|
||
if (isDraggingWithTouch)
|
||
{
|
||
return;
|
||
}
|
||
if (scrollbarHandleRect.Contains(InputPosition))
|
||
{
|
||
if (!scrollbarHandleHovered && !GetButton)
|
||
{
|
||
scrollbarHandleHovered = true;
|
||
scrollbarHandleActive = false;
|
||
scrollbarHandleImage.color = scrollbarHandleHoverColor;
|
||
}
|
||
if (GetButtonDown)
|
||
{
|
||
previousInputPosition = InputPosition;
|
||
scrollbarHandleInputStart = InputPosition - (Vector3)scrollbarHandleRect.center;
|
||
isDraggingScrollHandle = true;
|
||
scrollbarHandleHovered = false;
|
||
scrollbarHandleActive = true;
|
||
scrollbarHandleImage.color = scrollbarHandleActiveColor;
|
||
}
|
||
}
|
||
else if (!isDraggingScrollHandle && (scrollbarHandleHovered || scrollbarHandleActive))
|
||
{
|
||
scrollbarHandleHovered = false;
|
||
scrollbarHandleActive = false;
|
||
scrollbarHandleImage.color = scrollbarHandleNormalColor;
|
||
}
|
||
if (isDraggingScrollHandle)
|
||
{
|
||
if (GetButton)
|
||
{
|
||
float num = InputPosition.y - previousInputPosition.y;
|
||
float y = ((Vector2)InputPosition - (scrollbarHandleRect.position + scrollbarHandleRect.size / 2f) - scrollbarHandleInputStart).y;
|
||
if ((num > 0f && y >= 0f) || (num < 0f && y <= 0f))
|
||
{
|
||
scrollbarHandle.anchoredPosition += new Vector2(0f, num);
|
||
}
|
||
ConstrainScrollbarHandle();
|
||
previousInputPosition = InputPosition;
|
||
return;
|
||
}
|
||
isDraggingScrollHandle = false;
|
||
}
|
||
if (!disableBaseNavigation && !isDraggingScrollHandle && scrollbarBaseRect.Contains(InputPosition) && GetButtonDown)
|
||
{
|
||
scrollbarHandle.anchoredPosition = (Vector2)InputPosition - (scrollbarBaseRect.center + scrollbarBaseRect.size / 2f) + new Vector2(0f, scrollbarHandle.sizeDelta.y / 2f);
|
||
ConstrainScrollbarHandle();
|
||
}
|
||
if (scrollbarNavigationArrowUpRect.Contains(InputPosition))
|
||
{
|
||
if (!scrollbarNavigationArrowUpHovered && (!GetButton || scrollbarNavigationArrowUpActivated))
|
||
{
|
||
scrollbarNavigationArrowUpHovered = true;
|
||
if (scrollbarNavigationArrowUpActivated)
|
||
{
|
||
navigationArrowUp.color = navigationActiveColor;
|
||
}
|
||
else
|
||
{
|
||
navigationArrowUp.color = navigationHoverColor;
|
||
}
|
||
}
|
||
if (GetButtonDown)
|
||
{
|
||
scrollbarNavigationArrowUpActivated = true;
|
||
navigationArrowUp.color = navigationActiveColor;
|
||
chatContentBox.anchoredPosition -= new Vector2(0f, LineHeight);
|
||
ConstrainContentBox();
|
||
}
|
||
if (!scrollbarNavigationArrowUpActivated)
|
||
{
|
||
return;
|
||
}
|
||
if (GetButton)
|
||
{
|
||
navigationInitialHoldTime += Time.deltaTime;
|
||
if (navigationInitialHoldTime >= navigationInitialHoldDelay)
|
||
{
|
||
navigationIntervalTime += Time.deltaTime;
|
||
if (navigationIntervalTime >= navigationIntervalDelay)
|
||
{
|
||
navigationIntervalTime -= navigationIntervalDelay;
|
||
chatContentBox.anchoredPosition -= new Vector2(0f, LineHeight);
|
||
ConstrainContentBox();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
scrollbarNavigationArrowUpActivated = false;
|
||
navigationInitialHoldTime = 0f;
|
||
navigationIntervalTime = 0f;
|
||
navigationArrowUp.color = navigationHoverColor;
|
||
}
|
||
return;
|
||
}
|
||
if (scrollbarNavigationArrowUpHovered)
|
||
{
|
||
scrollbarNavigationArrowUpHovered = false;
|
||
navigationArrowUp.color = navigationNormalColor;
|
||
}
|
||
if (scrollbarNavigationArrowUpActivated && !GetButton)
|
||
{
|
||
scrollbarNavigationArrowUpActivated = false;
|
||
navigationInitialHoldTime = 0f;
|
||
navigationIntervalTime = 0f;
|
||
navigationArrowUp.color = navigationNormalColor;
|
||
}
|
||
if (scrollbarNavigationArrowDownRect.Contains(InputPosition))
|
||
{
|
||
if (!scrollbarNavigationArrowDownHovered && (!GetButton || scrollbarNavigationArrowDownActivated))
|
||
{
|
||
scrollbarNavigationArrowDownHovered = true;
|
||
if (scrollbarNavigationArrowDownActivated)
|
||
{
|
||
navigationArrowDown.color = navigationActiveColor;
|
||
}
|
||
else
|
||
{
|
||
navigationArrowDown.color = navigationHoverColor;
|
||
}
|
||
}
|
||
if (GetButtonDown)
|
||
{
|
||
scrollbarNavigationArrowDownActivated = true;
|
||
navigationArrowDown.color = navigationActiveColor;
|
||
chatContentBox.anchoredPosition += new Vector2(0f, LineHeight);
|
||
ConstrainContentBox();
|
||
}
|
||
if (!scrollbarNavigationArrowDownActivated)
|
||
{
|
||
return;
|
||
}
|
||
if (GetButton)
|
||
{
|
||
navigationInitialHoldTime += Time.deltaTime;
|
||
if (navigationInitialHoldTime >= navigationInitialHoldDelay)
|
||
{
|
||
navigationIntervalTime += Time.deltaTime;
|
||
if (navigationIntervalTime >= navigationIntervalDelay)
|
||
{
|
||
navigationIntervalTime -= navigationIntervalDelay;
|
||
chatContentBox.anchoredPosition += new Vector2(0f, LineHeight);
|
||
ConstrainContentBox();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
scrollbarNavigationArrowDownActivated = false;
|
||
navigationInitialHoldTime = 0f;
|
||
navigationIntervalTime = 0f;
|
||
navigationArrowDown.color = navigationHoverColor;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (scrollbarNavigationArrowDownHovered)
|
||
{
|
||
scrollbarNavigationArrowDownHovered = false;
|
||
navigationArrowDown.color = navigationNormalColor;
|
||
}
|
||
if (scrollbarNavigationArrowDownActivated && !GetButton)
|
||
{
|
||
scrollbarNavigationArrowDownActivated = false;
|
||
navigationInitialHoldTime = 0f;
|
||
navigationIntervalTime = 0f;
|
||
navigationArrowDown.color = navigationNormalColor;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void ProcessToggle()
|
||
{
|
||
if (!fadeWhenDisabled)
|
||
{
|
||
return;
|
||
}
|
||
if (fadeIn)
|
||
{
|
||
fadeLerpValue += Time.unscaledDeltaTime * fadeInSpeed;
|
||
chatBoxCanvasGroup.alpha = Mathf.Lerp(toggledAlpha, 1f, fadeLerpValue);
|
||
if (fadeLerpValue >= 1f)
|
||
{
|
||
fadeIn = false;
|
||
fadeLerpValue = 1f;
|
||
chatBoxCanvasGroup.alpha = 1f;
|
||
}
|
||
}
|
||
else if (fadeOut)
|
||
{
|
||
fadeLerpValue -= Time.unscaledDeltaTime * fadeOutSpeed;
|
||
chatBoxCanvasGroup.alpha = Mathf.Lerp(toggledAlpha, 1f, fadeLerpValue);
|
||
if (fadeLerpValue <= 0f)
|
||
{
|
||
fadeOut = false;
|
||
fadeLerpValue = 0f;
|
||
chatBoxCanvasGroup.alpha = toggledAlpha;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void ProcessCollapse()
|
||
{
|
||
if (!collapseWhenDisabled)
|
||
{
|
||
return;
|
||
}
|
||
if (expandChatBox)
|
||
{
|
||
collapseLerpValue += Time.unscaledDeltaTime * expandSpeed;
|
||
BaseTransform.sizeDelta = Vector2.Lerp(baseTransformCollapsedSize, baseTransformSize, collapseLerpValue);
|
||
visibleChatBoundingBox.sizeDelta = Vector2.Lerp(boundingBoxCollapsedSize, visibleBoundingBoxSize, collapseLerpValue);
|
||
if (collapseLerpValue >= 1f)
|
||
{
|
||
expandChatBox = false;
|
||
collapseLerpValue = 1f;
|
||
BaseTransform.sizeDelta = baseTransformSize;
|
||
visibleChatBoundingBox.sizeDelta = visibleBoundingBoxSize;
|
||
}
|
||
if (!chatBoxPositionCustom)
|
||
{
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
}
|
||
UpdateChatBoxComponentSizes();
|
||
ConstrainContentBox();
|
||
}
|
||
else if (collapseChatBox)
|
||
{
|
||
collapseLerpValue -= Time.unscaledDeltaTime * collapseSpeed;
|
||
BaseTransform.sizeDelta = Vector2.Lerp(baseTransformCollapsedSize, baseTransformSize, collapseLerpValue);
|
||
visibleChatBoundingBox.sizeDelta = Vector2.Lerp(boundingBoxCollapsedSize, visibleBoundingBoxSize, collapseLerpValue);
|
||
if (collapseLerpValue < 0f)
|
||
{
|
||
collapseChatBox = false;
|
||
collapseLerpValue = 0f;
|
||
BaseTransform.sizeDelta = baseTransformCollapsedSize;
|
||
visibleChatBoundingBox.sizeDelta = boundingBoxCollapsedSize;
|
||
}
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
UpdateChatBoxComponentSizes();
|
||
ConstrainContentBox();
|
||
}
|
||
}
|
||
|
||
private void ProcessScrollbarToggle()
|
||
{
|
||
if (!(scrollbarToggleSpeed <= 0f) && scrollbarToggle)
|
||
{
|
||
scrollbarToggleLerpValue += Time.unscaledDeltaTime * scrollbarToggleSpeed;
|
||
scrollbarCanvasGroup.alpha = Mathf.Lerp(1f, 0f, scrollbarToggleLerpValue);
|
||
if (scrollbarToggleLerpValue >= 1f)
|
||
{
|
||
scrollbarToggle = false;
|
||
scrollbarToggleLerpValue = 0f;
|
||
scrollbarCanvasGroup.alpha = 0f;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void DisableScrollbar()
|
||
{
|
||
ScrollbarActive = false;
|
||
if (scrollbarToggleSpeed > 0f)
|
||
{
|
||
scrollbarToggle = true;
|
||
scrollbarToggleLerpValue = 0f;
|
||
}
|
||
else
|
||
{
|
||
scrollbarCanvasGroup.alpha = 0f;
|
||
}
|
||
}
|
||
|
||
private void ProcessInputField()
|
||
{
|
||
if (!useInputField)
|
||
{
|
||
return;
|
||
}
|
||
if (InputSystem.GetDevice<Keyboard>().enterKey.wasPressedThisFrame || InputSystem.GetDevice<Keyboard>().numpadEnterKey.wasPressedThisFrame)
|
||
{
|
||
ToggleInputField();
|
||
}
|
||
if (!InputFieldEnabled && GetButtonDown && inputFieldRect.Contains(InputPosition))
|
||
{
|
||
EnableInputField();
|
||
}
|
||
if (useExtraImage && extraImage != null && GetButtonDown && extraImageRect.Contains(InputPosition))
|
||
{
|
||
this.OnExtraImageInteract?.Invoke();
|
||
}
|
||
if (InputFieldEnabled && inputField.text != InputFieldValue)
|
||
{
|
||
if (disableRichTextFromPlayers)
|
||
{
|
||
MatchCollection matchCollection = new Regex("<[^>]*>").Matches(inputField.text);
|
||
for (int i = 0; i < matchCollection.Count; i++)
|
||
{
|
||
if (!useTextEmoji || !matchCollection[i].ToString().Contains("sprite"))
|
||
{
|
||
int stringPosition = inputField.stringPosition - matchCollection[i].Length;
|
||
if (inputField.stringPosition == inputField.text.Length)
|
||
{
|
||
stringPosition = inputField.text.Length;
|
||
}
|
||
inputField.text = inputField.text.Replace(matchCollection[i].ToString(), string.Empty);
|
||
inputField.stringPosition = stringPosition;
|
||
}
|
||
}
|
||
}
|
||
if (inputField.text.Contains("\t"))
|
||
{
|
||
inputField.text = inputField.text.Replace("\t", string.Empty);
|
||
}
|
||
MatchCollection matchCollection2 = new Regex(Environment.NewLine).Matches(inputField.text);
|
||
for (int j = 0; j < matchCollection2.Count; j++)
|
||
{
|
||
inputField.text = inputField.text.Replace(matchCollection2[j].ToString(), " ");
|
||
}
|
||
InputFieldValue = inputField.text;
|
||
this.OnInputFieldUpdated?.Invoke(InputFieldValue);
|
||
if (InputFieldValue != string.Empty && InputFieldValue[0].ToString() == "/")
|
||
{
|
||
string arg = "";
|
||
if (InputFieldValue.Contains(" "))
|
||
{
|
||
arg = InputFieldValue.Remove(0, InputFieldValue.Split(' ')[0].Length + 1);
|
||
}
|
||
this.OnInputFieldCommandUpdated?.Invoke(InputFieldValue.Split(' ')[0].ToLower(), arg);
|
||
InputFieldContainsCommand = true;
|
||
}
|
||
else
|
||
{
|
||
InputFieldContainsCommand = false;
|
||
}
|
||
}
|
||
if (!useEmojiWindow || !(emojiButtonImage != null) || !(emojiWindowImage != null))
|
||
{
|
||
return;
|
||
}
|
||
if (EmojiWindowEnabled && GetButtonDown)
|
||
{
|
||
for (int k = 0; k < emojiRects.Count; k++)
|
||
{
|
||
if (emojiRects[k].Contains(InputPosition))
|
||
{
|
||
inputField.text = inputField.text.Insert(inputField.stringPosition, $"<sprite={k}>");
|
||
inputField.stringPosition += $"<sprite={k}>".Length;
|
||
inputField.caretPosition++;
|
||
inputField.ActivateInputField();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (GetButtonDown)
|
||
{
|
||
if (emojiButtonRect.Contains(InputPosition))
|
||
{
|
||
EmojiWindowEnabled = true;
|
||
emojiWindowCanvasGroup.alpha = 1f;
|
||
inputField.stringPosition = inputFieldStringPosition;
|
||
EnableInputField();
|
||
}
|
||
else if (EmojiWindowEnabled && !emojiWindowRect.Contains(InputPosition))
|
||
{
|
||
EmojiWindowEnabled = false;
|
||
emojiWindowCanvasGroup.alpha = 0f;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void UpdateChatBoxComponentSizes()
|
||
{
|
||
if (totalContentSpace < chatContentBox.sizeDelta.y || totalContentSpace > chatContentBox.sizeDelta.y)
|
||
{
|
||
chatContentBox.sizeDelta = new Vector2(chatContentBox.sizeDelta.x, totalContentSpace);
|
||
}
|
||
bottomContentPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
chatBoxScreenRect = CalculateRect(BaseTransform);
|
||
AdjustChatBoxScreenRect();
|
||
if (!useScrollbar || scrollbarBase == null)
|
||
{
|
||
return;
|
||
}
|
||
if (chatContentBox.sizeDelta.y <= visibleChatBoundingBox.sizeDelta.y && ScrollbarActive)
|
||
{
|
||
ScrollbarActive = false;
|
||
scrollbarCanvasGroup.alpha = 0f;
|
||
}
|
||
else if (chatContentBox.sizeDelta.y > visibleChatBoundingBox.sizeDelta.y && !ScrollbarActive && !visibleOnlyOnHover)
|
||
{
|
||
ScrollbarActive = true;
|
||
scrollbarCanvasGroup.alpha = 1f;
|
||
}
|
||
scrollbarBase.sizeDelta = new Vector2(scrollbarBase.sizeDelta.x, visibleChatBoundingBox.sizeDelta.y);
|
||
if (useNavigationArrows && navigationArrowUp != null)
|
||
{
|
||
scrollbarBase.sizeDelta -= new Vector2(0f, navigationArrowUp.rectTransform.sizeDelta.y * 2f);
|
||
scrollbarNavigationArrowUpRect = CalculateRect(navigationArrowUp.rectTransform);
|
||
}
|
||
scrollbarBaseRect = CalculateRect(scrollbarBase);
|
||
if (scrollbarHandle != null)
|
||
{
|
||
float t = Mathf.Abs(visibleChatBoundingBox.sizeDelta.y / chatContentBox.sizeDelta.y);
|
||
if (chatContentBox.sizeDelta.y <= visibleChatBoundingBox.sizeDelta.y)
|
||
{
|
||
t = 1f;
|
||
}
|
||
t = Mathf.Lerp(scrollbarMinimumSize, 1f, t);
|
||
scrollbarHandle.sizeDelta = new Vector2(scrollbarBase.sizeDelta.x, scrollbarBase.sizeDelta.y * t);
|
||
scrollbarBottomPosition = new Vector2(0f, scrollbarHandle.sizeDelta.y - scrollbarBase.sizeDelta.y);
|
||
if (!chatBoxPositionCustom)
|
||
{
|
||
scrollbarHandle.anchoredPosition = scrollbarBottomPosition;
|
||
}
|
||
scrollbarHandleRect = CalculateRect(scrollbarHandle);
|
||
}
|
||
}
|
||
|
||
private Rect CalculateRect(RectTransform rectTransform)
|
||
{
|
||
return new Rect(rectTransform.position - (Vector3)(rectTransform.sizeDelta * parentCanvasScale * rectTransform.pivot), rectTransform.sizeDelta * parentCanvasScale);
|
||
}
|
||
|
||
private void AdjustChatBoxScreenRect()
|
||
{
|
||
if (useScrollbar && scrollbarBase != null)
|
||
{
|
||
if (scrollbarBaseRect.xMin < chatBoxScreenRect.xMin)
|
||
{
|
||
chatBoxScreenRect.xMin = scrollbarBaseRect.xMin;
|
||
}
|
||
else if (scrollbarBaseRect.xMax > chatBoxScreenRect.xMax)
|
||
{
|
||
chatBoxScreenRect.xMax = scrollbarBaseRect.xMax;
|
||
}
|
||
}
|
||
if (useInputField && inputField != null)
|
||
{
|
||
if (inputFieldRect.yMin < chatBoxScreenRect.yMin)
|
||
{
|
||
chatBoxScreenRect.yMin = inputFieldRect.min.y;
|
||
}
|
||
else if (inputFieldRect.yMax > chatBoxScreenRect.yMax)
|
||
{
|
||
chatBoxScreenRect.yMax = inputFieldRect.yMax;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void CalculateUsernameRect(ChatInformation chatInfo)
|
||
{
|
||
chatInfo.usernameRect = new Rect(new Vector2((0f - chatContentBox.sizeDelta.x) / 2f, chatInfo.anchoredPosition.y - chatInfo.lineHeight) * parentCanvasScale, new Vector2(chatInfo.usernameWidth * parentCanvasScale.x, chatInfo.lineHeight * parentCanvasScale.y));
|
||
}
|
||
|
||
private void ConstrainContentBox()
|
||
{
|
||
if (chatContentBox.anchoredPosition.y < 0f && chatContentBox.sizeDelta.y >= visibleChatBoundingBox.sizeDelta.y)
|
||
{
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, 0f);
|
||
}
|
||
else if (chatContentBox.anchoredPosition.y > chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y)
|
||
{
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
}
|
||
UpdateChatBoxVisibility();
|
||
if (useScrollbar && scrollbarHandle != null)
|
||
{
|
||
scrollbarHandle.anchoredPosition = Vector2.Lerp(Vector2.zero, scrollbarBottomPosition, (chatContentBox.anchoredPosition.y == 0f) ? 0f : (chatContentBox.anchoredPosition.y / (chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y)));
|
||
scrollbarHandleRect = CalculateRect(scrollbarHandle);
|
||
}
|
||
}
|
||
|
||
private void ConstrainScrollbarHandle()
|
||
{
|
||
if (scrollbarHandle.anchoredPosition.y > 0f)
|
||
{
|
||
scrollbarHandle.anchoredPosition = new Vector2(0f, 0f);
|
||
}
|
||
else if (scrollbarHandle.anchoredPosition.y < scrollbarHandle.sizeDelta.y - scrollbarBase.sizeDelta.y)
|
||
{
|
||
scrollbarHandle.anchoredPosition = new Vector2(0f, scrollbarHandle.sizeDelta.y - scrollbarBase.sizeDelta.y);
|
||
}
|
||
scrollbarHandle.anchoredPosition = new Vector2(0f, scrollbarHandle.anchoredPosition.y);
|
||
scrollbarHandleRect = CalculateRect(scrollbarHandle);
|
||
chatContentBox.anchoredPosition = Vector2.Lerp(new Vector2(chatContentBox.anchoredPosition.x, 0f), bottomContentPosition, (scrollbarHandle.anchoredPosition.y == 0f) ? 0f : (scrollbarHandle.anchoredPosition.y / scrollbarBottomPosition.y));
|
||
UpdateChatBoxVisibility();
|
||
}
|
||
|
||
private void UpdateChatBoxVisibility()
|
||
{
|
||
if (ChatInformations.Count == 0)
|
||
{
|
||
return;
|
||
}
|
||
chatBoxVisiblityRect = new Rect(new Vector2(0f, chatContentBox.anchoredPosition.y), visibleChatBoundingBox.sizeDelta);
|
||
List<int> list = new List<int>();
|
||
for (int i = 0; i < ChatInformations.Count; i++)
|
||
{
|
||
ChatInformations[i].UpdateVisibility();
|
||
if (ChatInformations[i].IsVisible && ChatInformations[i].chatText == null)
|
||
{
|
||
list.Add(i);
|
||
}
|
||
else if (!ChatInformations[i].IsVisible && ChatInformations[i].chatText != null)
|
||
{
|
||
SendTextToPool(ChatInformations[i].chatText);
|
||
ChatInformations[i].chatText = null;
|
||
}
|
||
}
|
||
for (int j = 0; j < list.Count; j++)
|
||
{
|
||
ChatInformations[list[j]].chatText = GetTextFromPool();
|
||
ChatInformations[list[j]].UpdateText();
|
||
ChatInformations[list[j]].chatText.rectTransform.sizeDelta = new Vector2(chatContentBox.sizeDelta.x, ChatInformations[list[j]].contentSpace);
|
||
ChatInformations[list[j]].chatText.rectTransform.anchoredPosition = ChatInformations[list[j]].anchoredPosition;
|
||
}
|
||
chatBoxPositionCustom = !ChatInformations[ChatInformations.Count - 1].IsVisible;
|
||
}
|
||
|
||
private void RepositionAllChats()
|
||
{
|
||
if (ChatInformations.Count == 0)
|
||
{
|
||
return;
|
||
}
|
||
totalContentSpace = 0f;
|
||
for (int i = 0; i < ChatInformations.Count; i++)
|
||
{
|
||
ChatInformations[i].anchoredPosition = new Vector2(0f, 0f - totalContentSpace);
|
||
if (ChatInformations[i].chatText != null)
|
||
{
|
||
SendTextToPool(ChatInformations[i].chatText);
|
||
ChatInformations[i].chatText = null;
|
||
}
|
||
if (i == ChatInformations.Count - 1 && spaceBetweenChats > 0f)
|
||
{
|
||
ChatInformations[i].contentSpace = (float)ChatInformations[i].lineCount * ChatInformations[i].lineHeight;
|
||
}
|
||
totalContentSpace += ChatInformations[i].contentSpace;
|
||
}
|
||
UpdateChatBoxComponentSizes();
|
||
ConstrainContentBox();
|
||
if (useInteractableUsername)
|
||
{
|
||
for (int j = 0; j < ChatInformations.Count; j++)
|
||
{
|
||
CalculateUsernameRect(ChatInformations[j]);
|
||
}
|
||
CurrentHoveredChatIndex = -1;
|
||
if (UsernameHighlighted)
|
||
{
|
||
UsernameHighlighted = false;
|
||
interactableUsernameImage.color = Color.clear;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void OnTransformParentChanged()
|
||
{
|
||
ParentCanvas = null;
|
||
Transform parent = base.transform.parent;
|
||
if (parent == null)
|
||
{
|
||
return;
|
||
}
|
||
while (parent != null)
|
||
{
|
||
if ((bool)parent.transform.GetComponent<Canvas>())
|
||
{
|
||
ParentCanvas = parent.transform.GetComponent<Canvas>();
|
||
parentCanvasRectTrans = ParentCanvas.GetComponent<RectTransform>();
|
||
break;
|
||
}
|
||
parent = parent.transform.parent;
|
||
}
|
||
}
|
||
|
||
private TextMeshProUGUI GetTextFromPool()
|
||
{
|
||
TextMeshProUGUI textMeshProUGUI;
|
||
if (UnusedTextPool.Count > 0)
|
||
{
|
||
textMeshProUGUI = UnusedTextPool[0];
|
||
UnusedTextPool.RemoveAt(0);
|
||
}
|
||
else
|
||
{
|
||
GameObject gameObject = UnityEngine.Object.Instantiate(textObject.gameObject, chatContentBox.transform);
|
||
gameObject.name = "ChatText";
|
||
gameObject.SetActive(value: true);
|
||
AllTextObjects.Add(gameObject.GetComponent<TextMeshProUGUI>());
|
||
textMeshProUGUI = gameObject.GetComponent<TextMeshProUGUI>();
|
||
}
|
||
textMeshProUGUI.color = textColor;
|
||
return textMeshProUGUI;
|
||
}
|
||
|
||
private void SendTextToPool(TextMeshProUGUI chatText)
|
||
{
|
||
UnusedTextPool.Add(chatText);
|
||
chatText.color = Color.clear;
|
||
}
|
||
|
||
private void RegisterChatInternal(string username, string message, ChatStyle style)
|
||
{
|
||
if (ChatInformations.Count > 0 && spaceBetweenChats > 0f)
|
||
{
|
||
ChatInformations[ChatInformations.Count - 1].contentSpace += LineHeight * spaceBetweenChats;
|
||
totalContentSpace += LineHeight * spaceBetweenChats;
|
||
if (ChatInformations[ChatInformations.Count - 1].chatText != null)
|
||
{
|
||
ChatInformations[ChatInformations.Count - 1].chatText.rectTransform.sizeDelta = new Vector2(chatContentBox.sizeDelta.x, ChatInformations[ChatInformations.Count - 1].contentSpace);
|
||
}
|
||
}
|
||
ChatInformation chatInformation = new ChatInformation
|
||
{
|
||
chatBox = this
|
||
};
|
||
if (username != string.Empty)
|
||
{
|
||
chatInformation.Username = username;
|
||
if (username.Contains("#"))
|
||
{
|
||
chatInformation.DisplayUsername = username.Split('#')[0];
|
||
}
|
||
else
|
||
{
|
||
chatInformation.DisplayUsername = username;
|
||
}
|
||
}
|
||
chatInformation.Message = message;
|
||
chatInformation.DisplayMessage = ((!(username != string.Empty)) ? "" : (((!style.noUsernameFollowupText) ? usernameFollowup : " ") ?? "")) + message;
|
||
chatInformation.chatBoxStyle = style;
|
||
chatInformation.chatText = GetTextFromPool();
|
||
if (username != string.Empty)
|
||
{
|
||
chatInformation.usernameWidth = chatInformation.chatText.GetPreferredValues(style.FormatUsernameOnly(chatInformation.DisplayUsername)).x;
|
||
}
|
||
chatInformation.UpdateText();
|
||
chatInformation.chatText.ForceMeshUpdate();
|
||
chatInformation.lineCount = chatInformation.chatText.textInfo.lineCount;
|
||
chatInformation.lineHeight = chatInformation.chatText.renderedHeight / (float)chatInformation.lineCount;
|
||
if (chatInformation.lineHeight < 0.1f)
|
||
{
|
||
chatInformation.lineHeight = LineHeight;
|
||
}
|
||
chatInformation.chatText.rectTransform.sizeDelta = new Vector2(chatContentBox.sizeDelta.x, chatInformation.lineHeight * (float)chatInformation.lineCount);
|
||
chatInformation.chatText.rectTransform.anchoredPosition = new Vector2(0f, 0f - totalContentSpace);
|
||
chatInformation.anchoredPosition = chatInformation.chatText.rectTransform.anchoredPosition;
|
||
chatInformation.contentSpace = chatInformation.chatText.rectTransform.sizeDelta.y;
|
||
CalculateUsernameRect(chatInformation);
|
||
ChatInformations.Add(chatInformation);
|
||
totalContentSpace += chatInformation.contentSpace;
|
||
if (maxTextInChatBox > 0 && ChatInformations.Count > maxTextInChatBox)
|
||
{
|
||
if (ChatInformations[0].chatText != null)
|
||
{
|
||
SendTextToPool(ChatInformations[0].chatText);
|
||
}
|
||
ChatInformations.RemoveAt(0);
|
||
RepositionAllChats();
|
||
}
|
||
this.OnChatRegistered?.Invoke(chatInformation);
|
||
if (!base.gameObject.activeInHierarchy)
|
||
{
|
||
SendTextToPool(chatInformation.chatText);
|
||
chatInformation.chatText = null;
|
||
return;
|
||
}
|
||
UpdateChatBoxComponentSizes();
|
||
if (!chatBoxPositionCustom)
|
||
{
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
}
|
||
ConstrainContentBox();
|
||
}
|
||
|
||
private static string FormatDebug(string error, string solution, string objectName)
|
||
{
|
||
return "<b>Ultimate Chat Box</b>\n<color=red><b>×</b></color> <i><b>Error:</b></i> " + error + ".\n<color=green><b>√</b></color> <i><b>Solution:</b></i> " + solution + ".\n<color=cyan><b>∙</b></color> <i><b>Object:</b></i> " + objectName + "\n";
|
||
}
|
||
|
||
public void UpdatePositioning()
|
||
{
|
||
if (ParentCanvas == null)
|
||
{
|
||
OnTransformParentChanged();
|
||
}
|
||
if (ParentCanvas == null)
|
||
{
|
||
if (Application.isPlaying)
|
||
{
|
||
Debug.LogError(FormatDebug("There is no parent canvas object", "Please make sure that the Ultimate Chat Box is placed within a canvas object in your scene", base.gameObject.name));
|
||
}
|
||
return;
|
||
}
|
||
parentCanvasSize = parentCanvasRectTrans.sizeDelta;
|
||
parentCanvasScale = parentCanvasRectTrans.localScale;
|
||
float num = Mathf.Min(parentCanvasSize.y, parentCanvasSize.x);
|
||
BaseTransform.sizeDelta = chatBoxSize / 10f * num * chatBoxSizeRatio * Vector2.one;
|
||
if (BaseTransform.sizeDelta.x <= 0f || BaseTransform.sizeDelta.y <= 0f)
|
||
{
|
||
return;
|
||
}
|
||
Vector2 vector = parentCanvasSize * (chatBoxPosition / 100f) - BaseTransform.sizeDelta * (chatBoxPosition / 100f) + new Vector2(BaseTransform.sizeDelta.x / 2f, 0f) - parentCanvasSize / 2f;
|
||
TotalChatBoxSize = BaseTransform.sizeDelta;
|
||
BaseTransform.anchorMin = new Vector2(0.5f, 0f);
|
||
BaseTransform.anchorMax = new Vector2(0.5f, 0f);
|
||
BaseTransform.pivot = new Vector2(0.5f, 0f);
|
||
BaseTransform.localScale = Vector3.one;
|
||
if (visibleChatBoundingBox == null || chatContentBox == null)
|
||
{
|
||
return;
|
||
}
|
||
visibleChatBoundingBox.anchorMin = new Vector2(0.5f, 0.5f);
|
||
visibleChatBoundingBox.anchorMax = new Vector2(0.5f, 0.5f);
|
||
visibleChatBoundingBox.pivot = new Vector2(0.5f, 0.5f);
|
||
visibleChatBoundingBox.sizeDelta = BaseTransform.sizeDelta - new Vector2(0f, Mathf.Max(BaseTransform.sizeDelta.x, BaseTransform.sizeDelta.y) * (verticalSpacing / 50f));
|
||
if ((double)visibleChatBoundingBox.sizeDelta.x <= 0.0 || (double)visibleChatBoundingBox.sizeDelta.y <= 0.0)
|
||
{
|
||
visibleChatBoundingBox.sizeDelta = BaseTransform.sizeDelta;
|
||
}
|
||
visibleChatBoundingBox.anchoredPosition = new Vector2(0f, BaseTransform.sizeDelta.y * (contentPosition.y / 100f) - visibleChatBoundingBox.sizeDelta.y * (contentPosition.y / 100f));
|
||
visibleBoundingBoxSize = visibleChatBoundingBox.sizeDelta;
|
||
baseTransformSize = BaseTransform.sizeDelta;
|
||
chatContentBox.anchorMin = new Vector2(0.5f, 1f);
|
||
chatContentBox.anchorMax = new Vector2(0.5f, 1f);
|
||
chatContentBox.pivot = new Vector2(0.5f, 1f);
|
||
chatContentBox.sizeDelta = visibleChatBoundingBox.sizeDelta - new Vector2(Mathf.Max(BaseTransform.sizeDelta.x, BaseTransform.sizeDelta.y) * (horizontalSpacing / 50f), 0f);
|
||
chatContentBox.anchoredPosition = new Vector2(BaseTransform.sizeDelta.x * (contentPosition.x / 100f) - chatContentBox.sizeDelta.x * (contentPosition.x / 100f), 0f);
|
||
if ((double)chatContentBox.sizeDelta.x <= 0.0 || (double)chatContentBox.sizeDelta.y <= 0.0)
|
||
{
|
||
chatContentBox.sizeDelta = BaseTransform.sizeDelta;
|
||
}
|
||
if (useScrollbar && scrollbarBase != null && scrollbarHandle != null)
|
||
{
|
||
scrollbarBase.anchorMin = new Vector2(0.5f, 0.5f);
|
||
scrollbarBase.anchorMax = new Vector2(0.5f, 0.5f);
|
||
scrollbarBase.pivot = new Vector2(0.5f, 0.5f);
|
||
scrollbarBase.sizeDelta = new Vector2(visibleBoundingBoxSize.x * scrollbarWidth, visibleBoundingBoxSize.y);
|
||
scrollbarBase.localPosition = new Vector3(BaseTransform.sizeDelta.x * (scrollbarHorizontalPosition / 100f) - scrollbarBase.sizeDelta.x * (scrollbarHorizontalPosition / 100f), visibleChatBoundingBox.localPosition.y, 0f);
|
||
if (useNavigationArrows && navigationArrowUp != null && navigationArrowDown != null)
|
||
{
|
||
Vector2 vector2 = Vector2.one;
|
||
if (navigationArrowUp.sprite != null)
|
||
{
|
||
vector2 = navigationArrowUp.sprite.rect.size / Mathf.Max(navigationArrowUp.sprite.rect.width, navigationArrowUp.sprite.rect.height);
|
||
}
|
||
navigationArrowUp.rectTransform.anchorMin = new Vector2(0.5f, 1f);
|
||
navigationArrowUp.rectTransform.anchorMax = new Vector2(0.5f, 1f);
|
||
navigationArrowUp.rectTransform.pivot = new Vector2(0.5f, 0f);
|
||
navigationArrowUp.rectTransform.sizeDelta = Vector2.one * scrollbarBase.sizeDelta.x * vector2;
|
||
navigationArrowUp.rectTransform.anchoredPosition = Vector2.zero;
|
||
navigationArrowDown.rectTransform.anchorMin = new Vector2(0.5f, 0f);
|
||
navigationArrowDown.rectTransform.anchorMax = new Vector2(0.5f, 0f);
|
||
navigationArrowDown.rectTransform.pivot = new Vector2(0.5f, 0f);
|
||
navigationArrowDown.rectTransform.anchoredPosition = Vector2.zero;
|
||
navigationArrowDown.rectTransform.sizeDelta = Vector2.one * scrollbarBase.sizeDelta.x * vector2;
|
||
scrollbarBase.sizeDelta -= new Vector2(0f, navigationArrowUp.rectTransform.sizeDelta.y * 2f);
|
||
navigationArrowUp.color = navigationNormalColor;
|
||
navigationArrowDown.color = navigationNormalColor;
|
||
scrollbarNavigationArrowUpHovered = false;
|
||
scrollbarNavigationArrowUpActivated = false;
|
||
scrollbarNavigationArrowDownHovered = false;
|
||
scrollbarNavigationArrowDownActivated = false;
|
||
}
|
||
scrollbarHandle.anchorMin = new Vector2(0.5f, 1f);
|
||
scrollbarHandle.anchorMax = new Vector2(0.5f, 1f);
|
||
scrollbarHandle.pivot = new Vector2(0.5f, 1f);
|
||
scrollbarHandle.sizeDelta = new Vector2(scrollbarBase.sizeDelta.x, scrollbarBase.sizeDelta.y / 4f);
|
||
scrollbarHandle.anchoredPosition = new Vector2(0f, 0f - scrollbarBase.sizeDelta.y + scrollbarHandle.sizeDelta.y);
|
||
if (scrollbarBase.localPosition.x + scrollbarBase.sizeDelta.x / 2f > BaseTransform.sizeDelta.x / 2f)
|
||
{
|
||
TotalChatBoxSize = new Vector2(TotalChatBoxSize.x + (scrollbarBase.localPosition.x + scrollbarBase.sizeDelta.x / 2f) - BaseTransform.sizeDelta.x / 2f, TotalChatBoxSize.y);
|
||
vector.x = parentCanvasSize.x * (chatBoxPosition.x / 100f) - TotalChatBoxSize.x * (chatBoxPosition.x / 100f) + (BaseTransform.sizeDelta.x / 2f - parentCanvasSize.x / 2f);
|
||
}
|
||
else if (scrollbarBase.localPosition.x - scrollbarBase.sizeDelta.x / 2f < 0f - BaseTransform.sizeDelta.x / 2f)
|
||
{
|
||
float num2 = 0f - BaseTransform.sizeDelta.x / 2f - (scrollbarBase.localPosition.x - scrollbarBase.sizeDelta.x / 2f);
|
||
TotalChatBoxSize = new Vector2(TotalChatBoxSize.x + num2, TotalChatBoxSize.y);
|
||
vector.x = parentCanvasSize.x * (chatBoxPosition.x / 100f) - TotalChatBoxSize.x * (chatBoxPosition.x / 100f) + num2 + (BaseTransform.sizeDelta.x / 2f - parentCanvasSize.x / 2f);
|
||
}
|
||
}
|
||
if (useInputField && inputField != null)
|
||
{
|
||
inputFieldTransform.sizeDelta = baseTransformSize * (inputFieldSize / 100f);
|
||
inputFieldTransform.localPosition = BaseTransform.sizeDelta * (inputFieldPosition / 100f) - inputFieldTransform.sizeDelta * (inputFieldPosition / 100f);
|
||
inputField.textViewport.sizeDelta = inputFieldTransform.sizeDelta * (new Vector2(inputFieldTextAreaSize.x, inputFieldTextAreaSize.y) / 100f);
|
||
inputField.textViewport.anchoredPosition = new Vector2(inputFieldTransform.sizeDelta.x * (inputFieldTextHorizontalPosition / 100f), 0f) - new Vector2(inputField.textViewport.sizeDelta.x * (inputFieldTextHorizontalPosition / 100f), 0f);
|
||
inputField.textComponent.rectTransform.localPosition = Vector3.zero;
|
||
inputField.placeholder.rectTransform.localPosition = Vector3.zero;
|
||
float num3 = LineHeight;
|
||
if ((bool)inputField.placeholder.GetComponent<TextMeshProUGUI>())
|
||
{
|
||
inputField.placeholder.GetComponent<TextMeshProUGUI>().ForceMeshUpdate();
|
||
num3 = inputField.placeholder.GetComponent<TextMeshProUGUI>().renderedHeight;
|
||
}
|
||
inputField.textViewport.GetComponent<RectMask2D>().padding = new Vector4((0f - num3) / 8f, (0f - num3) / 4f, 0f, 0f);
|
||
if (inputFieldSmartFontSize > 0f)
|
||
{
|
||
inputField.pointSize = (int)(inputField.textViewport.sizeDelta.y * inputFieldSmartFontSize);
|
||
if (inputField.pointSize <= 0f)
|
||
{
|
||
inputField.pointSize = 1f;
|
||
}
|
||
}
|
||
inputField.textComponent.fontSize = inputField.pointSize;
|
||
inputField.placeholder.GetComponent<TextMeshProUGUI>().fontSize = inputField.pointSize;
|
||
if (useExtraImage && extraImage != null)
|
||
{
|
||
extraImage.rectTransform.sizeDelta = inputFieldTransform.sizeDelta * (new Vector2(extraImageWidth, extraImageHeight) / 100f);
|
||
extraImage.rectTransform.anchoredPosition = new Vector2(inputFieldTransform.sizeDelta.x * (extraImageHorizontalPosition / 100f), 0f) - new Vector2(extraImage.rectTransform.sizeDelta.x * (extraImageHorizontalPosition / 100f), 0f);
|
||
}
|
||
if (useTextEmoji && useEmojiWindow)
|
||
{
|
||
if (emojiButtonImage != null)
|
||
{
|
||
emojiButtonImage.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
|
||
emojiButtonImage.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
|
||
emojiButtonImage.rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
||
emojiButtonImage.rectTransform.sizeDelta = Vector2.one * inputFieldTransform.sizeDelta.y * emojiButtonSize;
|
||
emojiButtonImage.rectTransform.anchoredPosition = inputFieldTransform.sizeDelta * new Vector2((emojiButtonHorizontalPosition - 50f) / 100f, 0f) - new Vector2(emojiButtonImage.rectTransform.sizeDelta.x * ((emojiButtonHorizontalPosition - 50f) / 100f), 0f);
|
||
}
|
||
if (emojiWindowImage != null)
|
||
{
|
||
emojiWindowImage.rectTransform.anchorMin = new Vector2(1f, 0f);
|
||
emojiWindowImage.rectTransform.anchorMax = new Vector2(1f, 0f);
|
||
emojiWindowImage.rectTransform.pivot = new Vector2(0f, 0f);
|
||
emojiWindowImage.rectTransform.sizeDelta = Vector2.one * TotalChatBoxSize.y * (new Vector2(emojiWindowSize.x, emojiWindowSize.y) / 100f);
|
||
emojiWindowImage.rectTransform.anchoredPosition = (baseTransformSize + new Vector2(0f, inputFieldTransform.sizeDelta.y + baseTransformSize.y * ((0f - inputFieldPosition.y) / 100f))) * (new Vector2(emojiWindowPosition.x, emojiWindowPosition.y) / 100f);
|
||
if (emojiText != null)
|
||
{
|
||
emojiText.margin = Vector4.one * (emojiWindowImage.rectTransform.sizeDelta.x * emojiTextEdgePadding);
|
||
emojiText.rectTransform.anchorMin = Vector2.zero;
|
||
emojiText.rectTransform.anchorMax = Vector2.one;
|
||
emojiText.rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
||
emojiText.rectTransform.anchoredPosition = Vector2.zero;
|
||
}
|
||
}
|
||
}
|
||
if (inputFieldTransform.localPosition.y > BaseTransform.sizeDelta.y)
|
||
{
|
||
TotalChatBoxSize = new Vector2(TotalChatBoxSize.x, TotalChatBoxSize.y + inputFieldTransform.localPosition.y - BaseTransform.sizeDelta.y);
|
||
vector.y = parentCanvasSize.y * (chatBoxPosition.y / 100f) - TotalChatBoxSize.y * (chatBoxPosition.y / 100f) - parentCanvasSize.y / 2f;
|
||
}
|
||
else if (inputFieldTransform.localPosition.y - inputFieldTransform.sizeDelta.y < 0f)
|
||
{
|
||
TotalChatBoxSize = new Vector2(TotalChatBoxSize.x, TotalChatBoxSize.y + (inputFieldTransform.sizeDelta.y - inputFieldTransform.localPosition.y));
|
||
vector.y = parentCanvasSize.y * (chatBoxPosition.y / 100f) - TotalChatBoxSize.y * (chatBoxPosition.y / 100f) + (inputFieldTransform.sizeDelta.y - inputFieldTransform.localPosition.y) - parentCanvasSize.y / 2f;
|
||
}
|
||
}
|
||
BaseTransform.localPosition = vector;
|
||
if (textObject != null)
|
||
{
|
||
if (!textObject.gameObject.activeInHierarchy)
|
||
{
|
||
textObject.gameObject.SetActive(value: true);
|
||
}
|
||
textObject.text = "<b>Username</b>" + usernameFollowup + "Message";
|
||
if (useTextEmoji && emojiAsset != null)
|
||
{
|
||
textObject.text += " <sprite=0>";
|
||
}
|
||
if (smartFontSize > 0f)
|
||
{
|
||
textObject.fontSize = (int)(baseTransformSize.y * smartFontSize);
|
||
if (textObject.fontSize <= 0f)
|
||
{
|
||
textObject.fontSize = 1f;
|
||
}
|
||
for (int i = 0; i < AllTextObjects.Count; i++)
|
||
{
|
||
AllTextObjects[i].fontSize = textObject.fontSize;
|
||
}
|
||
}
|
||
RectTransform component = textObject.GetComponent<RectTransform>();
|
||
component.anchorMin = new Vector2(0.5f, 1f);
|
||
component.anchorMax = new Vector2(0.5f, 1f);
|
||
component.pivot = new Vector2(0.5f, 1f);
|
||
component.sizeDelta = new Vector2(chatContentBox.sizeDelta.x, textObject.renderedHeight);
|
||
component.anchoredPosition = Vector2.zero;
|
||
if (Application.isPlaying)
|
||
{
|
||
textObject.ForceMeshUpdate();
|
||
LineHeight = textObject.renderedHeight;
|
||
totalContentSpace = 0f;
|
||
for (int j = 0; j < ChatInformations.Count; j++)
|
||
{
|
||
if (ChatInformations[j].chatText != null)
|
||
{
|
||
SendTextToPool(ChatInformations[j].chatText);
|
||
}
|
||
ChatInformations[j].chatText = textObject;
|
||
if (ChatInformations[j].DisplayUsername != null)
|
||
{
|
||
ChatInformations[j].usernameWidth = ChatInformations[j].chatText.GetPreferredValues(ChatInformations[j].chatBoxStyle.FormatUsernameOnly(ChatInformations[j].DisplayUsername)).x;
|
||
}
|
||
ChatInformations[j].UpdateText();
|
||
ChatInformations[j].chatText.ForceMeshUpdate();
|
||
ChatInformations[j].lineCount = ChatInformations[j].chatText.textInfo.lineCount;
|
||
ChatInformations[j].lineHeight = ChatInformations[j].chatText.renderedHeight / (float)ChatInformations[j].lineCount;
|
||
ChatInformations[j].chatText.rectTransform.sizeDelta = new Vector2(chatContentBox.sizeDelta.x, ChatInformations[j].lineHeight * (float)ChatInformations[j].lineCount);
|
||
ChatInformations[j].anchoredPosition = new Vector2(0f, 0f - totalContentSpace);
|
||
ChatInformations[j].contentSpace = ChatInformations[j].chatText.rectTransform.sizeDelta.y;
|
||
CalculateUsernameRect(ChatInformations[j]);
|
||
ChatInformations[j].chatText = null;
|
||
if (spaceBetweenChats > 0f && j < ChatInformations.Count - 1)
|
||
{
|
||
ChatInformations[j].contentSpace += LineHeight * spaceBetweenChats;
|
||
}
|
||
totalContentSpace += ChatInformations[j].contentSpace;
|
||
}
|
||
textObject.gameObject.SetActive(value: false);
|
||
textObject.text = "";
|
||
}
|
||
if (useInteractableUsername && interactableUsernameImage != null && !Application.isPlaying)
|
||
{
|
||
interactableUsernameImage.rectTransform.sizeDelta = new Vector2(textObject.GetPreferredValues("<b>Username</b>").x, textObject.renderedHeight / (float)textObject.textInfo.lineCount);
|
||
interactableUsernameImage.rectTransform.anchoredPosition = new Vector2((0f - chatContentBox.sizeDelta.x) / 2f + interactableUsernameImage.rectTransform.sizeDelta.x / 2f, (0f - interactableUsernameImage.rectTransform.sizeDelta.y) / 2f);
|
||
if (interactableUsernameWidthModifier > 0f)
|
||
{
|
||
interactableUsernameImage.rectTransform.sizeDelta = new Vector2(textObject.GetPreferredValues("<b>Username</b>").x + textObject.renderedHeight * interactableUsernameWidthModifier, textObject.renderedHeight / (float)textObject.textInfo.lineCount);
|
||
}
|
||
}
|
||
}
|
||
if (!Application.isPlaying)
|
||
{
|
||
return;
|
||
}
|
||
if (collapseWhenDisabled)
|
||
{
|
||
boundingBoxCollapsedSize = new Vector2(BaseTransform.sizeDelta.x, LineHeight * (float)visibleLineCount + LineHeight * (float)(visibleLineCount - 1) * spaceBetweenChats);
|
||
baseTransformCollapsedSize = new Vector2(BaseTransform.sizeDelta.x, boundingBoxCollapsedSize.y + BaseTransform.sizeDelta.x * (verticalSpacing / 50f));
|
||
}
|
||
if (useScrollbar && scrollbarBase != null)
|
||
{
|
||
if (useNavigationArrows && navigationArrowUp != null && navigationArrowDown != null)
|
||
{
|
||
scrollbarNavigationArrowUpRect = CalculateRect(navigationArrowUp.rectTransform);
|
||
scrollbarNavigationArrowDownRect = CalculateRect(navigationArrowDown.rectTransform);
|
||
scrollbarNavigationArrowDownRect.center = new Vector2(scrollbarNavigationArrowDownRect.center.x, scrollbarNavigationArrowDownRect.center.y - scrollbarNavigationArrowDownRect.size.y);
|
||
}
|
||
scrollbarBaseRect = CalculateRect(scrollbarBase);
|
||
}
|
||
if (useInputField && inputField != null)
|
||
{
|
||
inputFieldRect = CalculateRect(inputFieldTransform);
|
||
if (useExtraImage && extraImage != null)
|
||
{
|
||
extraImageRect = CalculateRect(extraImage.rectTransform);
|
||
}
|
||
if (useTextEmoji && useEmojiWindow)
|
||
{
|
||
if (emojiButtonImage != null)
|
||
{
|
||
emojiButtonRect = CalculateRect(emojiButtonImage.rectTransform);
|
||
}
|
||
if (emojiWindowImage != null)
|
||
{
|
||
emojiWindowRect = CalculateRect(emojiWindowImage.rectTransform);
|
||
emojiWindowCanvasGroup = emojiWindowImage.gameObject.GetComponent<CanvasGroup>();
|
||
emojiWindowCanvasGroup.alpha = 0f;
|
||
if (emojiText != null && Application.isPlaying)
|
||
{
|
||
emojiText.ForceMeshUpdate();
|
||
emojiRects = new List<Rect>();
|
||
for (int k = 0; k < emojiText.textInfo.characterCount; k++)
|
||
{
|
||
if (emojiText.textInfo.characterInfo[k].elementType != TMP_TextElementType.Character)
|
||
{
|
||
emojiRects.Add(new Rect(emojiText.rectTransform.TransformPoint(emojiText.textInfo.characterInfo[k].bottomLeft), (Vector2)(emojiText.textInfo.characterInfo[k].topRight - emojiText.textInfo.characterInfo[k].bottomLeft) * (Vector2)parentCanvasScale));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
EmojiWindowEnabled = false;
|
||
}
|
||
}
|
||
UpdateChatBoxComponentSizes();
|
||
RepositionAllChats();
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
ConstrainContentBox();
|
||
if (!IsEnabled)
|
||
{
|
||
Disable(instant: true);
|
||
}
|
||
}
|
||
|
||
public void RegisterChat(string message)
|
||
{
|
||
RegisterChatInternal("", message, UltimateChatBoxStyles.none);
|
||
}
|
||
|
||
public void RegisterChat(string message, ChatStyle style)
|
||
{
|
||
if (style == null)
|
||
{
|
||
Debug.LogWarning(FormatDebug("The provided style is null. Defaulting to None for the style", "Please make sure that your style value is actually assigned before sending it in to the Ultimate Chat Box", "Unknown (User Script)"));
|
||
style = UltimateChatBoxStyles.none;
|
||
}
|
||
RegisterChatInternal("", message, style);
|
||
}
|
||
|
||
public void RegisterChat(string username, string message)
|
||
{
|
||
RegisterChatInternal(username, message, UltimateChatBoxStyles.none);
|
||
}
|
||
|
||
public void RegisterChat(string username, string message, ChatStyle style)
|
||
{
|
||
if (style == null)
|
||
{
|
||
Debug.LogWarning(FormatDebug("The provided style is null. Defaulting to None for the style", "Please make sure that your style value is actually assigned before sending it in to the Ultimate Chat Box", "Unknown (User Script)"));
|
||
style = UltimateChatBoxStyles.none;
|
||
}
|
||
RegisterChatInternal(username, message, style);
|
||
}
|
||
|
||
public void Enable()
|
||
{
|
||
if (IsEnabled)
|
||
{
|
||
return;
|
||
}
|
||
IsEnabled = true;
|
||
if (fadeInSpeed <= 0f)
|
||
{
|
||
chatBoxCanvasGroup.alpha = 1f;
|
||
fadeLerpValue = 1f;
|
||
fadeOut = false;
|
||
}
|
||
else
|
||
{
|
||
fadeIn = true;
|
||
if (fadeOut)
|
||
{
|
||
fadeOut = false;
|
||
}
|
||
}
|
||
if (!collapseWhenDisabled)
|
||
{
|
||
return;
|
||
}
|
||
if (expandSpeed <= 0f)
|
||
{
|
||
collapseLerpValue = 1f;
|
||
BaseTransform.sizeDelta = baseTransformSize;
|
||
visibleChatBoundingBox.sizeDelta = visibleBoundingBoxSize;
|
||
UpdateChatBoxComponentSizes();
|
||
ConstrainContentBox();
|
||
chatBoxScreenRect = CalculateRect(BaseTransform);
|
||
AdjustChatBoxScreenRect();
|
||
}
|
||
else
|
||
{
|
||
expandChatBox = true;
|
||
if (collapseChatBox)
|
||
{
|
||
collapseChatBox = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
public void Disable(bool instant = false)
|
||
{
|
||
if (!IsEnabled && !instant)
|
||
{
|
||
return;
|
||
}
|
||
IsEnabled = false;
|
||
if (fadeWhenDisabled)
|
||
{
|
||
if (fadeOutSpeed <= 0f || instant)
|
||
{
|
||
chatBoxCanvasGroup.alpha = toggledAlpha;
|
||
fadeLerpValue = 0f;
|
||
fadeIn = false;
|
||
}
|
||
else
|
||
{
|
||
fadeOut = true;
|
||
if (fadeIn)
|
||
{
|
||
fadeIn = false;
|
||
}
|
||
}
|
||
}
|
||
if (collapseWhenDisabled)
|
||
{
|
||
if (collapseSpeed <= 0f || instant)
|
||
{
|
||
collapseLerpValue = 0f;
|
||
BaseTransform.sizeDelta = baseTransformCollapsedSize;
|
||
visibleChatBoundingBox.sizeDelta = boundingBoxCollapsedSize;
|
||
chatContentBox.anchoredPosition = new Vector2(chatContentBox.anchoredPosition.x, chatContentBox.sizeDelta.y - visibleChatBoundingBox.sizeDelta.y);
|
||
UpdateChatBoxComponentSizes();
|
||
ConstrainContentBox();
|
||
}
|
||
else
|
||
{
|
||
collapseChatBox = true;
|
||
if (expandChatBox)
|
||
{
|
||
expandChatBox = false;
|
||
}
|
||
}
|
||
}
|
||
if (useInputField)
|
||
{
|
||
DisableInputField();
|
||
}
|
||
}
|
||
|
||
public void ClearChat()
|
||
{
|
||
for (int i = 0; i < ChatInformations.Count; i++)
|
||
{
|
||
if (!(ChatInformations[i].chatText == null))
|
||
{
|
||
SendTextToPool(ChatInformations[i].chatText);
|
||
ChatInformations[i].chatText.rectTransform.anchoredPosition = Vector2.zero;
|
||
ChatInformations[i].chatText = null;
|
||
}
|
||
}
|
||
ChatInformations = new List<ChatInformation>();
|
||
totalContentSpace = 0f;
|
||
chatBoxPositionCustom = false;
|
||
UpdateChatBoxComponentSizes();
|
||
}
|
||
|
||
public void EnableInputField(string inputFieldValue = "")
|
||
{
|
||
if (useInputField && !(inputField == null) && !InputFieldEnabled)
|
||
{
|
||
InputFieldEnabled = true;
|
||
inputField.enabled = true;
|
||
inputField.interactable = true;
|
||
inputField.ActivateInputField();
|
||
Enable();
|
||
if (inputFieldValue != string.Empty)
|
||
{
|
||
InputFieldValue += inputFieldValue;
|
||
inputField.text = InputFieldValue;
|
||
inputField.caretPosition = InputFieldValue.Length;
|
||
inputField.selectionAnchorPosition = InputFieldValue.Length;
|
||
}
|
||
this.OnInputFieldEnabled?.Invoke();
|
||
}
|
||
}
|
||
|
||
public void ToggleInputField()
|
||
{
|
||
if (!InputFieldEnabled)
|
||
{
|
||
EnableInputField();
|
||
}
|
||
else
|
||
{
|
||
DisableInputField();
|
||
}
|
||
}
|
||
|
||
public void DisableInputField()
|
||
{
|
||
if (!useInputField || inputField == null || !InputFieldEnabled)
|
||
{
|
||
return;
|
||
}
|
||
InputFieldEnabled = false;
|
||
for (int i = 0; i < InputFieldValue.Length && char.IsWhiteSpace(InputFieldValue[i]); i++)
|
||
{
|
||
if (i == InputFieldValue.Length - 1)
|
||
{
|
||
inputField.text = string.Empty;
|
||
InputFieldValue = string.Empty;
|
||
}
|
||
}
|
||
if (IsEnabled && InputFieldValue != string.Empty)
|
||
{
|
||
if (InputFieldValue[0].ToString() == "/")
|
||
{
|
||
InputFieldContainsCommand = true;
|
||
string text = InputFieldValue;
|
||
string arg = "";
|
||
if (InputFieldValue.Contains(" "))
|
||
{
|
||
text = InputFieldValue.Split(' ')[0];
|
||
arg = InputFieldValue.Split(' ')[1];
|
||
}
|
||
this.OnInputFieldCommandSubmitted?.Invoke(text.ToLower(), arg);
|
||
}
|
||
chatBoxPositionCustom = false;
|
||
this.OnInputFieldSubmitted?.Invoke(InputFieldValue);
|
||
inputField.text = string.Empty;
|
||
InputFieldValue = string.Empty;
|
||
}
|
||
if (EmojiWindowEnabled && emojiWindowCanvasGroup != null)
|
||
{
|
||
EmojiWindowEnabled = false;
|
||
emojiWindowCanvasGroup.alpha = 0f;
|
||
}
|
||
inputField.ReleaseSelection();
|
||
inputField.DeactivateInputField();
|
||
inputField.enabled = false;
|
||
inputField.interactable = false;
|
||
InputFieldContainsCommand = false;
|
||
if (IsEnabled)
|
||
{
|
||
Disable();
|
||
}
|
||
this.OnInputFieldDisabled?.Invoke();
|
||
}
|
||
|
||
public void SendCustomInput(Vector2 screenPosition, bool getButtonDown, bool getButton)
|
||
{
|
||
customInputRecieved = true;
|
||
customScreenPosition = screenPosition;
|
||
customGetButtonDown = getButtonDown;
|
||
customGetButton = getButton;
|
||
}
|
||
|
||
public List<ChatInformation> FindChatsFromUser(string username)
|
||
{
|
||
if (username == string.Empty)
|
||
{
|
||
Debug.LogError(FormatDebug("The provided username is empty", "Please provide this function with the string value of the user", "Unknown (User Script)"));
|
||
return new List<ChatInformation>();
|
||
}
|
||
List<ChatInformation> list = new List<ChatInformation>();
|
||
for (int i = 0; i < ChatInformations.Count; i++)
|
||
{
|
||
if (ChatInformations[i].Username == username)
|
||
{
|
||
list.Add(ChatInformations[i]);
|
||
}
|
||
}
|
||
if (list.Count == 0)
|
||
{
|
||
Debug.LogWarning(FormatDebug("No chats were found from the provided username: " + username + ". Either their are no chats currently registered from this user, or the provided username is incorrect", "Please ensure that the provided username is correct", "Unknown (User Script)"));
|
||
}
|
||
return list;
|
||
}
|
||
|
||
public List<ChatInformation> FindChatsOfStyle(ChatStyle style)
|
||
{
|
||
if (style == null)
|
||
{
|
||
Debug.LogError(FormatDebug("The provided style is null", "Please provide this function with the style of the chats you want returned", "Unknown (User Script)"));
|
||
return new List<ChatInformation>();
|
||
}
|
||
List<ChatInformation> list = new List<ChatInformation>();
|
||
for (int i = 0; i < ChatInformations.Count; i++)
|
||
{
|
||
if (ChatInformations[i].chatBoxStyle == style)
|
||
{
|
||
list.Add(ChatInformations[i]);
|
||
}
|
||
}
|
||
if (list.Count == 0)
|
||
{
|
||
Debug.LogWarning(FormatDebug("No chats were found that have been registered with the provided style", "Please ensure that the provided style is correct", "Unknown (User Script)"));
|
||
}
|
||
return list;
|
||
}
|
||
}
|
||
}
|