Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public static class RequestHandlerConstants
{
public const string REQUEST_ROUND_STATUS = "requestRoundStatus";
public const string REQUEST_SUPPORTERS = "requestRoundStatus";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using Core.Editor.Attributes;
using Core.Networking.AsyncMessageQueue;
using Logs;
using Managers.Supporters.FetchSupporterMethods;
using Newtonsoft.Json;
using Shared.Managers;
using UnityEngine;

Expand All @@ -20,6 +22,7 @@ public override void Awake()
{
base.Awake();
RefreshSupporters();
RpcMessageQueue.Instance.RegisterHandler(RequestHandlerConstants.REQUEST_SUPPORTERS, CurrentSupportersToJson);
}

public void RefreshSupporters()
Expand All @@ -38,13 +41,17 @@ public void RefreshSupporters()
}
}

private string CurrentSupportersToJson()
{
return JsonConvert.SerializeObject(SupporterList);
}

public static Tuple<bool, Supporter?> IsSupporter(PlayerInfo player)
{
foreach (var supporter in Instance.SupporterList)
{
#if UNITY_EDITOR
if (player.Username == supporter.Identifier) return new Tuple<bool, Supporter?>(true, supporter);
Debug.Log($"{player.Username} == {supporter.Identifier}: {player.Username == supporter.Identifier}");
#endif
if (player.AccountId == supporter.Identifier) return new Tuple<bool, Supporter?>(true, supporter);
}
Expand Down
3 changes: 3 additions & 0 deletions UnityProject/Assets/Scripts/UI/Systems/PreRound/Floating.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using TMPro;
using UnityEngine;

namespace UI.Systems.PreRound.Floating
{
public sealed class FloatingLabel : MonoBehaviour
{
[SerializeField] private TMP_Text _uiLabel;
private float _showDotThreshold = 0.65f;
private float _mouseProximityThreshold = 320f; // pixels
private Camera cam;

private void Awake()
{
if (_uiLabel == null)
_uiLabel = GetComponentInChildren<TMP_Text>();

cam = Camera.main;
}

private void Update()
{
UpdateVisibility();
}

public void UpdateVisibility()
{
if (!cam) return;
Vector2 mousePos = Input.mousePosition;
Vector2 elementScreenPos = RectTransformUtility.WorldToScreenPoint(null, transform.position);
float distance = Vector2.Distance(elementScreenPos, mousePos);
_uiLabel.SetActive(distance <= _mouseProximityThreshold);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using UnityEngine;
using UnityEngine.UI;

namespace UI.Systems.PreRound.Floating
{
public sealed class FloatingMover : MonoBehaviour
{
private Vector3 moveDirection;
private float speed;
private System.Action onFinished;
private RectTransform _rectTransform;
private bool _isUI;
private float rotationSpeed;
private float currentAngle;

private Image _image;
private FloatingLabel _floatingLabel;
private float labelOffset = 40f;
private float showDotThreshold = 0.65f; // cos(angle). ~50-55 degrees
private float lifetime = 0;

public void Initialize(Vector3 targetWorldOrLocal, float moveSpeed, System.Action onFinishedCallback, Image img, float rotationSpeedDegPerSec = 90f)
{
speed = moveSpeed;
onFinished = onFinishedCallback;
_rectTransform = GetComponent<RectTransform>();
_isUI = _rectTransform != null && _rectTransform.GetComponentInParent<Canvas>() != null;
rotationSpeed = rotationSpeedDegPerSec;
currentAngle = 0f;
Vector3 startPosition = _isUI && _rectTransform != null
? _rectTransform.anchoredPosition
: transform.position;
moveDirection = (targetWorldOrLocal - startPosition).normalized;
_image = img;
}

private void LateUpdate()
{
if (speed <= 0f) return;

var dt = Time.deltaTime;
lifetime += dt;

currentAngle += rotationSpeed * dt;
_image.transform.localEulerAngles = new Vector3(0f, 0f, currentAngle);

Vector3 nextPos = (_isUI && _rectTransform != null
? _rectTransform.anchoredPosition
: transform.position) + moveDirection * speed * dt;

if (_isUI && _rectTransform != null)
{
_rectTransform.anchoredPosition = new Vector2(nextPos.x, nextPos.y);
}
else
{
transform.position = nextPos;
}

if (IsOffScreen())
{
Finish();
}
}

private bool IsOffScreen()
{
if (lifetime < 30f) return false;
if (_isUI && _rectTransform != null)
{
var canvas = _rectTransform.GetComponentInParent<Canvas>();
if (canvas == null) return true;

var canvasRect = canvas.GetComponent<RectTransform>();
var pos = _rectTransform.anchoredPosition;

// Add a small margin for off-screen detection
float margin = 50f;
return pos.x < -canvasRect.rect.width / 2 - margin ||
pos.x > canvasRect.rect.width / 2 + margin ||
pos.y < -canvasRect.rect.height / 2 - margin ||
pos.y > canvasRect.rect.height / 2 + margin;
}
else
{
// For world space objects, use camera frustum
var cam = Camera.main;
if (cam == null) return true;
return !cam.isActiveAndEnabled || !GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(cam), new Bounds(transform.position, Vector3.one * 0.1f));
}
}

private void Finish()
{
onFinished?.Invoke();
Destroy(gameObject);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading