debug view working
This commit is contained in:
@@ -0,0 +1,280 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
|
||||
m_Name: PlayerManager Udon C# Program Asset
|
||||
m_EditorClassIdentifier:
|
||||
serializedUdonProgramAsset: {fileID: 11400000, guid: 6df9f9dc437f4c14e97425edea24e74a, type: 2}
|
||||
udonAssembly:
|
||||
assemblyError:
|
||||
sourceCsScript: {fileID: 11500000, guid: 3a37906412e429a43b713872bbb5f463, type: 3}
|
||||
scriptVersion: 2
|
||||
compiledVersion: 2
|
||||
behaviourSyncMode: 0
|
||||
hasInteractEvent: 0
|
||||
scriptID: -3107121390503143711
|
||||
serializationData:
|
||||
SerializedFormat: 2
|
||||
SerializedBytes:
|
||||
ReferencedUnityObjects: []
|
||||
SerializedBytesString:
|
||||
Prefab: {fileID: 0}
|
||||
PrefabModificationsReferencedUnityObjects: []
|
||||
PrefabModifications: []
|
||||
SerializationNodes:
|
||||
- Name: fieldDefinitions
|
||||
Entry: 7
|
||||
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
|
||||
UdonSharp.Editor]], mscorlib
|
||||
- Name: comparer
|
||||
Entry: 7
|
||||
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
|
||||
mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 4
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: playerIds
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: playerIds
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 7
|
||||
Data: 3|System.RuntimeType, mscorlib
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: System.Int32[], mscorlib
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 3
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 3
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: true
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 4|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data: 5|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: playerScores
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: playerScores
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 3
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 3
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 3
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 7|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data: 8|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: playerTeams
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: playerTeams
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 7
|
||||
Data: 10|System.RuntimeType, mscorlib
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: System.String[], mscorlib
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 10
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 3
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 11|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data: 12|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: currentPlayerIds
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: currentPlayerIds
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 3
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 3
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 3
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: true
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 14|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 1
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data: 15|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9c42919de20f12409bca49705e9f328
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
171
Assets/Quiz/Scripts/Managers/PlayerManager.cs
Normal file
171
Assets/Quiz/Scripts/Managers/PlayerManager.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
using System;
|
||||
|
||||
public class PlayerManager : UdonSharpBehaviour
|
||||
{
|
||||
[UdonSynced] public int[] playerIds = new int[0];
|
||||
[UdonSynced] private int[] playerScores = new int[0];
|
||||
[UdonSynced] private string[] playerTeams = new string[0];
|
||||
[UdonSynced] public int[] currentPlayerIds = new int[0];
|
||||
|
||||
public override void OnPlayerJoined(VRCPlayerApi player)
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject)) return;
|
||||
|
||||
int id = player.playerId;
|
||||
int index = GetPlayerIndex(id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
int[] newIds = new int[playerIds.Length + 1];
|
||||
int[] newScores = new int[playerScores.Length + 1];
|
||||
string[] newTeams = new string[playerTeams.Length + 1];
|
||||
|
||||
Array.Copy(playerIds, newIds, playerIds.Length);
|
||||
Array.Copy(playerScores, newScores, playerScores.Length);
|
||||
Array.Copy(playerTeams, newTeams, playerTeams.Length);
|
||||
|
||||
newIds[playerIds.Length] = id;
|
||||
newScores[playerScores.Length] = 0;
|
||||
newTeams[playerTeams.Length] = "unassigned";
|
||||
|
||||
playerIds = newIds;
|
||||
playerScores = newScores;
|
||||
playerTeams = newTeams;
|
||||
}
|
||||
|
||||
// Add to current players
|
||||
int[] newCurrentIds = new int[currentPlayerIds.Length + 1];
|
||||
Array.Copy(currentPlayerIds, newCurrentIds, currentPlayerIds.Length);
|
||||
newCurrentIds[currentPlayerIds.Length] = id;
|
||||
currentPlayerIds = newCurrentIds;
|
||||
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public override void OnPlayerLeft(VRCPlayerApi player)
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject)) return;
|
||||
|
||||
// Remove from current players
|
||||
int[] newCurrentIds = new int[currentPlayerIds.Length - 1];
|
||||
int j = 0;
|
||||
for (int i = 0; i < currentPlayerIds.Length; i++)
|
||||
{
|
||||
if (currentPlayerIds[i] != player.playerId)
|
||||
{
|
||||
newCurrentIds[j] = currentPlayerIds[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
currentPlayerIds = newCurrentIds;
|
||||
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public void SetScore(int playerId, int score)
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject)) return;
|
||||
|
||||
for (int i = 0; i < playerIds.Length; i++)
|
||||
{
|
||||
if (playerIds[i] == playerId)
|
||||
{
|
||||
playerScores[i] = score;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public int GetScore(int playerId)
|
||||
{
|
||||
for (int i = 0; i < playerIds.Length; i++)
|
||||
{
|
||||
if (playerIds[i] == playerId)
|
||||
{
|
||||
return playerScores[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void AddScore(int playerId, int increment)
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject)) return;
|
||||
|
||||
for (int i = 0; i < playerIds.Length; i++)
|
||||
{
|
||||
if (playerIds[i] == playerId)
|
||||
{
|
||||
playerScores[i] += increment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public VRCPlayerApi[] GetCurrentPlayers()
|
||||
{
|
||||
VRCPlayerApi[] players = new VRCPlayerApi[currentPlayerIds.Length];
|
||||
for (int i = 0; i < currentPlayerIds.Length; i++)
|
||||
{
|
||||
players[i] = VRCPlayerApi.GetPlayerById(currentPlayerIds[i]);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
// Team Management Methods
|
||||
public void AssignTeam(int playerId, string team)
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject)) return;
|
||||
|
||||
if (team != "red" && team != "blue" && team != "unassigned") return;
|
||||
|
||||
int index = GetPlayerIndex(playerId);
|
||||
if (index >= 0)
|
||||
{
|
||||
playerTeams[index] = team;
|
||||
RequestSerialization();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetTeam(int playerId)
|
||||
{
|
||||
int index = GetPlayerIndex(playerId);
|
||||
return index >= 0 ? playerTeams[index] : "unassigned";
|
||||
}
|
||||
|
||||
public int[] GetTeamMembers(string team)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < playerTeams.Length; i++)
|
||||
{
|
||||
if (playerTeams[i] == team) count++;
|
||||
}
|
||||
|
||||
int[] members = new int[count];
|
||||
int j = 0;
|
||||
for (int i = 0; i < playerTeams.Length; i++)
|
||||
{
|
||||
if (playerTeams[i] == team)
|
||||
{
|
||||
members[j++] = playerIds[i];
|
||||
}
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
// Helper Methods
|
||||
private int GetPlayerIndex(int playerId)
|
||||
{
|
||||
for (int i = 0; i < playerIds.Length; i++)
|
||||
{
|
||||
if (playerIds[i] == playerId) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
11
Assets/Quiz/Scripts/Managers/PlayerManager.cs.meta
Normal file
11
Assets/Quiz/Scripts/Managers/PlayerManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a37906412e429a43b713872bbb5f463
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user