Score UI and Color Coded Deduction, EdgePanning

dev-ali
Ali Sharoz 2 days ago
parent 584764676c
commit ce47f7515b

@ -0,0 +1,40 @@
using UnityEngine;
using Cinemachine;
public class EdgePanningController: MonoBehaviour
{
public CinemachineFreeLook virtualCamera;
private CinemachineCameraOffset cameraOffset;
public float edgeThreshold = 50f; // Edge detection distance
public float panSpeed = 0.1f; // How much to offset per frame
private Vector3 defaultOffset;
private void Start()
{
cameraOffset = virtualCamera.GetComponent<CinemachineCameraOffset>();
defaultOffset = cameraOffset.m_Offset; // Store default offset
}
private void Update()
{
Vector3 newOffset = defaultOffset;
Vector3 mousePos = Input.mousePosition;
float screenWidth = Screen.width;
float screenHeight = Screen.height;
// Left Edge
if (mousePos.x <= edgeThreshold) newOffset.x -= panSpeed;
// Right Edge
if (mousePos.x >= screenWidth - edgeThreshold) newOffset.x += panSpeed;
// Bottom Edge
if (mousePos.y <= edgeThreshold) newOffset.y -= panSpeed;
// Top Edge
if (mousePos.y >= screenHeight - edgeThreshold) newOffset.y += panSpeed;
// Smooth transition
cameraOffset.m_Offset = Vector3.Lerp(cameraOffset.m_Offset, newOffset, Time.deltaTime * 5f);
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9ef4e6fc7be9fb34fad425efb2b1d169
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1ea5a06766f2d924aba28a422e7d0d77
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -467,7 +467,7 @@ GameObject:
- component: {fileID: 5210474333085558486}
- component: {fileID: 5210474333085558483}
m_Layer: 5
m_Name: PartyHUD
m_Name: PartyHUD(original)
m_TagString: PartyHUD
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

File diff suppressed because it is too large Load Diff

@ -372,7 +372,7 @@ public class AbilitySystem : NetworkBehaviour
}
[ServerRpc(RequireOwnership = false)]
private void RequestAbilityActivationServerRpc(string abilityKey, Vector3 targetPosition, Vector3 targetRotation, ServerRpcParams rpcParams = default)
public void RequestAbilityActivationServerRpc(string abilityKey, Vector3 targetPosition, Vector3 targetRotation, ServerRpcParams rpcParams = default)
{
ulong ownerClientId = rpcParams.Receive.SenderClientId;
Debug.Log($"[AbilitySystem] Received activation request for ability '{abilityKey}' from client {ownerClientId}.");

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
public class CrowsForesightPrefab : NetworkBehaviour
{
@ -85,20 +86,20 @@ public class CrowsForesightPrefab : NetworkBehaviour
}
public void OnSwapAccepted(ulong senderId, Vector3 receiverPos)
{
{
Debug.Log($"[CrowsForesightPrefab] OnSwapAccepted - Sender: {senderId}, ReceiverPos: {receiverPos}");
if (!foresightLines.ContainsKey(senderId))
{
Debug.LogError($"[CrowsForesightPrefab] ERROR: No foresight line found for sender {senderId} when swap was accepted!");
return;
}
foresightLines[senderId].SetPosition(1, receiverPos);
if (foresightLines.ContainsKey(senderId))
{
// Destroy the line associated with the sender
Destroy(foresightLines[senderId].gameObject ,1f);
Destroy(foresightLines[senderId].gameObject, 1f);
foresightLines.Remove(senderId);
Debug.Log($"[CrowsForesightPrefab] Removed foresight line for rejected swap request from {senderId}.");
@ -106,7 +107,7 @@ public class CrowsForesightPrefab : NetworkBehaviour
Debug.Log($"[CrowsForesightPrefab] Foresight line completed from sender {senderId} to {receiverPos}.");
}
public void OnSwapRejected(ulong senderId, Vector3 receiverPos)
{
Debug.Log($"[CrowsForesightPrefab] OnSwapRejected - Sender: {senderId}, ReceiverPos: {receiverPos}");
@ -125,7 +126,7 @@ public class CrowsForesightPrefab : NetworkBehaviour
}
}
private LineRenderer CreateLine()
{
//GameObject lineObj = new GameObject("ForesightLine");

@ -43,8 +43,8 @@ public class ExecutionerBox : NetworkBehaviour
ulong ownerId = _owner.OwnerClientId;
// Handle score changes
ScoreManager.Instance.AddPlayerScore(ownerId, 10); // Add to owner
ScoreManager.Instance.SubtractPlayerScore(victim.OwnerClientId, 10); // Subtract from victim
ScoreManager.Instance.AddPlayerScore(ownerId, 10,Color.yellow); // Add to owner
ScoreManager.Instance.SubtractPlayerScore(victim.OwnerClientId, 10,new Color(1,0.647f,0,1)); // Subtract from victim
Debug.Log($"[ExecutionerBox] Scores updated. " +
$"Owner ({ownerId}) gained 10, " +

@ -165,6 +165,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
m_State = GetComponent<NetworkAvatarGuidState>();
uIStateDisplayHandler = GetComponent<UIStateDisplayHandler>();
heroActionBar = FindObjectOfType<HeroActionBar>();
abilitySystem = GetComponent<AbilitySystem>();
}
//Hazim
@ -231,16 +232,16 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
[ClientRpc]
private void UpdateCrowStatusClientRpc(bool status)
{
if (IsOwner==false)
if (IsOwner == false)
{
return;
}
IsCrow = status; // Update the value for all clients
if(heroActionBar==null)
if (heroActionBar == null)
{
Debug.Log("Hero action bar was null");
heroActionBar=FindObjectOfType<HeroActionBar>();
heroActionBar = FindObjectOfType<HeroActionBar>();
}
foreach (var button in heroActionBar.OtherButtons)
@ -421,19 +422,18 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
AbilitySystem abilitySystem;
[Rpc(SendTo.Server, RequireOwnership = false)]
public void NotifySwapRequestRpc(ulong senderId, string senderName)
{
PendingSwapRequest = senderId;
ShowSwapConfirmationPanelClientRpc(senderName);
//ShowSwapConfirmationPanelClientRpc(senderName);
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(senderId, out var senderObj) &&
senderObj.TryGetComponent(out ServerCharacter senderChar))
{
Vector3 senderPos = senderChar.transform.position;
Vector3 receiverPos = transform.position;
CrowManager.Instance.NotifyForesightSwap(senderChar.OwnerClientId, OwnerClientId, senderPos, receiverPos);
}
}

@ -282,7 +282,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
if (occupationTime >= 10f)
{
yield return new WaitForSeconds(penaltyInterval);
ScoreManager.Instance.SubtractPlayerScore(player.OwnerClientId, 10);
ScoreManager.Instance.SubtractPlayerScore(player.OwnerClientId, 10,Color.red);
}
yield return null;

@ -11,5 +11,10 @@ using TMPro;
public ulong PlayerClientID;
public TextMeshProUGUI PlayerName;
public TextMeshProUGUI PlayerScore;
private void Start()
{
}
}
//}

@ -12,7 +12,7 @@ public class ScoreManager : NetworkBehaviour
public Dictionary<ulong, int> playerScores = new Dictionary<ulong, int>();
public Dictionary<ulong, string> playerNames = new Dictionary<ulong, string>();
public static Action<ulong, int> OnScoreUpdated;
public static Action<ulong, int,Color> OnScoreUpdated;
private void Awake()
{
if (Instance != null && Instance != this)
@ -59,7 +59,7 @@ public class ScoreManager : NetworkBehaviour
Debug.Log($"[ScoreManager] Synced Player {ownerClientId} data: Name = {playerName}, Score = {score}");
// Update the scoreboard
Scoreboard.instance.InitializeScoreboardItem(ownerClientId, score, playerName);
Scoreboard.Instance.InitializeScoreboardItem(ownerClientId, score, playerName);
}
public void UpdatePlayerScore(ulong ownerClientId, int newScore)
@ -82,7 +82,7 @@ public class ScoreManager : NetworkBehaviour
if (playerNames.TryGetValue(ownerClientId, out var playerName))
{
Debug.Log($"[ScoreManager] Received score update for Player {ownerClientId} (Name: {playerName}): {newScore}");
Scoreboard.instance.UpdateScoreboard(playerName, newScore);
Scoreboard.Instance.UpdateScoreboard(ownerClientId, newScore);
}
else
{
@ -91,31 +91,30 @@ public class ScoreManager : NetworkBehaviour
}
}
public void AddPlayerScore(ulong ownerClientId, int scoreToAdd)
public void AddPlayerScore(ulong ownerClientId, int scoreToAdd, Color color = default)
{
if (playerScores.ContainsKey(ownerClientId))
{
OnScoreUpdateInvokerClientRpc(ownerClientId, scoreToAdd);
OnScoreUpdateInvokerClientRpc(ownerClientId, scoreToAdd, color);
//OnScoreUpdated?.Invoke(ownerClientId, playerScores[ownerClientId]);
playerScores[ownerClientId] += scoreToAdd;
UpdatePlayerScore(ownerClientId, playerScores[ownerClientId]);
}
}
public void SubtractPlayerScore(ulong ownerClientId, int scoreToSubtract)
public void SubtractPlayerScore(ulong ownerClientId, int scoreToSubtract, Color color = default)
{
if (playerScores.TryGetValue(ownerClientId, out var score))
{
OnScoreUpdateInvokerClientRpc(ownerClientId, -scoreToSubtract);
OnScoreUpdateInvokerClientRpc(ownerClientId, -scoreToSubtract, color);
int newScore = Mathf.Max(0, score - scoreToSubtract);
UpdatePlayerScore(ownerClientId, newScore);
}
}
[ClientRpc]
void OnScoreUpdateInvokerClientRpc(ulong id, int score)
void OnScoreUpdateInvokerClientRpc(ulong id, int score, Color color = default)
{
OnScoreUpdated?.Invoke(id, score);
OnScoreUpdated?.Invoke(id, score,color);
}
public void StartCrowPenaltyCoroutine()
{
@ -144,7 +143,7 @@ public class ScoreManager : NetworkBehaviour
// Apply the penalties after the iteration
foreach (ulong clientId in clientsToModify)
{
SubtractPlayerScore(clientId, 2);
SubtractPlayerScore(clientId, 2,Color.red);
Debug.Log($"[ScoreManager] Applied crow penalty to Player {clientId}. New score: {playerScores[clientId]}");
}

@ -1,56 +1,145 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Multiplayer.Samples.BossRoom;
using UnityEngine;
using Unity.Netcode;
using System.Linq;
public class Scoreboard : NetworkBehaviour
{
public List<PlayerItem> dummyPlayerItems;
public List<PlayerItem> playerItems = new();
private List<PlayerItem> playerItemsForSort = new();
public GameObject playerItemPrefab;
public Transform Parent, FinalParent;
public GameObject FinalLeaderBoardObj;
public static Scoreboard instance;
private bool coroutineStarter = false;
private void Awake() => instance = this;
public static Scoreboard Instance { get; private set; }
private int counter = 0;
private void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
private void Start()
{
counter = 1;
}
public void InitializeScoreboardItem(ulong clientId, int score, string name)
{
var item = Instantiate(playerItemPrefab, Parent).GetComponent<PlayerItem>();
if (counter >= dummyPlayerItems.Count) return;
var item = (NetworkManager.Singleton.LocalClientId == clientId)
? dummyPlayerItems[0]
: dummyPlayerItems[counter++];
item.gameObject.SetActive(true);
item.PlayerName.text = name;
item.PlayerScore.text = score.ToString();
item.PlayerClientID = clientId;
playerItems.Add(item);
if (NetworkManager.Singleton.LocalClientId != clientId)
playerItemsForSort.Add(item);
}
public void UpdateScoreboard(string playerName, int score, ClientRpcParams clientRpcParams = default)
public void UpdateScoreboard(ulong id, int score, ClientRpcParams clientRpcParams = default)
{
foreach (var item in playerItems)
{
if (item.PlayerName.text == playerName)
if (item.PlayerClientID == id)
{
item.PlayerScore.text = score.ToString();
if (NetworkManager.Singleton.LocalClientId == item.PlayerClientID)
item.PlayerScore.color = Color.green;
break;
}
if (NetworkManager.Singleton.LocalClientId == item.PlayerClientID)
item.PlayerScore.color = Color.green;
}
SortAndUpdateScoreboard();
//var item = playerItems.FirstOrDefault(p => p.PlayerClientID == id);
//if (item != null) item.PlayerScore.text = score.ToString();
//SortAndUpdateScoreboard();
}
public void FinalLeaderBoard()
{
if (IsServer) FinalLeaderBoardClientRPC();
}
[ClientRpc]
public void FinalLeaderBoardClientRPC()
private void FinalLeaderBoardClientRPC()
{
playerItems.ForEach(item => Instantiate(item.gameObject, FinalParent));
Debug.Log("FinalLeaderBoardClientRPC");
playerItems.ForEach(item => Instantiate(item, FinalParent).gameObject.SetActive(true));
FinalLeaderBoardObj.SetActive(true);
}
private void SortAndUpdateScoreboard()
{
playerItems.Sort((p1, p2) => int.Parse(p2.PlayerScore.text).CompareTo(int.Parse(p1.PlayerScore.text)));
for (int i = 0; i < playerItems.Count; i++) playerItems[i].transform.SetSiblingIndex(i);
playerItemsForSort = playerItemsForSort
.OrderByDescending(p => int.Parse(p.PlayerScore.text))
.ToList();
for (int i = 0; i < playerItemsForSort.Count; i++)
playerItemsForSort[i].transform.SetSiblingIndex(i);
}
}
//using System.Collections;
//using System.Collections.Generic;
//using Unity.Multiplayer.Samples.BossRoom;
//using UnityEngine;
//using Unity.Netcode;
//public class Scoreboard : NetworkBehaviour
//{
// public List<PlayerItem> playerItems = new();
// public GameObject playerItemPrefab;
// public Transform Parent, FinalParent;
// public GameObject FinalLeaderBoardObj;
// public static Scoreboard Instance;
// private bool coroutineStarter = false;
// private void Awake() => Instance = this;
// public void InitializeScoreboardItem(ulong clientId, int score, string name)
// {
// var item = Instantiate(playerItemPrefab, Parent).GetComponent<PlayerItem>();
// item.PlayerName.text = name;
// item.PlayerScore.text = score.ToString();
// item.PlayerClientID = clientId;
// playerItems.Add(item);
// }
// public void UpdateScoreboard(ulong id, int score, ClientRpcParams clientRpcParams = default)
// {
// foreach (var item in playerItems)
// {
// if (item.PlayerClientID == id)
// {
// item.PlayerScore.text = score.ToString();
// if (NetworkManager.Singleton.LocalClientId == item.PlayerClientID)
// item.PlayerScore.color = Color.green;
// break;
// }
// }
// SortAndUpdateScoreboard();
// }
// public void FinalLeaderBoard()
// {
// if (IsServer) FinalLeaderBoardClientRPC();
// }
// [ClientRpc]
// public void FinalLeaderBoardClientRPC()
// {
// playerItems.ForEach(item => Instantiate(item.gameObject, FinalParent));
// FinalLeaderBoardObj.SetActive(true);
// }
// private void SortAndUpdateScoreboard()
// {
// playerItems.Sort((p1, p2) => int.Parse(p2.PlayerScore.text).CompareTo(int.Parse(p1.PlayerScore.text)));
// for (int i = 0; i < playerItems.Count; i++) playerItems[i].transform.SetSiblingIndex(i);
// }
//}

@ -24,15 +24,16 @@ namespace Unity.BossRoom.Gameplay.UI
/// Initializes the floating score effect.
/// </summary>
/// <param name="change">The amount by which the score changed.</param>
public void Initialize(int change)
public void Initialize(int change,Color color=default)
{
color = color == default ? Color.green : color;
// Set the text to display the score change, adding a '+' for positive changes.
if (change >= 0)
{
scoreChangeText.text = $"+{change}";
scoreChangeText.fontMaterial = new Material(scoreChangeText.fontSharedMaterial);
scoreChangeText.fontMaterial.SetFloat("_OutlineWidth", 0.5f);
scoreChangeText.fontMaterial.SetColor("_OutlineColor", Color.green);
scoreChangeText.fontMaterial.SetColor("_OutlineColor", color);
//backgroundImage.color = new Color(0.66f, 1f, 0.38f, 1f); // Green for increases
}
else
@ -40,7 +41,7 @@ namespace Unity.BossRoom.Gameplay.UI
scoreChangeText.text = $"{change}";
scoreChangeText.fontMaterial = new Material(scoreChangeText.fontSharedMaterial);
scoreChangeText.fontMaterial.SetFloat("_OutlineWidth", 0.5f);
scoreChangeText.fontMaterial.SetColor("_OutlineColor", Color.red);
scoreChangeText.fontMaterial.SetColor("_OutlineColor", color);
//backgroundImage.color = new Color(1f, 0.4f, 0.38f, 1f); // Red for decreases
}
transform.DOLocalMove(Vector3.zero, 0.5f);

@ -3,6 +3,7 @@ using TMPro;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using Unity.BossRoom.Utils;
using Unity.Netcode;
using Unity.Services.Lobbies.Models;
using UnityEngine;
namespace Unity.BossRoom.Gameplay.UI
@ -61,24 +62,26 @@ namespace Unity.BossRoom.Gameplay.UI
// Called when the NetworkVariable changes.
private void OnScoreChanged(ulong oldScore, int newScore)
private void OnScoreChanged(ulong playerID, int newScore,Color color=default)
{
// Trigger a floating effect on all clients.
// Using a ClientRpc so that every client sees the same effect.
// if (NetworkManager.Singleton.IsServer)
{
RpcPlayScoreAnimationClientRpc(newScore, scoreEffectSpawnPoint);
RpcPlayScoreAnimationClientRpc(newScore, playerID,color);
}
}
// This ClientRpc will be executed on all clients.
[ClientRpc]
private void RpcPlayScoreAnimationClientRpc(int change, UnityEngine.Transform spawnPosition)
private void RpcPlayScoreAnimationClientRpc(int change, ulong playerID,Color color=default)
{
// Instantiate the floating score effect prefab on each client.
if (NetworkManager.Singleton.LocalClientId != playerID)
return; // Only the local player should see their own floating score
FloatingScore effect = Instantiate(floatingScorePrefab, m_PartyHUD.ScoreSpawnPos);
effect.transform.localPosition = Vector3.zero;
effect.transform.localEulerAngles= Vector3.zero;
effect.Initialize(change);
effect.transform.localEulerAngles = Vector3.zero;
effect.Initialize(change,color);
}
}
}

@ -35,7 +35,7 @@ public class TimerScript : MonoBehaviour
private void HandleTimerEnd()
{
Debug.Log("Timer has ended!");
Scoreboard.instance.FinalLeaderBoard();
Scoreboard.Instance.FinalLeaderBoard();
}
private void OnDestroy()

Loading…
Cancel
Save