浏览代码

* Fix Serializable(Cubemap|Mesh|Texture) classes

* Add back in blackboard classes to work with 2018.1
* Wrap some things in `#if UNITY_2018_1`s
/main
Peter Bay Bastian 7 年前
当前提交
0e49b142
共有 13 个文件被更改,包括 815 次插入42 次删除
  1. 37
      com.unity.shadergraph/Editor/Data/Graphs/SerializableCubemap.cs
  2. 37
      com.unity.shadergraph/Editor/Data/Graphs/SerializableMesh.cs
  3. 38
      com.unity.shadergraph/Editor/Data/Graphs/SerializableTexture.cs
  4. 16
      com.unity.shadergraph/Editor/Drawing/Views/ShaderPort.cs
  5. 2
      com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs
  6. 134
      com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs
  7. 11
      com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs.meta
  8. 181
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs
  9. 11
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs.meta
  10. 67
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs
  11. 11
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs.meta
  12. 301
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs
  13. 11
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs.meta

37
com.unity.shadergraph/Editor/Data/Graphs/SerializableCubemap.cs


public class SerializableCubemap
{
[SerializeField]
private string m_SerializedCubemap;
string m_SerializedCubemap;
[SerializeField]
string m_Guid;
[NonSerialized]
Cubemap m_Cubemap;
private class CubemapHelper
class CubemapHelper
{
public Cubemap cubemap;
}

get
{
if (string.IsNullOrEmpty(m_SerializedCubemap))
return null;
if (!string.IsNullOrEmpty(m_SerializedCubemap))
{
var textureHelper = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, textureHelper);
m_SerializedCubemap = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.cubemap));
m_Cubemap = textureHelper.cubemap;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Cubemap == null)
{
m_Cubemap = AssetDatabase.LoadAssetAtPath<Cubemap>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
var cube = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube);
return cube.cubemap;
return m_Cubemap;
if(cubemap == value)
return;
var cubemapHelper = new CubemapHelper();
cubemapHelper.cubemap = value;
m_SerializedCubemap = EditorJsonUtility.ToJson(cubemapHelper, true);
m_SerializedCubemap = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_Cubemap = value;
}
}
}

37
com.unity.shadergraph/Editor/Data/Graphs/SerializableMesh.cs


public class SerializableMesh
{
[SerializeField]
private string m_SerializedMesh;
string m_SerializedMesh;
[SerializeField]
string m_Guid;
[NonSerialized]
Mesh m_Mesh;
private class MeshHelper
class MeshHelper
{
public Mesh mesh;
}

get
{
if (string.IsNullOrEmpty(m_SerializedMesh))
return null;
if (!string.IsNullOrEmpty(m_SerializedMesh))
{
var textureHelper = new MeshHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedMesh, textureHelper);
m_SerializedMesh = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.mesh));
m_Mesh = textureHelper.mesh;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Mesh == null)
{
m_Mesh = AssetDatabase.LoadAssetAtPath<Mesh>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
var meshHelper = new MeshHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedMesh, meshHelper);
return meshHelper.mesh;
return m_Mesh;
if (mesh == value)
return;
var meshHelper = new MeshHelper();
meshHelper.mesh = value;
m_SerializedMesh = EditorJsonUtility.ToJson(meshHelper, true);
m_SerializedMesh = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_Mesh = value;
}
}
}

38
com.unity.shadergraph/Editor/Data/Graphs/SerializableTexture.cs


public class SerializableTexture
{
[SerializeField]
private string m_SerializedTexture;
string m_SerializedTexture;
[SerializeField]
string m_Guid;
[NonSerialized]
Texture m_Texture;
private class TextureHelper
class TextureHelper
{
public Texture texture;
}

get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
if (!string.IsNullOrEmpty(m_SerializedTexture))
{
var textureHelper = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, textureHelper);
m_SerializedTexture = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.texture));
m_Texture = textureHelper.texture;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Texture == null)
{
m_Texture = AssetDatabase.LoadAssetAtPath<Texture>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
return m_Texture;
if (texture == value)
return;
var textureHelper = new TextureHelper();
textureHelper.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(textureHelper, true);
m_SerializedTexture = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_Texture = value;
}
}
}

16
com.unity.shadergraph/Editor/Drawing/Views/ShaderPort.cs


{
sealed class ShaderPort : Port
{
#if UNITY_2018_1
ShaderPort(Orientation portOrientation, Direction portDirection, Type type)
: base(portOrientation, portDirection, type)
#else
: base(portOrientation, portDirection, portCapacity, type) { AddStyleSheetPath("Styles/ShaderPort"); }
: base(portOrientation, portDirection, portCapacity, type)
#endif
{
AddStyleSheetPath("Styles/ShaderPort");
}
var port = new ShaderPort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, slot.isInputSlot ? Capacity.Single : Capacity.Multi, null)
var port = new ShaderPort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output,
#if !UNITY_2018_1
slot.isInputSlot ? Capacity.Single : Capacity.Multi,
#endif
null)
{
m_EdgeConnector = new EdgeConnector<Edge>(connectorListener),
};

2
com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs


namespace UnityEditor.ShaderGraph.Drawing
{
public static class CompatibilityExtensions
static class CompatibilityExtensions
{
#if UNITY_2018_1
public static void OpenTextEditor(this BlackboardField field)

134
com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs


#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

11
com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs.meta


fileFormatVersion: 2
guid: 4312a96008ca8754593210fc93a4575d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

181
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs


#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

11
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs.meta


fileFormatVersion: 2
guid: 353b195797b2ff24092e20c643077f2f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

67
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs


#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

11
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs.meta


fileFormatVersion: 2
guid: 7532a1da2f917d54c800efef4149ae69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

301
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs


#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

11
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs.meta


fileFormatVersion: 2
guid: f7dcab10210c08a488ac46fee4811efd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存