feat: Add quiz scene with scoreboard, team machine, door, and player management systems.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using UdonSharp;
|
||||
using System;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
using System;
|
||||
using VRRefAssist;
|
||||
|
||||
[Singleton]
|
||||
public class PlayerManager : UdonSharpBehaviour
|
||||
{
|
||||
[UdonSynced] public int[] playerIds = new int[0];
|
||||
@@ -124,7 +126,7 @@ public class PlayerManager : UdonSharpBehaviour
|
||||
}
|
||||
|
||||
// Team Management Methods
|
||||
public void AssignTeam(int playerId, string team)
|
||||
public void SetTeam(int playerId, string team)
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject)) return;
|
||||
|
||||
@@ -139,6 +141,38 @@ public class PlayerManager : UdonSharpBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRandomViableTeam()
|
||||
{
|
||||
int redCount = 0;
|
||||
int blueCount = 0;
|
||||
|
||||
for (int i = 0; i < currentPlayerIds.Length; i++)
|
||||
{
|
||||
string team = GetTeam(currentPlayerIds[i]);
|
||||
if (team == "red") redCount++;
|
||||
else if (team == "blue") blueCount++;
|
||||
}
|
||||
|
||||
float half = currentPlayerIds.Length / 2f;
|
||||
bool canJoinRed = redCount < half;
|
||||
bool canJoinBlue = blueCount < half;
|
||||
|
||||
if (canJoinRed && canJoinBlue)
|
||||
{
|
||||
return UnityEngine.Random.Range(0, 2) == 0 ? "red" : "blue";
|
||||
}
|
||||
else if (canJoinRed)
|
||||
{
|
||||
return "red";
|
||||
}
|
||||
else if (canJoinBlue)
|
||||
{
|
||||
return "blue";
|
||||
}
|
||||
|
||||
return "unassigned";
|
||||
}
|
||||
|
||||
public string GetTeam(int playerId)
|
||||
{
|
||||
int index = GetPlayerIndex(playerId);
|
||||
@@ -165,7 +199,6 @@ public class PlayerManager : UdonSharpBehaviour
|
||||
return members;
|
||||
}
|
||||
|
||||
// Helper Methods
|
||||
private int GetPlayerIndex(int playerId)
|
||||
{
|
||||
for (int i = 0; i < playerIds.Length; i++)
|
||||
|
||||
Reference in New Issue
Block a user