Skip to content

Commit

Permalink
Added Graph Context Items
Browse files Browse the repository at this point in the history
  • Loading branch information
S2NX7 authored May 31, 2024
1 parent 756898b commit 9da8774
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Editor/Fundamentals/CommunityGraphContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System;
using Unity.VisualScripting.Community;

namespace Unity.VisualScripting.Community
{
[GraphContextExtension(typeof(FlowGraphContext))]
public class CommunityGraphContextExtensions : GraphContextExtension<FlowGraphContext>
{
public CommunityGraphContextExtensions(FlowGraphContext context) : base(context)
{
}

public override IEnumerable<GraphContextMenuItem> contextMenuItems
{
get
{
if (selection.Count >= 2)
{
yield return new GraphContextMenuItem(ConvertToEmbed, "To Embed Subgraph");
yield return new GraphContextMenuItem(ConvertToMacro, "To Macro Subgraph");
}

if (selection.Count == 0)
{
yield return new GraphContextMenuItem(OpenCSharpPreview, "Open Utility Window");
}

foreach (var item in base.contextMenuItems)
{
yield return item;
}
}
}

private void ConvertToEmbed(Vector2 pos)
{
NodeSelection.Convert(GraphSource.Embed);
}

private void ConvertToMacro(Vector2 pos)
{
NodeSelection.Convert(GraphSource.Macro);
}

private void OpenCSharpPreview(Vector2 pos)
{
UtilityWindow.Open();
}
}
}
2 changes: 2 additions & 0 deletions Editor/Fundamentals/CommunityGraphContextExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9da8774

Please sign in to comment.