Upload files to "Managers"
This commit is contained in:
1 parent
a3289ddec7
commit
1765940692
4 files changed
+188
No files matched your search
@@ -0,0 +1,41 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace GorillaCaptions.Managers;
|
||||||
|
|
||||||
|
public class AssetManager
|
||||||
|
{
|
||||||
|
private static AssetBundle assetBundle;
|
||||||
|
|
||||||
|
private static void LoadAssetBundle()
|
||||||
|
{
|
||||||
|
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GorillaCaptions.Resources.caption");
|
||||||
|
if (stream != null)
|
||||||
|
assetBundle = AssetBundle.LoadFromStream(stream);
|
||||||
|
else
|
||||||
|
Debug.LogError("Failed to load assetbundle");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T LoadObject<T>(string assetName) where T : Object
|
||||||
|
{
|
||||||
|
T gameObject = null;
|
||||||
|
|
||||||
|
if (assetBundle == null)
|
||||||
|
LoadAssetBundle();
|
||||||
|
|
||||||
|
gameObject = Object.Instantiate(assetBundle.LoadAsset<T>(assetName));
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T LoadAsset<T>(string assetName) where T : Object
|
||||||
|
{
|
||||||
|
T gameObject = null;
|
||||||
|
|
||||||
|
if (assetBundle == null)
|
||||||
|
LoadAssetBundle();
|
||||||
|
|
||||||
|
gameObject = assetBundle.LoadAsset(assetName) as T;
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using GorillaCaptions.Classes;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace GorillaCaptions.Managers;
|
||||||
|
|
||||||
|
public class BubbleManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static BubbleManager instance { get; private set; }
|
||||||
|
|
||||||
|
private GameObject BubbleAsset;
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
BubbleAsset = AssetManager.LoadAsset<GameObject>("SpeechBubble");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<VRRig, GameObject> SpeechBubbles = new();
|
||||||
|
public void SpawnBubble(VRRig Rig, string Text)
|
||||||
|
{
|
||||||
|
if (SpeechBubbles.TryGetValue(Rig, out GameObject ExistingBubble))
|
||||||
|
DestroyBubble(ExistingBubble);
|
||||||
|
|
||||||
|
GameObject TargetBubble = Instantiate(BubbleAsset);
|
||||||
|
TargetBubble.transform.SetParent(Rig.headMesh.transform, false);
|
||||||
|
TargetBubble.transform.Find("Canvas/Background/Text")
|
||||||
|
.GetComponent<TextMeshProUGUI>().text = Text;
|
||||||
|
TargetBubble.AddComponent<SpeechBubble>().Owner = Rig;
|
||||||
|
|
||||||
|
SpeechBubbles.Add(Rig, TargetBubble);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DestroyBubble(GameObject TargetBubble)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<VRRig, GameObject> SpeechBubble in SpeechBubbles)
|
||||||
|
{
|
||||||
|
if (SpeechBubble.Value == TargetBubble)
|
||||||
|
{
|
||||||
|
SpeechBubbles.Remove(SpeechBubble.Key);
|
||||||
|
Destroy(SpeechBubble.Value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GorillaCaptions.Managers;
|
||||||
|
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
public static string GetPlatform(this VRRig rig)
|
||||||
|
{
|
||||||
|
string platformProperty = (string)rig.creator.GetPlayerRef().CustomProperties["platform"];
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(platformProperty))
|
||||||
|
return platformProperty;
|
||||||
|
|
||||||
|
if (HasOwnedCosmetic(rig, "S. FIRST LOGIN"))
|
||||||
|
return "STEAM";
|
||||||
|
|
||||||
|
if (HasOwnedCosmetic(rig, "FIRST LOGIN") ||
|
||||||
|
rig.creator != null && rig.creator.GetPlayerRef().CustomProperties.Count > 3 ||
|
||||||
|
rig.currentRankedSubTierPC > 0)
|
||||||
|
return "PC";
|
||||||
|
|
||||||
|
return "Quest";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasOwnedCosmetic(VRRig rig, string cosmeticName)
|
||||||
|
{
|
||||||
|
if (rig._playerOwnedCosmetics == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach (string ownedCosmetic in rig._playerOwnedCosmetics)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ownedCosmetic))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ownedCosmetic.IndexOf(cosmeticName, StringComparison.Ordinal) >= 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace GorillaCaptions.Managers;
|
||||||
|
|
||||||
|
public class SynthesizerManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static SynthesizerManager instance { get; private set; }
|
||||||
|
public static string voskPath;
|
||||||
|
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
string resourcePath = "GorillaCaptions.Resources.QuickVosk.exe";
|
||||||
|
voskPath = Path.Combine(Path.GetTempPath(), "QuickVosk.exe");
|
||||||
|
|
||||||
|
if (File.Exists(voskPath))
|
||||||
|
File.Delete(voskPath);
|
||||||
|
|
||||||
|
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath);
|
||||||
|
using FileStream fs = new(voskPath, FileMode.Create, FileAccess.Write);
|
||||||
|
stream.CopyTo(fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> SynthesizeAudio(string audioPath)
|
||||||
|
{
|
||||||
|
ProcessStartInfo psi = new()
|
||||||
|
{
|
||||||
|
FileName = voskPath,
|
||||||
|
Arguments = audioPath,
|
||||||
|
UseShellExecute = false,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
CreateNoWindow = true
|
||||||
|
};
|
||||||
|
|
||||||
|
using Process proc = new() { StartInfo = psi };
|
||||||
|
|
||||||
|
string output = await Task.Run(() =>
|
||||||
|
{
|
||||||
|
proc.Start();
|
||||||
|
string outStr = proc.StandardOutput.ReadToEnd();
|
||||||
|
proc.WaitForExit();
|
||||||
|
return outStr;
|
||||||
|
});
|
||||||
|
|
||||||
|
string[] lines = output.Split("\n");
|
||||||
|
string finalText = lines[lines.Length - 2];
|
||||||
|
|
||||||
|
if (finalText.Length <= 1)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
finalText = char.ToUpper(finalText[0]) + finalText.Substring(1);
|
||||||
|
|
||||||
|
return finalText;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user