Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - davitosan

Pages: [1]
1
NGUI 3 Support / Re: UIWrapContent ItemHeight (itemSize)
« on: November 06, 2017, 04:41:25 PM »
I don't understand how adjusting the scroll view's dimensions help with having different sized content.
I don't think I explained my question correctly. Here is an image of what I'm trying to accomplish.


3
NGUI 3 Support / UIWrapContent ItemHeight (itemSize)
« on: November 02, 2017, 08:14:58 PM »
I have a ScrollView with an unknown number of items, because of this I am using UIWrapContent.

The design calls for this scroll view to have items organized by categories. At the start of each category the design calls for a 'label' item.
The desire is to have the 'label' item to be smaller then the actual items. If they were all the same size it would look odd.

From what I can gather, UIWrapContent only supports constant item sizes.

Does UIWrapContent support items of varying sizes?
(3.9.4)

Thank you.

4
Posting here because it's the top google serach.

I was able to get UIScrollBar working with UIWrapContent. Do not reference the scroll bar in your scroll view script.

The only assumption in the posted code is that your vertical scrollbars go top to bottom and your horizontal scroll bars go left to right. I'm sure you can easily modify if this assumption isn't true to you.

do this code when the scrollview moves. EX: scrollView.onMomentumMove += UpdateScrollbar;

_svStartLocalPos = _scrollView.transform.localPosition;

  1. UpdateScrollbar()
  2. {
  3.    float pct = 0.0f;
  4.    float endPos = 0.0f;
  5.    if(_scrollView.movement == UIScrollView.Movement.Vertical)
  6.    {
  7.       endPos = (_wrapContent.itemSize * (NUM_ITEMS / (float)NUM_COLUMNS) - _uiPanel.GetViewSize().y) + _svStartLocalPos.y;
  8.       pct = Mathf.Clamp((_scrollView.transform.localPosition.y - _svStartLocalPos.y) / (endPos - _svStartLocalPos.y), 0.0f, 100.0f);
  9.    }
  10.    else if(_scrollView.movement == UIScrollView.Movement.Horizontal)
  11.    {
  12.       endPos = (_wrapContent.itemSize * (NUM_ITEMS / (float)NUM_ROWS) - _uiPanel.GetViewSize().x) - Mathf.Abs(_svStartLocalPos.x);
  13.       pct = Mathf.Clamp((_scrollView.transform.localPosition.x - _svStartLocalPos.x) / (_svStartLocalPos.x - endPos), 0.0f, 100.0f);
  14.    }
  15.  
  16.    _scrollBar.value = Mathf.Lerp(_scrollBar.value, pct, 0.1f);
  17. }
  18.  

If you want to drag the scroll bar or click on the background to jump
  1. if(_scrollBar.backgroundWidget != null)
  2. {
  3.    UIEventListener bgl = UIEventListener.Get(_scrollBar.backgroundWidget.gameObject);
  4.    if(bgl != null)
  5.    {
  6.       bgl.onPress += OnScrollBarPressed;
  7.       bgl.onDrag += OnScrollBarDragged;
  8.    }
  9. }
  10.  
  11. void OnScrollBarPressed(GameObject go, bool isPressed)
  12. {
  13.    if(!isPressed)
  14.    {
  15.       OnScrollBarChanged();
  16.    }
  17. }
  18.  
  19. void OnScrollBarDragged(GameObject go, Vector2 delta)
  20. {
  21.    OnScrollBarChanged();
  22. }
  23.  
  24. void OnScrollBarChanged()
  25. {
  26.    Vector3 newLocalPos = _scrollView.gameObject.transform.localPosition;
  27.    if(_scrollView.movement == UIScrollView.Movement.Vertical)
  28.    {
  29.         newLocalPos.y = _scrollBar.value * (_wrapContent.itemSize * (NUM_ITEMS / (float)NUM_COLUMNS) - _uiPanel.GetViewSize().y) + _svStartLocalPos.y;
  30.    }
  31.    else if(_scrollView.movement == UIScrollView.Movement.Horizontal)
  32.    {
  33.       newLocalPos.x = -_scrollBar.value * (_wrapContent.itemSize * (NUM_ITEMS / (float)NUM_ROWS) - _uiPanel.GetViewSize().x) + _svStartLocalPos.x;
  34.    }
  35.    SpringPanel.Begin(_scrollView.panel.cachedGameObject, newLocalPos, 8).onFinished = OnSpringPanelFinished;
  36. }
  37.  
  38. void OnSpringPanelFinished()
  39. {
  40.    _scrollView.RestrictWithinBounds(false);
  41. }
  42.  

5
NGUI 3 Support / Re: UIWrapContent with multiple columns
« on: June 29, 2016, 10:30:26 PM »
I've came across this forum post
http://www.tasharen.com/forum/index.php?topic=8936.0 - Runtime dynamic scrollview

In it, ArenMook gives the advice:
Quote
If you need multiple rows, then organize your content like this:

UIWrapContent
- Row 1 (UIGrid)
-- Item 1
-- Item 2
-- Item 3
- Row 2 (UIGrid)
-- Item 4
-- Item 5
-- Item 6

