本文整理汇总了C#中IReorderableListAdaptor.CanDrag方法的典型用法代码示例。如果您正苦于以下问题:C# IReorderableListAdaptor.CanDrag方法的具体用法?C# IReorderableListAdaptor.CanDrag怎么用?C# IReorderableListAdaptor.CanDrag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReorderableListAdaptor
的用法示例。
在下文中一共展示了IReorderableListAdaptor.CanDrag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawListContainerAndItems
//.........这里部分代码省略.........
if (_tracking && eventType == EventType.MouseDrag) {
float midpoint = itemPosition.y + itemPosition.height / 2f;
if (s_TargetIndex < i) {
if (s_DragItemPosition.yMax > lastMidPoint && s_DragItemPosition.yMax < midpoint)
newTargetIndex = i;
}
else if (s_TargetIndex > i) {
if (s_DragItemPosition.y > lastMidPoint && s_DragItemPosition.y < midpoint)
newTargetIndex = i;
}
/*if (s_DragItemPosition.y > itemPosition.y && s_DragItemPosition.y <= midpoint)
newTargetIndex = i;
else if (s_DragItemPosition.yMax > midpoint && s_DragItemPosition.yMax <= itemPosition.yMax)
newTargetIndex = i + 1;*/
}
// The following may break use of tab key to navigate through controls :/
if ((Flags & ReorderableListFlags.DisableClipping) == 0) {
// Clip list item? Performance boost!
if (itemPosition.yMax < _visibleRect.y - itemPosition.height) {
// Let's try and trick Unity into maintaining tab key support...
GUIUtility.GetControlID(FocusType.Keyboard, itemPosition);
continue;
}
if (itemPosition.y > _visibleRect.yMax + itemPosition.height)
break;
}
// Draw list item.
DrawListItem(eventType, itemPosition, adaptor, i);
// Did list count change (i.e. item removed)?
if (adaptor.Count < count) {
// We assume that it was this item which was removed, so --i allows us
// to process the next item as usual.
count = adaptor.Count;
--i;
continue;
}
// Event has already been used, skip to next item.
if (Event.current.type != EventType.Used) {
switch (eventType) {
case EventType.MouseDown:
if (GUI.enabled && itemPosition.Contains(mousePosition)) {
// Remove input focus from control before attempting a context click or drag.
GUIUtility.keyboardControl = 0;
if (_allowReordering && adaptor.CanDrag(i) && Event.current.button == 0) {
s_DragItemPosition = itemPosition;
BeginTrackingReorderDrag(controlID, i);
s_AnchorMouseOffset = itemPosition.y - mousePosition.y;
s_TargetIndex = i;
Event.current.Use();
}
}
break;
/* DEBUG
case EventType.Repaint:
GUI.color = Color.red;
GUI.DrawTexture(new Rect(0, lastMidPoint, 10, 1), EditorGUIUtility.whiteTexture);
GUI.color = Color.yellow;
GUI.DrawTexture(new Rect(5, itemPosition.y + itemPosition.height / 2f, 10, 1), EditorGUIUtility.whiteTexture);
GUI.color = Color.white;
break;
//*/
}
}
}
// Item which is being dragged should be shown on top of other controls!
if (IsTrackingControl(controlID)) {
lastMidPoint = position.yMax - lastHeight / 2f;
if (eventType == EventType.MouseDrag) {
if (s_DragItemPosition.yMax >= lastMidPoint)
newTargetIndex = count;
// Force repaint to occur so that dragging rectangle is visible.
s_TargetIndex = newTargetIndex;
Event.current.Use();
}
DrawFloatingListItem(eventType, adaptor, targetSlotPosition);
/* DEBUG
if (eventType == EventType.Repaint) {
GUI.color = Color.blue;
GUI.DrawTexture(new Rect(100, lastMidPoint, 20, 1), EditorGUIUtility.whiteTexture);
GUI.color = Color.white;
}
//*/
}
// Fake control to catch input focus if auto focus was not possible.
GUIUtility.GetControlID(FocusType.Keyboard);
}
示例2: DrawListItem
private void DrawListItem(EventType eventType, Rect position, IReorderableListAdaptor adaptor, int itemIndex) {
bool visible = (position.y < _visibleRect.yMax && position.yMax > _visibleRect.y);
bool draggable = _allowReordering && adaptor.CanDrag(itemIndex);
Rect itemContentPosition = position;
itemContentPosition.x = position.x + 2;
itemContentPosition.y += 1;
itemContentPosition.width = position.width - 4;
itemContentPosition.height = position.height - 4;
// Make space for grab handle?
if (draggable) {
itemContentPosition.x += 20;
itemContentPosition.width -= 20;
}
// Make space for element index.
if (_indexLabelWidth != 0) {
itemContentPosition.width -= _indexLabelWidth;
if (eventType == EventType.Repaint && visible)
s_RightAlignedLabelStyle.Draw(new Rect(itemContentPosition.x, position.y, _indexLabelWidth, position.height - 4), itemIndex + ":", false, false, false, false);
itemContentPosition.x += _indexLabelWidth;
}
// Make space for remove button?
if (HasRemoveButtons)
itemContentPosition.width -= 27;
try {
s_CurrentItemIndex.Push(itemIndex);
EditorGUI.BeginChangeCheck();
if (eventType == EventType.Repaint && visible) {
// Draw background of list item.
var backgroundPosition = new Rect(position.x, position.y, position.width, position.height - 1);
adaptor.DrawItemBackground(backgroundPosition, itemIndex);
// Draw grab handle?
if (draggable) {
var texturePosition = new Rect(position.x + 6, position.y + position.height / 2f - 3, 9, 5);
GUIHelper.DrawTexture(texturePosition, ReorderableListResources.GetTexture(ReorderableListTexture.GrabHandle));
}
// Draw splitter between list items.
if (itemIndex != 0 && (!_tracking || itemIndex != s_AnchorIndex)) {
var texturePosition = new Rect(position.x, position.y - 1, position.width, 1);
GUIHelper.DrawTexture(texturePosition, ReorderableListResources.texItemSplitter);
}
}
// Allow control to be automatically focused.
if (s_AutoFocusIndex == itemIndex)
GUI.SetNextControlName("AutoFocus_" + _controlID + "_" + itemIndex);
// Present actual control.
adaptor.DrawItem(itemContentPosition, itemIndex);
if (EditorGUI.EndChangeCheck())
ReorderableListGUI.IndexOfChangedItem = itemIndex;
// Draw remove button?
if (HasRemoveButtons && adaptor.CanRemove(itemIndex)) {
s_RemoveButtonPosition = position;
s_RemoveButtonPosition.width = 27;
s_RemoveButtonPosition.x = itemContentPosition.xMax + 2;
s_RemoveButtonPosition.height -= 2;
if (DoRemoveButton(s_RemoveButtonPosition, visible))
RemoveItem(adaptor, itemIndex);
}
// Check for context click?
if (eventType == EventType.ContextClick && position.Contains(Event.current.mousePosition) && (Flags & ReorderableListFlags.DisableContextMenu) == 0) {
ShowContextMenu(_controlID, itemIndex, adaptor);
Event.current.Use();
}
}
finally {
s_CurrentItemIndex.Pop();
}
}
示例3: DrawListItem
private void DrawListItem(EventType eventType, Rect position, IReorderableListAdaptor adaptor, int itemIndex)
{
bool flag = position.y < this._visibleRect.yMax && position.yMax > this._visibleRect.y;
bool flag2 = this._allowReordering && adaptor.CanDrag(itemIndex);
Rect position2 = position;
position2.x = position.x + 2f;
position2.y = position2.y + 1f;
position2.width = position.width - 4f;
position2.height = position.height - 4f;
if (flag2)
{
position2.x = position2.x + 20f;
position2.width = position2.width - 20f;
}
if (this._indexLabelWidth != 0f)
{
position2.width = position2.width - this._indexLabelWidth;
if (eventType == EventType.Repaint && flag)
{
ReorderableListControl.s_RightAlignedLabelStyle.Draw(new Rect(position2.x, position.y, this._indexLabelWidth, position.height - 4f), itemIndex + ":", false, false, false, false);
}
position2.x = position2.x + this._indexLabelWidth;
}
if (this.hasRemoveButtons)
{
position2.width = position2.width - this.removeButtonStyle.fixedWidth;
}
if (eventType == EventType.Repaint && flag)
{
if (flag2)
{
GUI.DrawTexture(new Rect(position.x + 6f, position.y + position.height / 2f - 3f, 9f, 5f), ReorderableListResources.texGrabHandle);
}
if (!this._tracking || itemIndex != ReorderableListControl.s_AnchorIndex)
{
GUI.DrawTexture(new Rect(position.x, position.y - 1f, position.width, 1f), ReorderableListResources.texItemSplitter);
}
}
if (ReorderableListControl.s_AutoFocusIndex == itemIndex)
{
GUI.SetNextControlName(string.Concat(new object[]
{
"AutoFocus_",
this._controlID,
"_",
itemIndex
}));
}
try
{
ReorderableListControl.s_CurrentItemIndex.Push(itemIndex);
EditorGUI.BeginChangeCheck();
adaptor.DrawItem(position2, itemIndex);
if (EditorGUI.EndChangeCheck())
{
ReorderableListGUI.indexOfChangedItem = itemIndex;
}
if (this.hasRemoveButtons && adaptor.CanRemove(itemIndex))
{
ReorderableListControl.s_RemoveButtonPosition = position;
ReorderableListControl.s_RemoveButtonPosition.width = this.removeButtonStyle.fixedWidth;
ReorderableListControl.s_RemoveButtonPosition.x = position2.xMax + 2f;
ReorderableListControl.s_RemoveButtonPosition.height = ReorderableListControl.s_RemoveButtonPosition.height - 2f;
if (this.DoRemoveButton(ReorderableListControl.s_RemoveButtonPosition, flag))
{
this.RemoveItem(adaptor, itemIndex);
}
}
if (eventType == EventType.ContextClick && position.Contains(Event.current.mousePosition) && (this.flags & ReorderableListFlags.DisableContextMenu) == (ReorderableListFlags)0)
{
this.ShowContextMenu(this._controlID, itemIndex, adaptor);
Event.current.Use();
}
}
finally
{
ReorderableListControl.s_CurrentItemIndex.Pop();
}
}
示例4: DrawListContainerAndItems
//.........这里部分代码省略.........
newTargetIndex = i;
}
else if (s_TargetIndex > i) {
if (s_DragItemPosition.y > lastMidPoint && s_DragItemPosition.y < midpoint)
newTargetIndex = i;
}
/*if (s_DragItemPosition.y > itemPosition.y && s_DragItemPosition.y <= midpoint)
newTargetIndex = i;
else if (s_DragItemPosition.yMax > midpoint && s_DragItemPosition.yMax <= itemPosition.yMax)
newTargetIndex = i + 1;*/
}
// Draw list item.
DrawListItem(itemPosition, adaptor, i);
// Did list count change (i.e. item removed)?
if (adaptor.Count < count) {
// We assume that it was this item which was removed, so --i allows us
// to process the next item as usual.
count = adaptor.Count;
--i;
continue;
}
// Event has already been used, skip to next item.
if (Event.current.type != EventType.Used) {
switch (eventType) {
case EventType.MouseDown:
if (GUI.enabled && itemPosition.Contains(mousePosition)) {
// Remove input focus from control before attempting a context click or drag.
GUIUtility.keyboardControl = 0;
if (_allowReordering && adaptor.CanDrag(i) && Event.current.button == 0) {
s_DragItemPosition = itemPosition;
BeginTrackingReorderDrag(_controlID, i);
s_AnchorMouseOffset = itemPosition.y - mousePosition.y;
s_TargetIndex = i;
Event.current.Use();
}
}
break;
/* DEBUG
case EventType.Repaint:
GUI.color = Color.red;
GUI.DrawTexture(new Rect(0, lastMidPoint, 10, 1), EditorGUIUtility.whiteTexture);
GUI.color = Color.yellow;
GUI.DrawTexture(new Rect(5, itemPosition.y + itemPosition.height / 2f, 10, 1), EditorGUIUtility.whiteTexture);
GUI.color = Color.white;
break;
//*/
}
}
}
if (HorizontalLineAtEnd) {
var horizontalLinePosition = new Rect(itemPosition.x, position.yMax - ContainerStyle.padding.vertical, itemPosition.width, 1);
GUIHelper.Separator(horizontalLinePosition, HorizontalLineColor);
}
lastMidPoint = position.yMax - lastHeight / 2f;
// Assume that drop insertion is not allowed at this time; we can change our
// mind a little further down ;)
示例5: DrawListContainerAndItems
//.........这里部分代码省略.........
int count = adaptor.Count;
int i = 0;
while (i < count)
{
rect.y = rect.yMax;
rect.height = 0f;
if (!this._tracking)
{
goto IL_286;
}
if (i == ReorderableListControl.s_TargetIndex)
{
targetSlotPosition = rect.y;
rect.y = rect.y + ReorderableListControl.s_DragItemPosition.height;
}
if (i != ReorderableListControl.s_AnchorIndex)
{
num3 = rect.y - num4 / 2f;
goto IL_286;
}
IL_415:
i++;
continue;
IL_286:
rect.height = adaptor.GetItemHeight(i) + 4f;
num4 = rect.height;
if (this._tracking && typeForControl == EventType.MouseDrag)
{
float num5 = rect.y + rect.height / 2f;
if (ReorderableListControl.s_TargetIndex < i)
{
if (ReorderableListControl.s_DragItemPosition.yMax > num3 && ReorderableListControl.s_DragItemPosition.yMax < num5)
{
num = i;
}
}
else
{
if (ReorderableListControl.s_TargetIndex > i && ReorderableListControl.s_DragItemPosition.y > num3 && ReorderableListControl.s_DragItemPosition.y < num5)
{
num = i;
}
}
}
if ((this.flags & ReorderableListFlags.DisableClipping) == (ReorderableListFlags)0)
{
if (rect.yMax < this._visibleRect.y - rect.height)
{
GUIUtility.GetControlID(FocusType.Keyboard, rect);
goto IL_415;
}
if (rect.y > this._visibleRect.yMax + rect.height)
{
break;
}
}
this.DrawListItem(typeForControl, rect, adaptor, i);
if (adaptor.Count < count)
{
count = adaptor.Count;
i--;
goto IL_415;
}
if (Event.current.type == EventType.Used)
{
goto IL_415;
}
EventType eventType2 = typeForControl;
if (eventType2 != 0 || !GUI.enabled || !rect.Contains(mousePosition))
{
goto IL_415;
}
GUIUtility.keyboardControl = 0;
if (this._allowReordering && adaptor.CanDrag(i) && Event.current.button == 0)
{
ReorderableListControl.s_DragItemPosition = rect;
ReorderableListControl.BeginTrackingReorderDrag(controlID, i);
ReorderableListControl.s_AnchorMouseOffset = rect.y - mousePosition.y;
ReorderableListControl.s_TargetIndex = i;
Event.current.Use();
goto IL_415;
}
goto IL_415;
}
if (ReorderableListControl.IsTrackingControl(controlID))
{
num3 = position.yMax - num4 / 2f;
if (typeForControl == EventType.MouseDrag)
{
if (ReorderableListControl.s_DragItemPosition.yMax >= num3)
{
num = count;
}
ReorderableListControl.s_TargetIndex = num;
Event.current.Use();
}
this.DrawFloatingListItem(typeForControl, adaptor, targetSlotPosition);
}
GUIUtility.GetControlID(FocusType.Keyboard);
}