Skip to content

Instantly share code, notes, and snippets.

@TigerHix
Created November 3, 2023 08:16
Show Gist options
  • Save TigerHix/ab3522bb25669457cc583abc4fb025d2 to your computer and use it in GitHub Desktop.
Save TigerHix/ab3522bb25669457cc583abc4fb025d2 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
using Warudo.Core.Attributes;
using Warudo.Core.Data;
using Warudo.Core.Graphs;
using Warudo.Core.Scenes;
namespace Warudo.Plugins.Core.Nodes {
[NodeType(Id = "f9c3fc33-7d37-4199-b4b4-3bfb54d86f83", Title = "FIND_ASSET_BY_TYPE", Category = "CATEGORY_ASSETS")]
public class FindAssetByTypeNode : Node {
[DataInput]
[Label("TYPE")]
[AutoComplete(nameof(AutoCompleteAssetType), forceSelection: true)]
public string AssetType;
private async UniTask<AutoCompleteList> AutoCompleteAssetType() {
var types = new HashSet<Type>();
foreach (var kv in Graph.Scene.GetAssets()) {
var asset = kv.Value;
var type = asset.GetType();
while (type != null) {
types.Add(type);
if (type == typeof(Asset))
break;
type = type.BaseType;
}
}
return types.Select(it => new AutoCompleteEntry {
label = it.Name,
value = it.FullName
}).ToAutoCompleteList();
}
[DataOutput]
[Label("ASSET")]
public Asset Asset() {
foreach (var kv in Graph.Scene.GetAssets()) {
var asset = kv.Value;
var type = asset.GetType();
while (type != null) {
if (type.FullName == AssetType) {
return asset;
}
if (type == typeof(Asset))
break;
type = type.BaseType;
}
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment