Author Topic: SetAnchor without affecting scale.  (Read 2179 times)

vikti

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
SetAnchor without affecting scale.
« on: February 12, 2015, 06:23:57 AM »
Hello,

I add ngui prefabs dynamically that I have to anchor on regular gameobject outside the UIRoot. (They are some map markers).
The problem is that this gameobject as a World scale of 1.
So when I do the Anchor, the UIWidget size go from 80 to 2.
I tried to reset the UIWidget size to 80 (the original size) after the anchoring, but this makes offset my UIWidget out of the Panel...

I read the doc and, indeed, the target affect the actual UIrectangle.

So, what is the correct way to anchor a object with a UIRoot outside GO without affecting its scale?
         

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SetAnchor without affecting scale.
« Reply #1 on: February 13, 2015, 08:51:58 AM »
Built-in anchoring was meant to work as a part of the UI hierarchy. Why are you keeping them outside of it? You can have UI widgets anchored to 3D game objects, no problem. There is no need to have them be outside of the UI hierarchy for that.

vikti

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: SetAnchor without affecting scale.
« Reply #2 on: February 13, 2015, 02:11:19 PM »
Yep, but the object in question (OnlineMaps component) can't be in UIRoot due to the scale transformation.

vikti

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: SetAnchor without affecting scale.
« Reply #3 on: February 13, 2015, 06:07:19 PM »
I tried to do :
  1. Vector2 dummyPosOnScreen = _mapCamera.WorldToViewportPoint(_dummy.instance.transform.position);
  2. transform.position = new Vector3( dummyPosOnScreen[0], dummyPosOnScreen[1],0);

It almost do the job but the marker moves strangely. Like a parallax effect. I think there is a ratio problem to solve between the camera. Have you an idea on this ?

EDIT : Find out !!

  1. NGUIMath.OverlayPosition(transform, _dummy.instance.transform.position, _mapCamera, UICamera.currentCamera);
  2.  
  8)
« Last Edit: February 13, 2015, 06:26:03 PM by vikti »