170 lines
3.6 KiB
C#
170 lines
3.6 KiB
C#
|
|
using System.Collections.Generic;
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Data;
|
|
using VRC.SDK3.StringLoading;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common.Interfaces;
|
|
using VRC.Udon.Serialization.OdinSerializer.Utilities;
|
|
|
|
|
|
public enum QuestionType
|
|
{
|
|
BetweenRounds,
|
|
MultipleChoice,
|
|
LightningRound,
|
|
DumpsterDive,
|
|
TheChase,
|
|
FinalRound,
|
|
Tiebreaker
|
|
}
|
|
|
|
public enum MusicEventType
|
|
{
|
|
None,
|
|
TheChase,
|
|
ThinkAboutIt,
|
|
WhereInTheWorld,
|
|
RockapellaIdent
|
|
}
|
|
|
|
public enum SFXEventType
|
|
{
|
|
None,
|
|
Ding,
|
|
Buzzer
|
|
}
|
|
|
|
|
|
public class GameManagerBase : UdonSharpBehaviour
|
|
{
|
|
[UdonSynced] protected bool _GameHasBegun = false;
|
|
|
|
[SerializeField] protected HostCardManager _HostCard = null;
|
|
|
|
[SerializeField] protected VRCUrl _QuestionURL;
|
|
|
|
private bool _AllowInteractionFromHostCard = false;
|
|
|
|
|
|
void Start()
|
|
{
|
|
InitialiseGameMode();
|
|
}
|
|
|
|
protected void EnableInteraction(string NextInteraction = "Advance")
|
|
{
|
|
_AllowInteractionFromHostCard = true;
|
|
_HostCard.SetNextInteractionText(NextInteraction);
|
|
}
|
|
protected void DisableInteraction()
|
|
{
|
|
_AllowInteractionFromHostCard = false;
|
|
}
|
|
|
|
public bool IsInteractionEnabled()
|
|
{
|
|
return _AllowInteractionFromHostCard;
|
|
}
|
|
|
|
public void HostCardUseButtonDown()
|
|
{
|
|
if (!IsInteractionEnabled()) { return; }
|
|
|
|
_HostCardUseButtonDown_Internal();
|
|
}
|
|
|
|
protected HostCardInterfaceBase GetHostCardInterface(QuestionType Type)
|
|
{
|
|
return _HostCard.EnableHostCardDisplay(Type);
|
|
}
|
|
|
|
protected virtual void _HostCardUseButtonDown_Internal()
|
|
{
|
|
Debug.LogError("You should not be seeing this. You don't need to call base._HostCardUseButtonDown_Internal()");
|
|
}
|
|
|
|
|
|
protected virtual void InitialiseGameMode()
|
|
{
|
|
// Download our test question.
|
|
VRCStringDownloader.LoadUrl(_QuestionURL, (IUdonEventReceiver)this);
|
|
}
|
|
|
|
|
|
public override void OnStringLoadSuccess(IVRCStringDownload DownloadedString)
|
|
{
|
|
string ErrorString = "";
|
|
string JSONString = DownloadedString.Result;
|
|
if (VRCJson.TryDeserializeFromJson(JSONString, out DataToken JSONResult))
|
|
{
|
|
if (JSONResult.TokenType == TokenType.DataDictionary)
|
|
{
|
|
DataDictionary Dict = JSONResult.DataDictionary;
|
|
|
|
if (!Dict.ContainsKey("Round 1") || !Dict.ContainsKey("Round 2") || !Dict.ContainsKey("Round 3"))
|
|
{
|
|
ErrorString = "Could not find all the necessary keys for game rounds.";
|
|
}
|
|
else
|
|
{
|
|
// Attempt to load Round 1 data
|
|
if (Dict["Round 1"].TokenType == TokenType.DataList)
|
|
{
|
|
LoadQuestionData(Dict["Round 1"].DataList);
|
|
}
|
|
else
|
|
{
|
|
ErrorString = "Ensure the 'Round 1' entry is an array of dictionaries.";
|
|
}
|
|
|
|
// Attempt to load Round 2 data
|
|
if (Dict["Round 2"].TokenType == TokenType.DataList)
|
|
{
|
|
// LoadQuestionData(Dict["Round 2"].DataList);
|
|
}
|
|
else
|
|
{
|
|
ErrorString = "Ensure the 'Round 2' entry is a dictionary with a location name and landmarks.";
|
|
}
|
|
|
|
// Attempt to load Round 2 data
|
|
if (Dict["Round 3"].TokenType == TokenType.DataList)
|
|
{
|
|
// LoadQuestionData(Dict["Round 3"].DataList);
|
|
}
|
|
else
|
|
{
|
|
// ErrorString = "Ensure the 'Round 3' dictionary entry is a list of dictionaries.";
|
|
}
|
|
}
|
|
|
|
if (Dict.ContainsKey("Round 1"))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
ErrorString = "Ensure the first element is a dictionary, containing 'Round 1', 'Round 2', and 'Round 3' entries.";
|
|
}
|
|
|
|
if (Dict.ContainsKey("Round 2"))
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ErrorString = "Ensure the first element is a dictionary";
|
|
}
|
|
}
|
|
|
|
if (ErrorString != "")
|
|
{
|
|
Debug.LogError("Malformed case file. " + ErrorString);
|
|
}
|
|
}
|
|
|
|
protected virtual void LoadQuestionData(DataList Data) {}
|
|
}
|