Author Topic: Vectrosity lines between UI elements with clipping...  (Read 7405 times)

Grofit

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Vectrosity lines between UI elements with clipping...
« on: August 16, 2012, 04:37:25 PM »
I have got an issue at the moment where I am using Vectrosity to draw lines between certain UI elements whilst clipping, it is for a large map so I want to pan around and draw lines linking areas of importance to each other to show trade routes etc, currently I am using something similar to this:

  1. var uiElement1 = // Some Element, lets say texture
  2. var uiElement2 = // Some Other Element lets say texture
  3. var uiElementContainer = // Some panel which contains all ui elements
  4. var guiCamera = GetComponentInChildren<Camera>();
  5. var transformedPosition1 = guiCamera.WorldToScreenPoint(uiElement1.transform.position);
  6. var transformedPosition2 = guiCamera.WorldToScreenPoint(uiElement2.transform.position);
  7. var line = VectorLine.SetLine(Color.red, transformedPosition1, transformedPosition2);
  8. line.vectorObject.transform.parent = uiElement1.transform; // Add under uiElement 1 to clip when it moves off the panel
  9. line.Draw3DAuto(uiElementContainer.transform);
  10. line.lineWidth = 2;

I can fully appreciate that you cannot offer any support as far as vectrosity goes, but if we just assume it acts like a normal game object for all intents and purposes, the problem is that it doesn't seem to scroll properly, its like it scrolls 1/3 the speed and is 1/3 the size... I am assuming its down to the WorldToScreenPoint usage or something but I am no whizz when it comes to 3d transforms so am wondering if there is anything special I need to do to get object displaying correctly when scrolling?

On a side note I am surprised there are not more Vectrosity + NGui questions...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vectrosity lines between UI elements with clipping...
« Reply #1 on: August 16, 2012, 05:30:40 PM »
I'm not sure what scrolling has to do with anything. Using vectrocity to draw something is one thing, but scrolling? That's totally unrelated.

Grofit

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Vectrosity lines between UI elements with clipping...
« Reply #2 on: August 17, 2012, 02:50:47 AM »
When you use the scrollbars within the context of an NGui DraggablePanel, the scroll bars move the clipping area around (I am assuming) so it will show and hide elements based on the scrolled position (or internal position if the scrollbars are just updating some internal position).

Either way the reason I mention the scroll bars is because I am drawing the lines where the element should be within the scene (also viewed through the debugger to check they are correct which they seem to be) but the elements appear elsewhere in the actual game so I am just wondering if given the above psudocode for drawing a line between 2 NGUI objects am I missing something which is specific to how NGUI operates? As I am still a novice at unity, so it can be a bit confusing when there is a main camera, and another camera in the NGUI part but this displays within the main camera anyway, so I could be missing a transform or some translation due to the way NGUI is rendered, especially when its being offset by a draggable panel with scrollbars.

So that is why I mentioned them, and was hoping someone who has more experience with NGUI/Unity would just see straight away where I am going wrong with the getting and assigning of the points to world space etc and just point me in the right direction.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vectrosity lines between UI elements with clipping...
« Reply #3 on: August 17, 2012, 09:48:50 AM »
The code looks fine to me.  Keep in mind though, uiElement.transform.position will give you the pivot point of the widget, whatever it may be -- center, top left, etc -- whatever you set it to.

Grofit

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Vectrosity lines between UI elements with clipping...
« Reply #4 on: August 17, 2012, 11:41:06 AM »
Hmmm ok well thanks for taking a look, it may be down to them using 2 different cameras too, as although the lines are attached under your camera, I think vectrosity draws with its own camera, so will have to look into that.