using System; using System.Collections.Generic; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.ShaderGraph.Drawing.Views.Blackboard { public class SGBlackboardSection : GraphElement { VisualElement m_DragIndicator; VisualElement m_MainContainer; VisualElement m_Header; Label m_TitleLabel; VisualElement m_RowsContainer; int m_InsertIndex; SGBlackboard m_Blackboard; SGBlackboard blackboard { get { return m_Blackboard ?? (m_Blackboard = GetFirstAncestorOfType()); } } public delegate bool CanAcceptDropDelegate(ISelectable selected); public CanAcceptDropDelegate canAcceptDrop { get; set; } int InsertionIndex(Vector2 pos) { int index = -1; VisualElement owner = contentContainer != null ? contentContainer : this; Vector2 localPos = this.ChangeCoordinatesTo(owner, pos); if (owner.ContainsPoint(localPos)) { index = 0; foreach (VisualElement child in Children()) { Rect rect = child.layout; if (localPos.y > (rect.y + rect.height / 2)) { ++index; } else { break; } } } return index; } VisualElement FindSectionDirectChild(VisualElement element) { VisualElement directChild = element; while ((directChild != null) && (directChild != this)) { if (directChild.parent == this) { return directChild; } directChild = directChild.parent; } return null; } public SGBlackboardSection() { // Setup VisualElement from Stylesheet and UXML file var tpl = Resources.Load("UXML/GraphView/BlackboardSection") as VisualTreeAsset; m_MainContainer = tpl.Instantiate(); m_MainContainer.AddToClassList("mainContainer"); m_Header = m_MainContainer.Q("sectionHeader"); m_TitleLabel = m_MainContainer.Q