Пример #1
0
 public void RemoveConnection(PTPPoint point)
 {
     if (connectedPointWeight.ContainsKey(point))
     {
         DeleteConnection(point);
         point.DeleteConnection(this);
     }
 }
Пример #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);
    }
Пример #3
0
    void OnEnable()
    {
        set      = (PTPSet)target;
        LastTool = Tools.current;

        currentSearch = SearchReason.None;

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

        pointsInSet.Add(newPoint);
    }
Пример #9
0
 void DeleteConnection(PTPPoint point)
 {
     connectedPointWeight.Remove(point);
 }