protected override void ProcessEventInCanvas(CanvasContext canvasCtx) { base.ProcessEventInCanvas(canvasCtx); if (m_mode == WayPointsEMode.None) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { //双击边改变方向 var element = canvasCtx.TestPoint(canvasCtx.m_curLocalPosition); if (element != null) { if (element is Edge && element == m_lastClickElement) { if (m_frameCount - m_lastClickFrame < 40) { m_lastClickFrame = m_frameCount; (element as Edge).ChangeDir(); } } m_lastClickFrame = m_frameCount; Debug.Log(m_lastClickFrame); m_lastClickElement = element; } //添加点 if (Event.current.control) { m_wayPointsData.AddPoint(canvasCtx.m_curLocalPosition); } } if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { //在点上点击鼠标右键开始添加边 var element = canvasCtx.TestPoint(canvasCtx.m_curLocalPosition); if (element != null && element is Point) { m_edgeStart = element as Point; m_mode = WayPointsEMode.AddEdge; } } //删除所选 if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Delete) { TryDelete(canvasCtx); } } else if (m_mode == WayPointsEMode.AddEdge) { var element = canvasCtx.TestPoint(canvasCtx.m_curLocalPosition); bool canAddEdge = element != null && element is Point && element != m_edgeStart && !m_wayPointsData.ContainEdge(m_edgeStart, element as Point); if (canAddEdge) { m_addEdgeColor = Color.green; } else { m_addEdgeColor = Color.red; } //松开鼠标右键添加边 if (Event.current.type == EventType.MouseUp && Event.current.button == 1) { if (canAddEdge) { m_wayPointsData.AddEdge(m_edgeStart as Point, element as Point); } m_mode = WayPointsEMode.None; } else if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { //添加点自动连成边,并继续添加边 var node = m_wayPointsData.AddPoint(canvasCtx.m_curLocalPosition); m_wayPointsData.AddEdge(m_edgeStart as Point, node); m_edgeStart = node; } } }
public void RemoveSelected(CanvasElementBase element) { m_selectedElements.Remove(element); }
public void AddSelected(CanvasElementBase element) { m_selectedElements.Add(element); }
public bool IsSelected(CanvasElementBase element) { return(m_selectedElements.Contains(element)); }
public void RemoveElement(CanvasElementBase element) { m_elements.Remove(element); }
public void AddElement(CanvasElementBase element) { m_elements.Add(element); }