82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.Core.Pool;
|
|
using VRC.SDK3.Components;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class LetterStack : UdonSharpBehaviour
|
|
{
|
|
public Transform letterSpawnPoint;
|
|
public VRCObjectPool letterPool;
|
|
[SerializeField] private string[] letters = { "A", "E", "I", "O", "U" };
|
|
[SerializeField] private int[] counts = { 15, 21, 13, 13, 5 };
|
|
[SerializeField] private string[] availableLetters;
|
|
|
|
void Start()
|
|
{
|
|
InitLetterPool();
|
|
}
|
|
|
|
public void InitLetterPool()
|
|
{
|
|
int total = 0;
|
|
for (int i = 0; i < counts.Length; i++)
|
|
{
|
|
total += counts[i];
|
|
}
|
|
availableLetters = new string[total];
|
|
int idx = 0;
|
|
for (int i = 0; i < letters.Length; i++)
|
|
{
|
|
for (int j = 0; j < counts[i]; j++)
|
|
{
|
|
availableLetters[idx++] = letters[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SpawnLetter()
|
|
{
|
|
if (availableLetters.Length == 0) return;
|
|
|
|
int rand = Random.Range(0, availableLetters.Length);
|
|
string selectedLetter = availableLetters[rand];
|
|
|
|
GameObject newLetter = letterPool.TryToSpawn();
|
|
if (newLetter != null)
|
|
{
|
|
newLetter.transform.position = letterSpawnPoint.position;
|
|
newLetter.transform.rotation = letterSpawnPoint.rotation;
|
|
newLetter.GetComponent<LetterCard>().SetLetter(selectedLetter);
|
|
}
|
|
// Remove the selected letter
|
|
string[] newAvailable = new string[availableLetters.Length - 1];
|
|
int newIdx = 0;
|
|
for (int i = 0; i < availableLetters.Length; i++)
|
|
{
|
|
if (i != rand)
|
|
{
|
|
newAvailable[newIdx++] = availableLetters[i];
|
|
}
|
|
}
|
|
availableLetters = newAvailable;
|
|
}
|
|
|
|
public void ResetLetters()
|
|
{
|
|
InitLetterPool();
|
|
for (int i = 0; i < letterPool.Pool.Length; i++)
|
|
{
|
|
letterPool.Return(letterPool.Pool[i]);
|
|
}
|
|
}
|
|
|
|
public override void Interact()
|
|
{
|
|
SpawnLetter();
|
|
}
|
|
}
|