I'm attempting to do so with Example 14 - Vertical 3. This is how I've set it up, looks fine before playing. I made sure the UIPanel is wide enough.


but, after pressing play, the UIGrid objects are placed on the same x (column), and for some reason the first grid is placed down one height (-100). I haven't been able to figure out how to get the two columns.

6
NGUI 3 Support / Re: UIWrapContent with multiple columns
« on: June 28, 2016, 05:43:51 PM »
This is the solution I've come up with that doesn't use UIWrapContent.
There seems to be some error when we are at the moment we need to reposition the scrollview, sometimes it get's stuck and needs an extra nudge from user input; sometimes the next row doesn't populate for a cell.

+Root (Managing Script)
|-UIScrollBar
|-UIPanel+UIScrollView(Unreferenced ScrollBars)
|--UITable(Columns: 2, Direction: Down, Pivot: Top Left)
|---UIDragScrollView
|---UIDragScrollView
|---UIDragScrollView
...


Here is code. Two vars are located in a different class:
-TopCellIndex: is an int specifying the top cell being shown by the scrollview
-data: is a list of all the objects this scrollview will be scrolling through.

  1. public class MultiColumnWrap : MonoBehaviour
  2. {
  3.         [Header("Prefabs")]
  4.         public GameObject CellPrefab;
  5.  
  6.         [Header("NGUI Scrolling")]
  7.         public UIPanel _UIPanel;
  8.         public UIScrollView _scrollView;
  9.         public UITable _table;
  10.         public UIScrollBar _scrollBar;
  11.  
  12.         private List<CellScript> _cellList;
  13.         private GameObject _lastCell
  14.  
  15.         private int _numCellsInPanel;   //This is how many cells the panel can fit
  16.         private Vector2 _cellSize;
  17.         private float _svStartingPosY;
  18.  
  19.         void Start()
  20.         {
  21.                 //Instantiate enough Prefabs to fill our Panel and then some. This will be our cycling pool of Cells
  22.                 _cellList = new List<CellScript>();
  23.  
  24.                 //Get Bounds of the prefabs that will populate this view
  25.                 GameObject template = NGUITools.AddChild(_table.gameObject, CellPrefab);
  26.                 Bounds b = NGUIMath.CalculateRelativeWidgetBounds(template.transform, true);
  27.                 GameObject.Destroy(template);
  28.  
  29.                 //Calculate the maximum number of cells a user could see within the panel
  30.                 _cellSize.x = b.size.x;
  31.                 _cellSize.y = b.size.y;
  32.  
  33.                 //Calculate how many cells we can fit in the panels clip region
  34.                 _numCellsInPanel = Mathf.CeilToInt(_UIPanel.baseClipRegion.w / (_cellSize.y + _table.padding.y)) * _table.columns;
  35.                 //Add one more row to cover scrolling
  36.                 _numCellsInPanel += Mathf.FloorToInt(_UIPanel.baseClipRegion.z / (_cellSize.x + _table.padding.x));
  37.                 //Instantiate cells and make them inactive
  38.                 for(int i = 0; i < _numCellsInPanel; i++)
  39.                 {
  40.                         GameObject cellGO = NGUITools.AddChild(_table.gameObject, CellPrefab);
  41.                         CellScript cellScript = cellGO.GetComponent<CellScript>();
  42.                         if(cellScript != null)
  43.                         {
  44.                                 _cellList.Add(cellScript);
  45.                         }
  46.                         cellGO.SetActive(false);
  47.                 }
  48.  
  49.                 //Set the Cells with our Data
  50.                 for(int i = TopCellIndex, j = 0; i < data.Length && j < _numCellsInPanel; i++, j++)
  51.                 {
  52.                         CellScript cellScript = _cellList[j].GetComponent<CellScript>();
  53.                         if(cellScript != null)
  54.                         {
  55.                                 _lastCell = cellScript[i];
  56.  
  57.                                 cellScript.gameObject.SetActive(true);
  58.                                 cellScript.SetData(data[i]);
  59.                         }
  60.                 }
  61.  
  62.                 _table.repositionNow = true;
  63.                 _scrollView.ResetPosition();
  64.  
  65.                 //Start our update loop
  66.                 StartCoroutine(UpdateCR());
  67.         }
  68.  
  69.         IEnumerator UpdateCR()
  70.         {
  71.                 yield return null; //Wait for NGUI to Reposition
  72.  
  73.                 _svStartingPosY = _scrollView.transform.localPosition.y;
  74.  
  75.                 //let's spin our main loop
  76.                 while(true)
  77.                 {
  78.                         //Make sure we aren't already showing the bottom cell
  79.                         if(_lastCell != data[data.Length - 1])
  80.                         {
  81.                                 //Check if we moved a row off screen - Down
  82.                                 if(_scrollView.transform.localPosition.y > (_svStartingPosY + _cellSize.y))
  83.                                 {
  84.                                         MoveScrollView(true);
  85.                                 }
  86.                         }
  87.                         else
  88.                         {
  89.                                 _scrollView.RestrictWithinBounds(true);
  90.                         }
  91.  
  92.                         //Make sure we aren't already showing the top cell
  93.                         if(TopCellIndex > 0)
  94.                         {
  95.                                 //Check if we moved a row off screen - Up
  96.                                 if(_scrollView.transform.localPosition.y < _svStartingPosY)
  97.                                 {
  98.                                         MoveScrollView(false);
  99.                                 }
  100.                         }
  101.                         else
  102.                         {
  103.                                 _scrollView.RestrictWithinBounds(true);
  104.                         }
  105.  
  106.                         UpdateScrollbar();
  107.  
  108.                         yield return null;//tick
  109.                 }
  110.         }
  111.  
  112.         void MoveScrollView(bool moveDown)
  113.         {
  114.                 if(moveDown == true)
  115.                 {
  116.                         TopCellIndex += _table.columns;
  117.                 }
  118.                 else
  119.                 {
  120.                         TopCellIndex -= _table.columns;
  121.                 }
  122.  
  123.                 Mathf.Clamp(TopCellIndex, 0, data.Length);
  124.  
  125.                 for(int i = 0; i < _cellList.Count; i++)
  126.                 {
  127.                         CellScript currCell = _cellList[i];
  128.                         if(TopCellIndex + i >= data.Length)
  129.                         {
  130.                                 //We've run out of players on the data side
  131.                                 currCell.gameObject.SetActive(false);
  132.                         }
  133.                         else
  134.                         {
  135.                                 //Set the data, and update
  136.                                 currCell.gameObject.SetActive(true);
  137.  
  138.                                 _lastCell = data[TopCellIndex + i];
  139.  
  140.                                 currCell.SetData(_lastCell);
  141.                         }
  142.                 }
  143.  
  144.                 float distance = _cellSize.y;
  145.                 _scrollView.MoveRelative(new Vector3(0.0f, moveDown ? -distance : distance, 0.0f));
  146.         }
  147.  
  148.         void UpdateScrollbar()
  149.         {
  150.                 if(data.Length < _numCellsInPanel)
  151.                 {
  152.                         _scrollBar.gameObject.SetActive(false);
  153.                 }
  154.                 else if(data.Length > 0)
  155.                 {
  156.                         _scrollBar.gameObject.SetActive(true);
  157.  
  158.                         float pct = TopCellIndex / (float)(data.Length - _numCellsInPanel);
  159.                         _scrollBar.value = Mathf.Lerp(_scrollBar.value, pct, 0.1f);
  160.                         _scrollBar.barSize = _numCellsInPanel / (float)data.Length;
  161.                 }
  162.         }
  163. }
  164.  

7
NGUI 3 Support / UIWrapContent with multiple columns
« on: June 28, 2016, 04:22:12 PM »
Unity 5.3.4p4
NGUI 3.9.4

I've read through these:
http://www.tasharen.com/forum/index.php?topic=10160.0 - Topic: How to use UIWrapContent programatically?
http://www.tasharen.com/forum/index.php?topic=10245.0 -  Topic: Fast scrolling Grid [add and remove row dynamically]

I have a similar requirement as the posters above.
-An undefined 'n' size of items to be scrolled within a pool of Drag Scroll Views.

Unfortunately my design requires 2 and sometimes 3 columns in my vertical scrollview.

I'm confused as to if UIWrapContent supports that. Can it be used with Table or Grid?

8
NGUI 3 Documentation / Re: UIScrollView
« on: June 03, 2014, 04:03:23 PM »
Hello,

I've implemented the UIScrollView using Example 7 Scroll View (Panel) as a reference. Works as I need, thank you very much.

In your example you are emulating a shop where a user can select and purchase items.

My question is, is it be possible to maintain the scroll functionality as is but limit the area that would purchase the item? Adding a buy now button below the gold price per item to where clicking the button and only the buttons executes some method. But dragging anywhere including the button scrolls the view.

If case my question/description isn't clear enough. The only thing that I can think of that is similar is Farm Heroes (mobile) Leaderboard. I cannot find any video of anyone actually doing this though.

I figured it out. I guess I just needed to write it out. Here is my solution

Panel
- Scroll View
- - Grid
- - - Item
- - - - Button
- - - Item
- - - - Button

The button contains a collider and a UIForward Events script. I forward the Events to the Item (Buttons Parent).

9
NGUI 3 Documentation / Re: UIScrollView
« on: June 03, 2014, 03:46:52 PM »
Hello,

I've implemented the UIScrollView using Example 7 Scroll View (Panel) as a reference. Works as I need, thank you very much.

In your example you are emulating a shop where a user can select and purchase items.

My question is, is it be possible to maintain the scroll functionality as is but limit the area that would purchase the item? Adding a buy now button below the gold price per item to where clicking the button and only the buttons executes some method. But dragging anywhere including the button scrolls the view.

If case my question/description isn't clear enough. The only thing that I can think of that is similar is Farm Heroes (mobile) Leaderboard. I cannot find any video of anyone actually doing this though.

Pages: [1]