您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
60 行
1.4 KiB
60 行
1.4 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.RMGUI;
|
|
|
|
namespace RMGUI.GraphView
|
|
{
|
|
public class ClickSelector : Manipulator
|
|
{
|
|
public MouseButton activateButton { get; set; }
|
|
|
|
public ClickSelector()
|
|
{
|
|
// snoop events before children
|
|
phaseInterest = EventPhase.Capture;
|
|
activateButton = MouseButton.LeftMouse;
|
|
}
|
|
|
|
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
|
|
{
|
|
var selectable = finalTarget.GetFirstOfType<ISelectable>();
|
|
if ( selectable==null || !selectable.IsSelectable())
|
|
{
|
|
return EventPropagation.Continue;
|
|
}
|
|
|
|
var graphView = target as GraphView;
|
|
if (graphView == null)
|
|
{
|
|
throw new InvalidOperationException("Manipulator can only be added to a GraphView");
|
|
}
|
|
|
|
switch (evt.type)
|
|
{
|
|
case EventType.MouseDown:
|
|
if (evt.button == (int)activateButton)
|
|
{
|
|
if (graphView.selection.Contains(selectable))
|
|
{
|
|
if (evt.control)
|
|
{
|
|
graphView.RemoveFromSelection(selectable);
|
|
return EventPropagation.Stop;
|
|
}
|
|
break;
|
|
}
|
|
|
|
var ve = selectable as VisualElement;
|
|
if (ve != null && ve.parent == graphView.contentViewContainer)
|
|
{
|
|
if (!evt.control)
|
|
graphView.ClearSelection();
|
|
graphView.AddToSelection(selectable);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return EventPropagation.Continue;
|
|
}
|
|
}
|
|
}
|