Author Topic: SoftClip issue with custom positionning.  (Read 1469 times)

alfredduler

  • Guest
SoftClip issue with custom positionning.
« on: August 29, 2013, 11:15:46 AM »
Hello again.

Well, in order to achieve to maintain position and scale according to screen size , I managed to hack a bit UIRoot to get what I want.

It works pretty well since what I get on my screen is what I get on my iPhone and iPad.

The problem is now the scrollview seems broken, shame on me.

Here is how I modified UIRoot, in its Awake function:

  1.                 GameObject.Find("Camera").GetComponent<Camera>().orthographicSize = Screen.width/2;
  2.                 Vector3 cameraScale = new Vector3(Screen.width/2, Screen.width/2, 0);
  3.                 GameObject.Find("Camera").transform.localScale = cameraScale;
  4.                
  5.                 minimumHeight = Screen.width;
  6.                 maximumHeight = Screen.width * 2;
  7.  

But now I get this error under the Soft Clip enum on the Inspector:

" Clipped panels must have a uniform scale, or clipping won't work properly!  "

And so it makes the clipping slighly downing when scrolling to the bottom.

Is this possible to get through this easily or am I trapped?

Thanks again!

Alfred

alfredduler

  • Guest
Re: SoftClip issue with custom positionning.
« Reply #1 on: August 29, 2013, 12:03:58 PM »
Well, I finally managed to get it work.



Regarding the error, I search on the UIPanelInspector what caused the issue. It was doing a verification on a function NGUIEditorTools:

  1. static public bool IsUniform (Vector3 scale)
  2.         {
  3.                 return Mathf.Approximately(scale.x, scale.y) && Mathf.Approximately(scale.x, scale.z);
  4.         }

So I searched what could be different in my hierarchy in both x,y and z axis.

Figure it out that it was, indeed, from what of my wonderful hack:

  1. Vector3 cameraScale = new Vector3(Screen.width/2, Screen.width/2, 0);
  2. GameObject.Find("Camera").transform.localScale = cameraScale;
  3.  

So I just basically modified it to be:
  1. Vector3 cameraScale = new Vector3(Screen.width/2, Screen.width/2, Screen.width/2);
  2. GameObject.Find("Camera").transform.localScale = cameraScale;
  3.  

I don't know if it good or not, it certainly dirty, but it's working I am wanted it to.

Maybe it gonna help someone one day, maybe not!



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SoftClip issue with custom positionning.
« Reply #2 on: August 29, 2013, 04:16:40 PM »
Non-uniform scaling completely breaks scrollable panels due to how they work. You shouldn't be doing it.

Furthermore.. never ever ever use GameObject.Find. Ever. When I see a poster use it, I cringe and can't even process the rest of the question. Tim even did a talk about it at Unite.