예제 #1
0
    public void RemoveLink(WaypointLink link)
    {
        bool contains = false;
        int  i        = 0;

        foreach (WaypointLink l in NeighborNodes)
        {
            if (l.Equals(link))
            {
                contains = true;
            }
        }

        if (contains)
        {
            WaypointLink[] tempList = new WaypointLink[NeighborNodes.Length - 1];
            if (NeighborNodes.Length > 1)// The length is bigger than one, so we have to make a new list.
            {
                foreach (WaypointLink l in NeighborNodes)
                {
                    if (!l.Equals(link))
                    {
                        tempList[i] = l;
                        i++;
                    }
                }
                NeighborNodes = tempList;
            }
            else
            {
                NeighborNodes = new WaypointLink[0];
            }
        }
    }
예제 #2
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }

        WaypointLink link = (WaypointLink)obj;

        if ((object)obj == null)
        {
            return(false);
        }

        if (obj.GetType() != typeof(WaypointLink))
        {
            return(false);
        }

        if ((from == link.from && to == link.to) || (from == (link.Flipped).from && to == (link.Flipped).to))
        {
            return(true);
        }

        return(base.Equals(obj));
    }
예제 #3
0
    public bool AddLink(WaypointLink link)
    {
        bool contains = false;

        foreach (WaypointLink l in NeighborNodes)
        {
            if (l.Equals(link))
            {
                contains = true;
            }
        }
        if (!contains)
        {
            WaypointLink[] tempList = new WaypointLink[NeighborNodes.Length + 1];
            tempList[NeighborNodes.Length] = link;
            for (int i = 0; i < NeighborNodes.Length; i++)
            {
                tempList[i] = NeighborNodes[i];
            }
            NeighborNodes = tempList;
            return(true);
        }
        else
        {
            return(false);
        }
    }
    public bool Unlink(WaypointLink link)
    {
        int i = 0;
        bool contains = false;
        foreach (WaypointLink l in NeighborNodes)
        {
            if (l.Equals(link))
                contains = true;
        }
        if (contains)
        {
            WaypointLink[] tempList = new WaypointLink[NeighborNodes.Length - 1];
            if (NeighborNodes.Length > 1)// The length is bigger than one, so we have to make a new list.
            {
                foreach (WaypointLink l in NeighborNodes)
                {
                    if (!l.Equals(link))
                    {
                        tempList[i] = l;
                        i++;
                    }
                }
                NeighborNodes = tempList;

            }
            else
            {
                NeighborNodes = new WaypointLink[0];
            }
            return true;
        }
        else
            return false;
    }
 public bool AddLink(WaypointLink link)
 {
     bool contains = false;
     foreach (WaypointLink l in NeighborNodes)
     {
         if (l.Equals(link))
             contains = true;
     }
     if (!contains)
     {
         WaypointLink[] tempList = new WaypointLink[NeighborNodes.Length + 1];
         tempList[NeighborNodes.Length] = link;
         for (int i = 0; i < NeighborNodes.Length; i++)
         {
             tempList[i] = NeighborNodes[i];
         }
         NeighborNodes = tempList;
         return true;
     }
     else
         return false;
 }
    void UnlinkNodes()
    {
        Event current = Event.current;
        WaypointNode cNode = null;
        // Handles.DrawRectangle(ControlID, 

        if (!current.alt)
        {
            Ray mRay = HandleUtility.GUIPointToWorldRay(current.mousePosition);
            RaycastHit rHit;
            if (Physics.Raycast(mRay, out rHit, Mathf.Infinity))
            {
                cNode = currentWaypoints.GetClosestNode(rHit.point, 1.0f);
            }

            // Clear if right mouse is pressed.
            if (current.type == EventType.mouseDown && current.button == 1)
            {
                from = Vector3.zero;
                to = Vector3.zero;
            }

            if (cNode != null)
            {
                Handles.DrawWireDisc(cNode.Position, Vector3.up, 0.5f);
                if (current.type == EventType.mouseDown && current.button == 0 && from == Vector3.zero) // Mouse1
                {
                    from = cNode.Position;
                }
                else if (current.type == EventType.mouseDown && current.button == 0 && to == Vector3.zero) // Mouse1 and we have a from
                {
                    if (cNode.Position != from)
                    {
                        to = cNode.Position;
                        WaypointLink newLink = new WaypointLink(from, to);
                        WaypointNode tempN = currentWaypoints.GetClosestNode(from);
                        if (tempN != null)
                        {
                            if (tempN.Unlink(newLink))
                            {
                                tempN = currentWaypoints.GetClosestNode(to);
                                tempN.Unlink(newLink);
                                cNode = null;
                                from = to;
                                to = Vector3.zero;
                            }
                        }
                        else
                        {
                            cNode = null;
                            from = Vector3.zero;
                            to = Vector3.zero;
                            Debug.LogError("Could not find node from list.");
                        }
                    }
                }
            }

            if (from != Vector3.zero)
            {
                Handles.DrawLine(from, rHit.point);
            }
        }

    }
예제 #7
0
    void UnlinkNodes()
    {
        Event        current = Event.current;
        WaypointNode cNode   = null;

        // Handles.DrawRectangle(ControlID,

        if (!current.alt)
        {
            Ray        mRay = HandleUtility.GUIPointToWorldRay(current.mousePosition);
            RaycastHit rHit;
            if (Physics.Raycast(mRay, out rHit, Mathf.Infinity))
            {
                cNode = currentWaypoints.GetClosestNode(rHit.point, 1.0f);
            }

            // Clear if right mouse is pressed.
            if (current.type == EventType.mouseDown && current.button == 1)
            {
                from = Vector3.zero;
                to   = Vector3.zero;
            }

            if (cNode != null)
            {
                Handles.DrawWireDisc(cNode.Position, Vector3.up, 0.5f);
                if (current.type == EventType.mouseDown && current.button == 0 && from == Vector3.zero) // Mouse1
                {
                    from = cNode.Position;
                }
                else if (current.type == EventType.mouseDown && current.button == 0 && to == Vector3.zero) // Mouse1 and we have a from
                {
                    if (cNode.Position != from)
                    {
                        to = cNode.Position;
                        WaypointLink newLink = new WaypointLink(from, to);
                        WaypointNode tempN   = currentWaypoints.GetClosestNode(from);
                        if (tempN != null)
                        {
                            if (tempN.Unlink(newLink))
                            {
                                tempN = currentWaypoints.GetClosestNode(to);
                                tempN.Unlink(newLink);
                                cNode = null;
                                from  = to;
                                to    = Vector3.zero;
                            }
                        }
                        else
                        {
                            cNode = null;
                            from  = Vector3.zero;
                            to    = Vector3.zero;
                            Debug.LogError("Could not find node from list.");
                        }
                    }
                }
            }

            if (from != Vector3.zero)
            {
                Handles.DrawLine(from, rHit.point);
            }
        }
    }