Author Topic: UIAnchor and UIStretch wrong update in editor  (Read 6503 times)

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
UIAnchor and UIStretch wrong update in editor
« on: August 06, 2012, 06:13:08 AM »
I have some wired behavior with the UIAnchor and UIStretch components inside of the editor.

I have a UIAnchor set to TopLeft at a resolution of 480X320
  • The Position of the Anchor is X:-240 Y:160.
  • If i go to the scene view and press save the position is now: X:-213.3333 Y:160.
  • And if i save again (noting deone between this steps) the position is now: X:-320 Y:160.

Is it possible that this scripts are using the scene view in this case because it does not fit at all with the game view.

A nearly the same problem i have with the scale of UIStretch
  • The scale of the sprite is X:480 Y:320.
  • If i go to the scene view and press save the scale is now: X:640 Y:480.

My understanding is that this should be only reacting to the Game view and not the Scene view.
The current Behavior makes testing very annoying.

PS: I'm using a UIRoot with the settings  Automatic = True and Manual Height = 480

Greetings Malzbier

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor and UIStretch wrong update in editor
« Reply #1 on: August 06, 2012, 02:52:44 PM »
Make sure that the size of your game window is actually able to fit the dimensions properly. Unity screen dimensions may also be delayed by one frame at edit time. If you try resizing the game window you will notice that the UI will not scale with it as you would expect to see it (and as it does if you're playing). This is because Unity is simply not sending out any update events. Without updates, there is nothing to tell the UI that the screen has changed and that it needs to be updated.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: UIAnchor and UIStretch wrong update in editor
« Reply #2 on: August 07, 2012, 03:06:48 AM »
The updating is not the problem , the problem is that the UIAnchor and UIStretch components are using the size of the scene window instead of the game window.

The problem is that i have to build a layout that fits for the resolution of 480X320 and if i change over to my scene view , this components are using the size of the scene view size to reposition and recalculate size.

Im not sure if it is related to this but the variable MScreenSize of UIPanel is changing if i go over to the scene view and save.

and resize the scene view to the same dimensions of the game view is not an option...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor and UIStretch wrong update in editor
« Reply #3 on: August 07, 2012, 12:01:18 PM »
That doesn't happen here, so I don't know what to tell you.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: UIAnchor and UIStretch wrong update in editor
« Reply #4 on: August 08, 2012, 03:32:01 AM »
You are using Camera.pixelRect to determine the size of the screen and so i wrote a debug script:
(attached to the GUI camera)
  1. using UnityEngine;
  2. using System.Collections;
  3. [ExecuteInEditMode]
  4. public class CameraDebug : MonoBehaviour {
  5.  
  6.         // Update is called once per frame
  7.         void Update () {
  8.        
  9.                 if(this.camera)
  10.                 {
  11.                         Debug.Log(this.camera.pixelRect);
  12.                 }
  13.                
  14.         }
  15. }

Game View : (left:0.00, top:0.00, width:480.00, height:320.00)
Svene View: (left:0.00, top:0.00, width:640.00, height:480.00)

thats looks like to be the problem.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: UIAnchor and UIStretch wrong update in editor
« Reply #5 on: August 09, 2012, 03:07:11 AM »
The same problem at a new project with NGUI 2.1.4.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor and UIStretch wrong update in editor
« Reply #6 on: August 09, 2012, 02:03:57 PM »
Thanks, it's on the list of things to look into.