10
2014
New UI: Full View Image Panner
New UI: Image Panner Tutorial (where scrolling area scales to full camera view size) with ZERO lines of code 🙂
Requires 4.6.0 Beta (17 or 18) : http://unity3d.com/unity/beta/4.6
Tutorial steps
• Add new canvas from menu: GameObject / UI / Canvas
• While Canvas gameobject is selected: Right click over it, select> Create Empty
• Rename the new empty “GameObject” as “ScrollRect” (optional)
• While ScrollRect gameobject is selected: Add ScrollRect component to it
• While ScrollRect gameobject is selected: Right click over it, select> UI / Image
• Get some test image, I used this one:
“Nusfjord road, 2010 09” by Ximonic, Simo Räsänen – Own work” Licensed under GNU Free Documentation License via Wikimedia Commons
http://commons.wikimedia.org/wiki/File:Nusfjord_road,_2010_09.jpg#mediaviewer/File:Nusfjord_road,_2010_09.jpg
• Select your image from the project window, then on the inspector set it as sprite and adjust max size:
Set Texture Type as “Sprite (2D and UI)”
Set Max Size as 4096 (or other size which is suitable for your image)
• Then assign the sample image into “Image” gameobject as Source Image (in Image component)
• Enable [x] Preserve Aspect
• Click “Set Native Size” (your image rect transform Width & Height become the same as the original imaze, 4096×1673 in my test image)
• Select ScrollRect gameobject: Then Drag “Image” gameobject as Content for the Scroll Rect component
• While ScrollRect is selected: Press T (or click the 2D transform tool(?) from toolbar)
• Resize ScrollRect to match the Canvas by dragging those blue dots, they will snap to canvas borders
• Then also drag the anchors into Canvas borders (to make the ScrollRect scale with canvas size)
• Hit play!
Webplayer:
http://unitycoder.com/upload/demos/UI_ImagePanner/
(12mb due to large image – published with beta17 webplayer, had to manually re-install webplayer from http://unity3d.com/webplayer on another pc)
—
References:
Here you’ll learn how easy it is to add scrollbars to that scrollrect:
http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui
Related Posts
3 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
3DBuzz Releases Over 5 Hours of Training for the New UI (part 1 free)
http://forum.unity3d.com/threads/3dbuzz-releases-over-5-hours-of-training-for-the-new-ui.268655/
Awesome 3D scene you have designed here
Unity 4.6 GUI Tutorials (menu, healthbar HUD, scroll menu, etc)
http://forum.unity3d.com/threads/unity-4-6-gui-tutorials-by-the-game-contriver.268319/