public void RemoveConnection(PTPPoint point) { if (connectedPointWeight.ContainsKey(point)) { DeleteConnection(point); point.DeleteConnection(this); } }
public void AddConnection(PTPPoint point, float weight) { //Set connection for self SetConnection(point, weight); //set connection for other point point.SetConnection(this, weight); }
void OnEnable() { set = (PTPSet)target; LastTool = Tools.current; currentSearch = SearchReason.None; start = null; end = null; }
void SetConnection(PTPPoint point, float weight) { if (connectedPointWeight.ContainsKey(point)) { connectedPointWeight[point] = weight; } else { connectedPointWeight.Add(point, weight); } }
void CheckEndOfDrag(Event e) { //Check the event type and make sure it's left click. if (e.type == EventType.mouseUp && e.button == 0) { if (start != null && end != null) { if (action == ConnectionAction.Add) { start.AddConnection(end, 1); } else { start.RemoveConnection(end); } } currentSearch = SearchReason.None; start = null; end = null; e.Use(); } }
void CreateConnectionEditor(List <PTPPoint> points, Event e) { Vector2 screenLocation = e.mousePosition; PTPPoint newEnd = null; float closestDist = float.MaxValue; CheckMouseEvent(e); for (int i = 0; i < points.Count; i++) { if (points[i] == start || points[i] == end) { if (action == ConnectionAction.Add) { Handles.color = Color.green; } else { Handles.color = Color.red; } } else { Handles.color = Color.white; } Handles.SphereHandleCap(i, points[i].GetLocation(), Quaternion.identity, .75f, EventType.Repaint); //todo REPLACE with more reliable system if (currentSearch != SearchReason.None && Camera.current != null) { Vector2 screen = HandleUtility.WorldToGUIPoint(points[i].GetLocation()); float dist = Vector2.Distance(screen, screenLocation); if (dist < closestDist && dist < targetSnapDistance) { if (currentSearch == SearchReason.Start) { start = points[i]; closestDist = dist; } else if (points[i] != start) { closestDist = dist; newEnd = points[i]; } } } DrawConnections(points, i); } end = newEnd; CheckForActionChange(e); if (start != null) { DrawLine(HandleUtility.GUIPointToWorldRay(e.mousePosition).origin); } CheckEndOfDrag(e); }
public int GetIndexOfPoint(PTPPoint point) { return(pointsInSet.IndexOf(point)); }
public void AddPoint(Vector3 location) { PTPPoint newPoint = new PTPPoint(location, this); pointsInSet.Add(newPoint); }
void DeleteConnection(PTPPoint point) { connectedPointWeight.Remove(point); }