Score UI and Color Coded Deduction, EdgePanning
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:
|
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
// }
|
||||
//}
|
||||
|
Loading…
Reference in New Issue