Singularity/Library/PackageCache/com.unity.shadergraph@12.1.11/Editor/Drawing/Views/ShaderGroup.cs

58 lines
1.8 KiB
C#
Raw Permalink Normal View History

2024-05-06 14:45:45 -04:00
using System;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.UIElements;
using ContextualMenuManipulator = UnityEngine.UIElements.ContextualMenuManipulator;
using ContextualMenuPopulateEvent = UnityEngine.UIElements.ContextualMenuPopulateEvent;
using VisualElementExtensions = UnityEngine.UIElements.VisualElementExtensions;
namespace UnityEditor.ShaderGraph
{
sealed class ShaderGroup : Group
{
GraphData m_Graph;
public new GroupData userData
{
get => (GroupData)base.userData;
set => base.userData = value;
}
public ShaderGroup()
{
VisualElementExtensions.AddManipulator(this, new ContextualMenuManipulator(BuildContextualMenu));
style.backgroundColor = new StyleColor(new Color(25 / 255f, 25 / 255f, 25 / 255f, 25 / 255f));
capabilities |= Capabilities.Ascendable;
}
public void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
}
public override bool AcceptsElement(GraphElement element, ref string reasonWhyNotAccepted)
{
if (element is StackNode stackNode)
{
reasonWhyNotAccepted = "Vertex and Pixel Stacks cannot be grouped";
return false;
}
var nodeView = element as IShaderNodeView;
if (nodeView == null)
{
// sticky notes are not nodes, but still groupable
return true;
}
if (nodeView.node is BlockNode)
{
reasonWhyNotAccepted = "Block Nodes cannot be grouped";
return false;
}
return true;
}
}
}