コード例 #1
0
 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;
         }
     }
 }
コード例 #2
0
 public void RemoveSelected(CanvasElementBase element)
 {
     m_selectedElements.Remove(element);
 }
コード例 #3
0
 public void AddSelected(CanvasElementBase element)
 {
     m_selectedElements.Add(element);
 }
コード例 #4
0
 public bool IsSelected(CanvasElementBase element)
 {
     return(m_selectedElements.Contains(element));
 }
コード例 #5
0
 public void RemoveElement(CanvasElementBase element)
 {
     m_elements.Remove(element);
 }
コード例 #6
0
 public void AddElement(CanvasElementBase element)
 {
     m_elements.Add(element);
 }