-
-
Save TigerHix/f0f1a7e3c53ca65450fdca1ff06eb343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using Cysharp.Threading.Tasks; | |
using Warudo.Core; | |
using Warudo.Core.Attributes; | |
using Warudo.Core.Data; | |
using Warudo.Core.Graphs; | |
using Warudo.Core.Resource; | |
using Random = UnityEngine.Random; | |
namespace Warudo.Plugins.Interactions.Nodes { | |
[NodeType(Id = "98f0598d-b81d-4db7-beb2-695bca9a017a", Title = "GET_RANDOM_SOUND", Category = "CATEGORY_INTERACTIONS")] | |
public class GetRandomSoundNode : Node { | |
[DataInput] | |
[Label("SOUNDS")] | |
[AutoCompleteResource("Sound")] | |
public string[] Sounds; | |
[DataInput] | |
[Label("COLLECTIONS")] | |
[AutoComplete(nameof(AutoCompleteSoundCollection), true)] | |
public string[] Collections; | |
public async UniTask<AutoCompleteList> AutoCompleteSoundCollection() { | |
return AutoCompleteList.Single(Context.ResourceManager.ProvideResources("Sound").ToAutoCompleteList() | |
.categories.Select(it => new AutoCompleteEntry { | |
label = it.LocalizedTitle, | |
value = it.title | |
}).ToList()); | |
} | |
private readonly List<string> choices = new(); | |
protected override void OnCreate() { | |
base.OnCreate(); | |
WatchAll(new[] { | |
nameof(Sounds), nameof(Collections) | |
}, () => { | |
var resources = Context.ResourceManager.ProvideResources("Sound").ToAutoCompleteList(); | |
choices.Clear(); | |
choices.AddRange(Sounds); | |
foreach (var collection in Collections) { | |
var category = resources.categories.FirstOrDefault(it => it.title == collection); | |
if (category != null) { | |
choices.AddRange(category.entries.Select(it => it.value)); | |
} | |
} | |
}); | |
} | |
[DataOutput] | |
[Label("SOUND_SOURCE")] | |
public string SoundSource() { | |
return choices.Count == 0 ? null : choices[Random.Range(0, choices.Count)]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment