Author Topic: it seems that i don't properly get positioning? help! picture included  (Read 4391 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Hi! I am struggling with this problem for a while, although i searched forum and tried to forge the solution but did not succeed.
I am trying to get two panels side by side one on the right that will hold menu buttons and one on the left that will hold content. I am using fixedSize to get everything scale properly for both mobile and desktop devices for all resolutions.

there are no step by step instructions for this kind of thing and no clear explanation how to use all those anchors,pixeadjustments and scaling styles. there are many combinations and i get entangled any time i tried to do it. sorry about asking again and again the same things but i just cant figure it out!

Look at the picture

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I cannot explain it any clearer than in the previous post you made on this very issue. http://www.tasharen.com/forum/index.php?topic=4799

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
That said, I am better at coding than explaining things, so maybe this will help you.
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UIPanel))]
  4. public class AutoAdjustPanel : MonoBehaviour
  5. {
  6.         public float x = 0.3f;
  7.         public float y = 0.5f;
  8.         public float width = 0.667f;
  9.         public float height = 1f;
  10.  
  11.         void Start ()
  12.         {
  13.                 UIPanel panel = GetComponent<UIPanel>();
  14.                 panel.clipRange = new Vector4(
  15.                         Screen.width  * (x - 0.5f),
  16.                         Screen.height * (y - 0.5f),
  17.                         Screen.width  * width,
  18.                         Screen.height * height);
  19.         }
  20. }
Attaching this script to a clipped panel will make it take 2/3rds of the screen -- so left side as well as the middle, leaving the right side for another panel. If you want the right side to be taken by a second panel, attach the same script to your 2nd panel and give it values of (x=0.8333, width = 0.333).

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
I'm confused: do you want both panel to keep the relative size, or do you want one of them to be a fixed width?

Mobiles have a bunch of different aspects, so there are many possible solutions. :)

If you want relative width, the UIStretch has a relative size exposed in the inspector: then the red panel can just be UIAnchored to the left with its pivot to the left and a UIStretch that has relative size set to ~0.8. (80 % of the screen). The green panel can be anchored to the right with its pivot set to right and a stretch of 0.2.

Of course, when I say the "panel" I mean a background sprite on each panel, since UIAnchor and UIStretch works best on something like that. If you're trying to get two draggable panels side by side like the other question asks, then you can do the same thing, but then just read the values from the sprites I*m talking about into your Cliprange on the draggablepanels and destroy the sprites afterwards. - Sure it's a roundabout way of doing it, but it works.