0

I have created a level editor using new UI system in Unity3D. Using Level Editor:

  • I can drag the ui elements,
  • I am able to save them in scriptable objects

But how could i save and load them at runtime?

I mean, if i create a level with some {width x hight} resolution and if i load it on different resolution, then the whole UI positioning get distorted.

How could i anchor them correctly programmatically?

Any help would be appreciated.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
chetan rane
  • 533
  • 2
  • 10
  • 25
  • Provided I haven't completely missed your point... I use the canvas scaler for the new UI upgrade. You can set it to scale to screen res and specify default width and heights for it. It's a component under the Canvas object. As it stands and if using Unity 4.6.x, you may find that you've got it set to constant pixel size. – laminatefish Feb 20 '15 at 08:57
  • thanks LokiSinclair for reply but i want to store position of ui element for ex. i have one image and using drag i am changing the position now i want to save its position in scriptable object and then later i want to load that image exactly on the same position image.transform.position is not working...so what is the correct way? – chetan rane Feb 20 '15 at 10:31

2 Answers2

4

There are good video tutorials about the 4.6.x UI here:
http://unity3d.com/learn/tutorials/modules/beginner/ui.

Especially for positioning the elements I recommend watching: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.

I suggest you learn how to use the anchor correctly first. If you want to change the position and size of UI element in a script you can do that through the RectTransform component. It offers functions like offsetMax,offsetMin and sizeDelta for position your UI element. The functions you need to use depend on your anchor setting.

hamalaiv
  • 828
  • 2
  • 9
  • 18
1

as LokiSinclair said. You just need to Adjust the Scale that the new UI provided. It is the four Arrow on the Canvas of each Object and every UI object is inheriting their scale behavior from their Parent.

Aizen
  • 1,807
  • 2
  • 14
  • 28