Beispiel #1
0
 public void RemoveConnection(PTPPoint point)
 {
     if (connectedPointWeight.ContainsKey(point))
     {
         DeleteConnection(point);
         point.DeleteConnection(this);
     }
 }
Beispiel #2
0
    public void AddConnection(PTPPoint point, float weight)
    {
        //Set connection for self
        SetConnection(point, weight);

        //set connection for other point
        point.SetConnection(this, weight);
    }
Beispiel #3
0
    void OnEnable()
    {
        set      = (PTPSet)target;
        LastTool = Tools.current;

        currentSearch = SearchReason.None;

        start = null;
        end   = null;
    }
Beispiel #4
0
 void SetConnection(PTPPoint point, float weight)
 {
     if (connectedPointWeight.ContainsKey(point))
     {
         connectedPointWeight[point] = weight;
     }
     else
     {
         connectedPointWeight.Add(point, weight);
     }
 }
Beispiel #5
0
    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();
        }
    }
Beispiel #6
0
    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);
    }
Beispiel #7
0
 public int GetIndexOfPoint(PTPPoint point)
 {
     return(pointsInSet.IndexOf(point));
 }
Beispiel #8
0
    public void AddPoint(Vector3 location)
    {
        PTPPoint newPoint = new PTPPoint(location, this);

        pointsInSet.Add(newPoint);
    }
Beispiel #9
0
 void DeleteConnection(PTPPoint point)
 {
     connectedPointWeight.Remove(point);
 }