Peter Bay Bastian
7 年前
当前提交
f9b16024
共有 20 个文件被更改,包括 5 次插入 和 802 次删除
-
2com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs
-
11com.unity.shadergraph/Editor/Drawing/Controls/IntegerControl.cs
-
2com.unity.shadergraph/Editor/Drawing/Controls/ToggleControl.cs
-
3com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs
-
3com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs
-
4com.unity.shadergraph/Editor/Drawing/Manipulators/WindowDraggable.cs
-
6com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
-
3com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
-
2com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs
-
3com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs
-
10com.unity.shadergraph/Editor/Drawing/Views/ShaderPort.cs
-
32com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs
-
11com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs.meta
-
11com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs.meta
-
11com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs.meta
-
11com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs.meta
-
134com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs
-
67com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs
-
181com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs
-
300com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 4312a96008ca8754593210fc93a4575d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 353b195797b2ff24092e20c643077f2f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7532a1da2f917d54c800efef4149ae69 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f7dcab10210c08a488ac46fee4811efd |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if UNITY_2018_1
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleEnums; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing |
|||
{ |
|||
class Blackboard : GraphElement |
|||
{ |
|||
private const int k_DefaultWidth = 200; |
|||
private const float k_DefaultHeight = 400; |
|||
private VisualElement m_MainContainer; |
|||
private VisualElement m_Root; |
|||
private Label m_TitleLabel; |
|||
private Label m_SubTitleLabel; |
|||
private ScrollView m_ScrollView; |
|||
private VisualElement m_ContentContainer; |
|||
private VisualElement m_HeaderItem; |
|||
private Button m_AddButton; |
|||
private bool m_Scrollable = true; |
|||
|
|||
public Action<Blackboard> addItemRequested { get; set; } |
|||
public Action<Blackboard, int, VisualElement> moveItemRequested { get; set; } |
|||
public Action<Blackboard, VisualElement, string> editTextRequested { get; set; } |
|||
|
|||
public string title |
|||
{ |
|||
get { return m_TitleLabel.text; } |
|||
set { m_TitleLabel.text = value; } |
|||
} |
|||
|
|||
public string subTitle |
|||
{ |
|||
get { return m_SubTitleLabel.text; } |
|||
set { m_SubTitleLabel.text = value; } |
|||
} |
|||
|
|||
public override VisualElement contentContainer { get { return m_ContentContainer; } } |
|||
|
|||
public bool scrollable |
|||
{ |
|||
get |
|||
{ |
|||
return m_Scrollable; |
|||
} |
|||
set |
|||
{ |
|||
if (m_Scrollable == value) |
|||
return; |
|||
|
|||
m_Scrollable = value; |
|||
|
|||
if (m_Scrollable) |
|||
{ |
|||
if (m_ScrollView == null) |
|||
{ |
|||
m_ScrollView = new ScrollView(); |
|||
// m_ScrollView.stretchContentWidth = true;
|
|||
} |
|||
|
|||
// Remove the sections container from the content item and add it to the scrollview
|
|||
m_ContentContainer.RemoveFromHierarchy(); |
|||
m_Root.Add(m_ScrollView); |
|||
m_ScrollView.Add(m_ContentContainer); |
|||
style.positionType = PositionType.Manual; // As both the width and height can be changed by the user using a resizer
|
|||
|
|||
// If the current the current geometry is invalid then set a default size
|
|||
|
|||
if (layout.width == 0 || layout.height == 0) |
|||
{ |
|||
layout = new Rect(layout.x, layout.y, layout.width == 0 ? k_DefaultWidth : layout.width, layout.height == 0 ? k_DefaultHeight : layout.height); |
|||
} |
|||
|
|||
AddToClassList("scrollable"); |
|||
} |
|||
else |
|||
{ |
|||
if (m_ScrollView != null) |
|||
{ |
|||
// Remove the sections container from the scrollview and add it to the content item
|
|||
style.positionType = PositionType.Absolute; // As the height is automatically computed from the content but the width can be changed by the user using a resizer
|
|||
m_ScrollView.RemoveFromHierarchy(); |
|||
m_ContentContainer.RemoveFromHierarchy(); |
|||
m_Root.Add(m_ContentContainer); |
|||
} |
|||
RemoveFromClassList("scrollable"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public Blackboard() |
|||
{ |
|||
AddStyleSheetPath("Styles/Blackboard"); |
|||
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/Blackboard"); |
|||
|
|||
m_MainContainer = tpl.CloneTree(null); |
|||
m_MainContainer.AddToClassList("mainContainer"); |
|||
|
|||
m_Root = m_MainContainer.Q("content"); |
|||
|
|||
m_HeaderItem = m_MainContainer.Q("header"); |
|||
m_HeaderItem.AddToClassList("blackboardHeader"); |
|||
|
|||
m_AddButton = m_MainContainer.Q(name: "addButton") as Button; |
|||
m_AddButton.clickable.clicked += () => { |
|||
if (addItemRequested != null) |
|||
{ |
|||
addItemRequested(this); |
|||
} |
|||
}; |
|||
|
|||
m_TitleLabel = m_MainContainer.Q<Label>(name: "titleLabel"); |
|||
m_SubTitleLabel = m_MainContainer.Q<Label>(name: "subTitleLabel"); |
|||
m_ContentContainer = m_MainContainer.Q<VisualElement>(name: "contentContainer"); |
|||
|
|||
shadow.Add(m_MainContainer); |
|||
|
|||
capabilities |= Capabilities.Movable | Capabilities.Resizable; |
|||
clippingOptions = ClippingOptions.ClipAndCacheContents; |
|||
|
|||
ClearClassList(); |
|||
AddToClassList("sgblackboard"); |
|||
|
|||
this.AddManipulator(new Dragger { clampToParentEdges = true }); |
|||
|
|||
scrollable = false; |
|||
|
|||
shadow.Add(new Resizer()); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
#if UNITY_2018_1
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing |
|||
{ |
|||
class BlackboardRow : GraphElement |
|||
{ |
|||
private VisualElement m_Root; |
|||
private Button m_ExpandButton; |
|||
private VisualElement m_ItemContainer; |
|||
private VisualElement m_PropertyViewContainer; |
|||
private bool m_Expanded = true; |
|||
|
|||
public bool expanded |
|||
{ |
|||
get { return m_Expanded; } |
|||
set |
|||
{ |
|||
if (m_Expanded == value) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
m_Expanded = value; |
|||
|
|||
if (m_Expanded) |
|||
{ |
|||
m_Root.Add(m_PropertyViewContainer); |
|||
AddToClassList("expanded"); |
|||
} |
|||
else |
|||
{ |
|||
m_Root.Remove(m_PropertyViewContainer); |
|||
RemoveFromClassList("expanded"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public BlackboardRow(VisualElement item, VisualElement propertyView) |
|||
{ |
|||
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/BlackboardRow"); |
|||
VisualElement mainContainer = tpl.CloneTree(null); |
|||
mainContainer.AddToClassList("mainContainer"); |
|||
|
|||
m_Root = mainContainer.Q<VisualElement>("root"); |
|||
m_ItemContainer = mainContainer.Q<VisualElement>("itemContainer"); |
|||
m_PropertyViewContainer = mainContainer.Q<VisualElement>("propertyViewContainer"); |
|||
|
|||
m_ExpandButton = mainContainer.Q<Button>("expandButton"); |
|||
m_ExpandButton.clickable.clicked += () => expanded = !expanded; |
|||
|
|||
Add(mainContainer); |
|||
|
|||
ClearClassList(); |
|||
AddToClassList("sgblackboardRow"); |
|||
|
|||
m_ItemContainer.Add(item); |
|||
m_PropertyViewContainer.Add(propertyView); |
|||
|
|||
expanded = false; |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
#if UNITY_2018_1
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEditor.Graphing.Util; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing |
|||
{ |
|||
class BlackboardField : GraphElement |
|||
{ |
|||
private VisualElement m_ContentItem; |
|||
private Image m_Icon; |
|||
private Label m_TextLabel; |
|||
private TextField m_TextField; |
|||
private Label m_TypeLabel; |
|||
private bool m_EditTitleCancelled = false; |
|||
SelectionDropper m_SelectionDropper; |
|||
|
|||
public string text |
|||
{ |
|||
get { return m_TextLabel.text; } |
|||
set { m_TextLabel.text = value; } |
|||
} |
|||
|
|||
public string typeText |
|||
{ |
|||
get { return m_TypeLabel.text; } |
|||
set { m_TypeLabel.text = value; } |
|||
} |
|||
|
|||
public Texture icon |
|||
{ |
|||
get { return m_Icon.image; } |
|||
set |
|||
{ |
|||
m_Icon.image = value; |
|||
|
|||
if (value == null) |
|||
{ |
|||
AddToClassList("noIcon"); |
|||
m_Icon.visible = false; |
|||
} |
|||
else |
|||
{ |
|||
RemoveFromClassList("noIcon"); |
|||
m_Icon.visible = true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public BlackboardField() |
|||
: this(null, "", "") {} |
|||
|
|||
static Type s_ContextualMenuManipulator = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypesOrNothing()).FirstOrDefault(t => t.FullName == "UnityEngine.Experimental.UIElements.ContextualMenuManipulator"); |
|||
|
|||
public BlackboardField(Texture icon, string text, string typeText) |
|||
{ |
|||
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/BlackboardField"); |
|||
VisualElement mainContainer = tpl.CloneTree(null); |
|||
|
|||
mainContainer.AddToClassList("mainContainer"); |
|||
mainContainer.pickingMode = PickingMode.Ignore; |
|||
|
|||
m_ContentItem = mainContainer.Q("contentItem"); |
|||
|
|||
m_TextLabel = mainContainer.Q<Label>("textLabel"); |
|||
m_Icon = mainContainer.Q<Image>("iconItem"); |
|||
m_TypeLabel = mainContainer.Q<Label>("typeLabel"); |
|||
|
|||
m_TextField = mainContainer.Q<TextField>("textField"); |
|||
m_TextField.visible = false; |
|||
m_TextField.RegisterCallback<FocusOutEvent>(e => { OnEditTextFinished(); }); |
|||
m_TextField.RegisterCallback<KeyDownEvent>(OnTextFieldKeyPressed); |
|||
|
|||
Add(mainContainer); |
|||
|
|||
RegisterCallback<MouseDownEvent>(OnMouseDownEvent); |
|||
|
|||
capabilities |= Capabilities.Selectable | Capabilities.Droppable | Capabilities.Deletable; |
|||
|
|||
ClearClassList(); |
|||
AddToClassList("sgblackboardField"); |
|||
|
|||
this.text = text; |
|||
this.icon = icon; |
|||
this.typeText = typeText; |
|||
|
|||
m_SelectionDropper = new SelectionDropper(Handler); |
|||
// Workaround bug causing SelectionDropper to not work (m_Active should be initialized to false rather than true)
|
|||
var activeFieldInfo = typeof(SelectionDropper).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.Name == "m_Active"); |
|||
Debug.Assert(activeFieldInfo != null, "activeFieldInfo != null"); |
|||
activeFieldInfo.SetValue(m_SelectionDropper, false); |
|||
this.AddManipulator(m_SelectionDropper); |
|||
|
|||
this.AddManipulator((IManipulator)Activator.CreateInstance(s_ContextualMenuManipulator, (Action<ContextualMenuPopulateEvent>)BuildContextualMenu)); |
|||
} |
|||
|
|||
void BuildContextualMenu(ContextualMenuPopulateEvent evt) |
|||
{ |
|||
evt.menu.AppendAction("Rename", e => RenameGo(), ContextualMenu.MenuAction.AlwaysEnabled); |
|||
} |
|||
|
|||
void Handler(IMGUIEvent evt, List<ISelectable> selection, IDropTarget dropTarget) |
|||
{ |
|||
if (dropTarget == null || !dropTarget.CanAcceptDrop(selection)) |
|||
return; |
|||
|
|||
if (evt.imguiEvent.type == EventType.DragUpdated) |
|||
dropTarget.DragUpdated(evt, selection, dropTarget); |
|||
else if (evt.imguiEvent.type == EventType.DragPerform) |
|||
dropTarget.DragPerform(evt, selection, dropTarget); |
|||
else if (evt.imguiEvent.type == EventType.DragExited) |
|||
dropTarget.DragExited(); |
|||
|
|||
// if (propagation == EventPropagation.Stop)
|
|||
// evt.StopPropagation();
|
|||
} |
|||
|
|||
private void OnTextFieldKeyPressed(KeyDownEvent e) |
|||
{ |
|||
switch (e.keyCode) |
|||
{ |
|||
case KeyCode.Escape: |
|||
m_EditTitleCancelled = true; |
|||
m_TextField.Blur(); |
|||
break; |
|||
case KeyCode.Return: |
|||
case KeyCode.KeypadEnter: |
|||
m_TextField.Blur(); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
private void OnEditTextFinished() |
|||
{ |
|||
m_ContentItem.visible = true; |
|||
m_TextField.visible = false; |
|||
|
|||
if (!m_EditTitleCancelled && (text != m_TextField.text)) |
|||
{ |
|||
Blackboard blackboard = GetFirstAncestorOfType<Blackboard>(); |
|||
|
|||
if (blackboard.editTextRequested != null) |
|||
{ |
|||
blackboard.editTextRequested(blackboard, this, m_TextField.text); |
|||
} |
|||
else |
|||
{ |
|||
text = m_TextField.text; |
|||
} |
|||
} |
|||
|
|||
m_EditTitleCancelled = false; |
|||
} |
|||
|
|||
private void OnMouseDownEvent(MouseDownEvent e) |
|||
{ |
|||
if ((e.clickCount == 2) && e.button == (int)MouseButton.LeftMouse) |
|||
{ |
|||
RenameGo(); |
|||
e.PreventDefault(); |
|||
} |
|||
} |
|||
|
|||
internal void RenameGo() |
|||
{ |
|||
m_TextField.text = text; |
|||
m_TextField.visible = true; |
|||
m_ContentItem.visible = false; |
|||
m_TextField.Focus(); |
|||
m_TextField.SelectAll(); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
#if UNITY_2018_1
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleEnums; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing |
|||
{ |
|||
class BlackboardSection : GraphElement, IDropTarget |
|||
{ |
|||
private VisualElement m_DragIndicator; |
|||
private VisualElement m_MainContainer; |
|||
private VisualElement m_Header; |
|||
private Label m_TitleLabel; |
|||
private VisualElement m_RowsContainer; |
|||
private int m_InsertIndex; |
|||
|
|||
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 BlackboardSection() |
|||
{ |
|||
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/BlackboardSection"); |
|||
m_MainContainer = tpl.CloneTree(null); |
|||
m_MainContainer.AddToClassList("mainContainer"); |
|||
|
|||
m_Header = m_MainContainer.Q<VisualElement>("sectionHeader"); |
|||
m_TitleLabel = m_MainContainer.Q<Label>("sectionTitleLabel"); |
|||
m_RowsContainer = m_MainContainer.Q<VisualElement>("rowsContainer"); |
|||
|
|||
shadow.Add(m_MainContainer); |
|||
|
|||
m_DragIndicator = new VisualElement(); |
|||
|
|||
m_DragIndicator.name = "dragIndicator"; |
|||
m_DragIndicator.style.positionType = PositionType.Absolute; |
|||
shadow.Add(m_DragIndicator); |
|||
|
|||
ClearClassList(); |
|||
AddToClassList("sgblackboardSection"); |
|||
|
|||
m_InsertIndex = -1; |
|||
} |
|||
|
|||
public override VisualElement contentContainer { get { return m_RowsContainer; } } |
|||
|
|||
public string title |
|||
{ |
|||
get { return m_TitleLabel.text; } |
|||
set { m_TitleLabel.text = value; } |
|||
} |
|||
|
|||
public bool headerVisible |
|||
{ |
|||
get { return m_Header.parent != null; } |
|||
set |
|||
{ |
|||
if (value == (m_Header.parent != null)) |
|||
return; |
|||
|
|||
if (value) |
|||
{ |
|||
m_MainContainer.Add(m_Header); |
|||
} |
|||
else |
|||
{ |
|||
m_MainContainer.Remove(m_Header); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void SetDragIndicatorVisible(bool visible) |
|||
{ |
|||
if (visible && (m_DragIndicator.parent == null)) |
|||
{ |
|||
shadow.Add(m_DragIndicator); |
|||
m_DragIndicator.visible = true; |
|||
} |
|||
else if ((visible == false) && (m_DragIndicator.parent != null)) |
|||
{ |
|||
shadow.Remove(m_DragIndicator); |
|||
} |
|||
} |
|||
|
|||
public bool CanAcceptDrop(List<ISelectable> selection) |
|||
{ |
|||
// Look for at least one selected element in this section to accept drop
|
|||
foreach (ISelectable selected in selection) |
|||
{ |
|||
VisualElement selectedElement = selected as VisualElement; |
|||
|
|||
if (selected != null && Contains(selectedElement)) |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
// public bool DragUpdated(DragUpdatedEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
|
|||
public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) |
|||
{ |
|||
VisualElement sourceItem = null; |
|||
|
|||
foreach (ISelectable selectedElement in selection) |
|||
{ |
|||
sourceItem = selectedElement as VisualElement; |
|||
|
|||
if (sourceItem == null) |
|||
continue; |
|||
} |
|||
|
|||
if (!Contains(sourceItem)) |
|||
{ |
|||
SetDragIndicatorVisible(false); |
|||
|
|||
return EventPropagation.Continue; |
|||
} |
|||
|
|||
var target = evt.target as VisualElement; |
|||
// Vector2 localPosition = target.ChangeCoordinatesTo(this, evt.localMousePosition);
|
|||
Vector2 localPosition = target.ChangeCoordinatesTo(this, evt.imguiEvent.mousePosition); |
|||
|
|||
m_InsertIndex = InsertionIndex(localPosition); |
|||
|
|||
if (m_InsertIndex != -1) |
|||
{ |
|||
float indicatorY = 0; |
|||
|
|||
if (m_InsertIndex == childCount) |
|||
{ |
|||
VisualElement lastChild = this[childCount - 1]; |
|||
|
|||
indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.style.marginBottom)).y; |
|||
} |
|||
else |
|||
{ |
|||
VisualElement childAtInsertIndex = this[m_InsertIndex]; |
|||
|
|||
indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.style.marginTop)).y; |
|||
} |
|||
|
|||
SetDragIndicatorVisible(true); |
|||
|
|||
m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height); |
|||
|
|||
return EventPropagation.Stop; |
|||
} |
|||
else |
|||
{ |
|||
SetDragIndicatorVisible(false); |
|||
|
|||
m_InsertIndex = -1; |
|||
|
|||
return EventPropagation.Continue; |
|||
} |
|||
} |
|||
|
|||
int IndexOf(VisualElement element) |
|||
{ |
|||
var index = 0; |
|||
foreach (var childElement in Children()) |
|||
{ |
|||
if (childElement == element) |
|||
return index; |
|||
index++; |
|||
} |
|||
return -1; |
|||
} |
|||
|
|||
struct VisualElementPair |
|||
{ |
|||
public VisualElement Item1; |
|||
public VisualElement Item2; |
|||
|
|||
public VisualElementPair(VisualElement item1, VisualElement item2) |
|||
{ |
|||
Item1 = item1; |
|||
Item2 = item2; |
|||
} |
|||
} |
|||
|
|||
// public bool DragPerform(DragPerformEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
|
|||
public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) |
|||
{ |
|||
if (m_InsertIndex != -1) |
|||
{ |
|||
List<VisualElementPair> draggedElements = new List<VisualElementPair>(); |
|||
|
|||
foreach (ISelectable selectedElement in selection) |
|||
{ |
|||
var draggedElement = selectedElement as VisualElement; |
|||
|
|||
if (draggedElement != null && Contains(draggedElement)) |
|||
{ |
|||
draggedElements.Add(new VisualElementPair(FindSectionDirectChild(draggedElement), draggedElement)); |
|||
} |
|||
} |
|||
|
|||
if (draggedElements.Count == 0) |
|||
{ |
|||
SetDragIndicatorVisible(false); |
|||
|
|||
return EventPropagation.Continue; |
|||
} |
|||
|
|||
// Sorts the dragged elements from their relative order in their parent
|
|||
draggedElements.Sort((pair1, pair2) => { return IndexOf(pair1.Item1).CompareTo(IndexOf(pair2.Item1)); }); |
|||
|
|||
int insertIndex = m_InsertIndex; |
|||
|
|||
foreach (var draggedElement in draggedElements) |
|||
{ |
|||
VisualElement sectionDirectChild = draggedElement.Item1; |
|||
int indexOfDraggedElement = IndexOf(sectionDirectChild); |
|||
|
|||
if (!((indexOfDraggedElement == insertIndex) || ((insertIndex - 1) == indexOfDraggedElement))) |
|||
{ |
|||
Blackboard blackboard = GetFirstAncestorOfType<Blackboard>(); |
|||
|
|||
if (blackboard.moveItemRequested != null) |
|||
{ |
|||
blackboard.moveItemRequested(blackboard, m_InsertIndex, draggedElement.Item2); |
|||
} |
|||
else |
|||
{ |
|||
if (insertIndex == contentContainer.childCount) |
|||
{ |
|||
sectionDirectChild.BringToFront(); |
|||
} |
|||
else |
|||
{ |
|||
sectionDirectChild.PlaceBehind(this[insertIndex]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (insertIndex > indexOfDraggedElement) // No need to increment the insert index for the next dragged element if the current dragged element is above the current insert location.
|
|||
continue; |
|||
insertIndex++; |
|||
} |
|||
} |
|||
|
|||
SetDragIndicatorVisible(false); |
|||
|
|||
return EventPropagation.Stop; |
|||
} |
|||
|
|||
EventPropagation IDropTarget.DragExited() |
|||
{ |
|||
SetDragIndicatorVisible(false); |
|||
return EventPropagation.Continue; |
|||
} |
|||
} |
|||
} |
|||
#endif
|
撰写
预览
正在加载...
取消
保存
Reference in new issue