Skip to content
This repository was archived by the owner on Mar 29, 2026. It is now read-only.

Commit 7b32aa8

Browse files
committed
3.43.0 support
1 parent 417eb51 commit 7b32aa8

10 files changed

Lines changed: 1512 additions & 1549 deletions

File tree

Overlayer.Scripting/AudioPlayer.cs

Lines changed: 80 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,99 +7,94 @@
77
using UnityEngine;
88
using UnityEngine.Networking;
99

10-
namespace Overlayer.Scripting
11-
{
12-
public static class AudioPlayer
13-
{
14-
static List<AudioSource> sources = new List<AudioSource>();
15-
static Dictionary<string, AudioClip> clips = new Dictionary<string, AudioClip>();
16-
public static void Play(Sound sound)
17-
{
18-
if (sound?.sound == null) return;
19-
if (clips.TryGetValue(sound.sound, out var clip))
20-
{
21-
if (sound.offset > 0)
22-
StaticCoroutine.Run(PlayCo(sound.SetClip(clip)));
23-
else
24-
{
25-
AudioSource source = EnsureSource();
26-
sound.SetClip(clip);
27-
source.clip = sound.clip;
28-
source.volume = sound.volume;
29-
source.pitch = sound.pitch;
30-
source.Play();
31-
}
10+
namespace Overlayer.Scripting;
11+
12+
public static class AudioPlayer {
13+
static List<AudioSource> sources = new();
14+
static Dictionary<string, AudioClip> clips = new();
15+
public static void Play(Sound sound) {
16+
if(sound?.sound == null) {
17+
return;
18+
}
19+
20+
if(clips.TryGetValue(sound.sound, out var clip)) {
21+
if(sound.offset > 0) {
22+
StaticCoroutine.Run(PlayCo(sound.SetClip(clip)));
23+
} else {
24+
AudioSource source = EnsureSource();
25+
sound.SetClip(clip);
26+
source.clip = sound.clip;
27+
source.volume = sound.volume;
28+
source.pitch = sound.pitch;
29+
source.Play();
3230
}
33-
else StaticCoroutine.Run(LoadClip(sound.sound, clip => StaticCoroutine.Run(PlayCo(sound.SetClip(clip)))));
31+
} else {
32+
StaticCoroutine.Run(LoadClip(sound.sound, clip => StaticCoroutine.Run(PlayCo(sound.SetClip(clip)))));
3433
}
35-
public static void Stop(Sound sound)
36-
{
37-
sources.Find(a => a.clip == sound.clip)?.Stop();
34+
}
35+
public static void Stop(Sound sound) => sources.Find(a => a.clip == sound.clip)?.Stop();
36+
public static void StopAll() => sources.ForEach(a => a.Stop());
37+
public static void LoadAudio(string path, Action<AudioClip> callback) => StaticCoroutine.Run(LoadClip(path, callback));
38+
static IEnumerator PlayCo(Sound sound) {
39+
float counted = 0f;
40+
while(counted < sound.offset) {
41+
counted += UnityEngine.Time.deltaTime * 1000f;
42+
yield return null;
3843
}
39-
public static void StopAll()
40-
{
41-
sources.ForEach(a => a.Stop());
44+
AudioSource source = EnsureSource();
45+
source.clip = sound.clip;
46+
source.volume = sound.volume;
47+
source.pitch = sound.pitch;
48+
source.Play();
49+
}
50+
static IEnumerator LoadClip(string sound, Action<AudioClip> callback) {
51+
if(callback == null) {
52+
yield break;
4253
}
43-
public static void LoadAudio(string path, Action<AudioClip> callback)
44-
{
45-
StaticCoroutine.Run(LoadClip(path, callback));
54+
55+
if(clips.TryGetValue(sound, out var c)) {
56+
callback(c);
57+
yield break;
4658
}
47-
static IEnumerator PlayCo(Sound sound)
48-
{
49-
float counted = 0f;
50-
while (counted < sound.offset)
51-
{
52-
counted += UnityEngine.Time.deltaTime * 1000f;
53-
yield return null;
54-
}
55-
AudioSource source = EnsureSource();
56-
source.clip = sound.clip;
57-
source.volume = sound.volume;
58-
source.pitch = sound.pitch;
59-
source.Play();
59+
if(!File.Exists(sound)) {
60+
Main.Logger.Log($"{sound} Is Not Exist!!");
61+
yield break;
6062
}
61-
static IEnumerator LoadClip(string sound, Action<AudioClip> callback)
62-
{
63-
if (callback == null) yield break;
64-
if (clips.TryGetValue(sound, out var c))
65-
{
66-
callback(c);
67-
yield break;
68-
}
69-
if (!File.Exists(sound))
70-
{
71-
Main.Logger.Log($"{sound} Is Not Exist!!");
72-
yield break;
73-
}
74-
Uri.TryCreate(sound, UriKind.RelativeOrAbsolute, out Uri uri);
75-
if (uri == null) yield break;
76-
var at = Path.GetExtension(sound) switch
77-
{
78-
".ogg" => AudioType.OGGVORBIS,
79-
".mp3" => AudioType.MPEG,
80-
".aiff" => AudioType.AIFF,
81-
".wav" => AudioType.WAV,
82-
_ => AudioType.UNKNOWN
83-
};
84-
if (at == AudioType.UNKNOWN) yield break;
85-
var clipReq = UnityWebRequestMultimedia.GetAudioClip(uri, at);
86-
yield return clipReq.SendWebRequest();
87-
var clip = DownloadHandlerAudioClip.GetContent(clipReq);
88-
UnityEngine.Object.DontDestroyOnLoad(clip);
89-
callback(clips[sound] = clip);
63+
Uri.TryCreate(sound, UriKind.RelativeOrAbsolute, out Uri uri);
64+
if(uri == null) {
65+
yield break;
66+
}
67+
68+
var at = Path.GetExtension(sound) switch {
69+
".ogg" => AudioType.OGGVORBIS,
70+
".mp3" => AudioType.MPEG,
71+
".aiff" => AudioType.AIFF,
72+
".wav" => AudioType.WAV,
73+
_ => AudioType.UNKNOWN
74+
};
75+
if(at == AudioType.UNKNOWN) {
76+
yield break;
9077
}
91-
static AudioSource EnsureSource()
92-
{
93-
var source = sources.FirstOrDefault(a => !a.isPlaying);
94-
if (source != null) return source;
95-
GameObject sourceObject = new GameObject();
96-
source = sourceObject.AddComponent<AudioSource>();
97-
source.playOnAwake = false;
98-
source.ignoreListenerPause = true;
99-
source.ignoreListenerVolume = true;
100-
UnityEngine.Object.DontDestroyOnLoad(sourceObject);
101-
sources.Add(source);
78+
79+
var clipReq = UnityWebRequestMultimedia.GetAudioClip(uri, at);
80+
yield return clipReq.SendWebRequest();
81+
var clip = DownloadHandlerAudioClip.GetContent(clipReq);
82+
UnityEngine.Object.DontDestroyOnLoad(clip);
83+
callback(clips[sound] = clip);
84+
}
85+
static AudioSource EnsureSource() {
86+
var source = sources.FirstOrDefault(a => !a.isPlaying);
87+
if(source != null) {
10288
return source;
10389
}
90+
91+
GameObject sourceObject = new();
92+
source = sourceObject.AddComponent<AudioSource>();
93+
source.playOnAwake = false;
94+
source.ignoreListenerPause = true;
95+
source.ignoreListenerVolume = true;
96+
UnityEngine.Object.DontDestroyOnLoad(sourceObject);
97+
sources.Add(source);
98+
return source;
10499
}
105100
}

Overlayer.Scripting/Expression.cs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,26 @@
66
using Overlayer.Utils;
77
using System.Collections.Generic;
88

9-
namespace Overlayer.Scripting
10-
{
11-
public static class Expression
12-
{
13-
public static readonly Dictionary<string, ExprContext> expressions = new Dictionary<string, ExprContext>();
14-
[Tag("Expression", NotPlaying = true)]
15-
public static object Expr(string expr)
16-
{
17-
if (expressions.TryGetValue(expr, out var res))
18-
return res.Run();
19-
res = MiscUtils.ExecuteSafe(() => new ExprContext(Main.JSApi.PrepareInterpreter(), Engine.PrepareScript(JSUtils.RemoveImports(expr))), out _);
20-
if (!res.prepared.IsValid) return null;
21-
return (expressions[expr] = res).Run();
9+
namespace Overlayer.Scripting;
10+
11+
public static class Expression {
12+
public static readonly Dictionary<string, ExprContext> expressions = new();
13+
[Tag("Expression", NotPlaying = true)]
14+
public static object Expr(string expr) {
15+
if(expressions.TryGetValue(expr, out var res)) {
16+
return res.Run();
2217
}
23-
public class ExprContext
24-
{
25-
public Engine engine;
26-
public Prepared<Script> prepared;
27-
public ExprContext(Engine engine, Prepared<Script> prepared)
28-
{
29-
this.engine = engine;
30-
this.prepared = prepared;
31-
}
32-
public JsValue Run() => engine.Evaluate(prepared);
18+
19+
res = MiscUtils.ExecuteSafe(() => new ExprContext(Main.JSApi.PrepareInterpreter(), Engine.PrepareScript(JSUtils.RemoveImports(expr))), out _);
20+
return !res.prepared.IsValid ? null : (object)(expressions[expr] = res).Run();
21+
}
22+
public class ExprContext {
23+
public Engine engine;
24+
public Prepared<Script> prepared;
25+
public ExprContext(Engine engine, Prepared<Script> prepared) {
26+
this.engine = engine;
27+
this.prepared = prepared;
3328
}
29+
public JsValue Run() => engine.Evaluate(prepared);
3430
}
3531
}

0 commit comments

Comments
 (0)