Skip to content

Instantly share code, notes, and snippets.

@TigerHix
Created October 11, 2023 10:46
Show Gist options
  • Save TigerHix/6e0453d8db57949f3fc3aaa1b638331d to your computer and use it in GitHub Desktop.
Save TigerHix/6e0453d8db57949f3fc3aaa1b638331d to your computer and use it in GitHub Desktop.
using System;
using Cysharp.Threading.Tasks;
using Warudo.Core.Attributes;
using Warudo.Core.Data;
using Warudo.Core.Graphs;
using Warudo.Core.Utils;
using Warudo.Plugins.Core.Assets;
using Warudo.Plugins.Core.Utils;
namespace Warudo.Plugins.Core.Nodes {
[NodeType(Id = "613e8942-6d7a-4cd8-aad0-98d7201450a0", Title = "TOGGLE_ASSET_GAMEOBJECT", Category = "CATEGORY_ASSETS")]
public class ToggleAssetGameObjectNode : Node {
[DataInput]
[Label("ASSET")]
public GameObjectAsset Asset;
[DataInput]
[AutoComplete(nameof(AutoCompleteGameObjectPath))]
[Label("GAMEOBJECT_PATH")]
public string GameObjectPath;
public async UniTask<AutoCompleteList> AutoCompleteGameObjectPath() {
if (Asset == null || !Asset.Active) {
return AutoCompleteList.Message("SELECTED_PARENT_ASSET_IS_INACTIVE");
}
return Transforms.AutoCompleteTransformChildren(Asset.GameObject.transform);
}
[DataInput]
[Label("ACTION")]
public ToggleAction Action;
[FlowInput]
public Continuation Enter() {
if (Asset.IsNullOrInactive()) return Exit;
var gameObject = Asset.GameObject.transform.Find(GameObjectPath)?.gameObject;
if (gameObject == null) return Exit;
gameObject.SetActive(Action switch {
ToggleAction.Toggle => !gameObject.activeSelf,
ToggleAction.Enable => true,
ToggleAction.Disable => false,
_ => throw new ArgumentOutOfRangeException()
});
return Exit;
}
[FlowOutput]
public Continuation Exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment