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.


Topics - matteo.piccioni

Pages: [1]
1
NGUI 3 Support / UIWrapContent - Different Item Height for rows
« on: July 15, 2014, 05:28:55 AM »
Hello,
first of all thanks for your work and thanks for the new range limit feature on UIWrap Content script.

The need to have the same height for each object is very restrictive,
Is there any chance to have UIWrapContent script where the height of the items will be retrieved automatically (if not specified) ?
It would give enormous freedom to developers and allow the creation of more flexible interfaces

Thanks!

2
NGUI 3 Support / Fast scrolling Grid [add and remove row dynamically]
« on: July 04, 2014, 06:26:03 AM »
Hello,
first of all sorry for my bad english.
I have a list of 2 hundred items, and I need to instantiate only partial content at a time and remove the previous rows as they disappears to user.

Im new to unity, I successfully created a scene with
  1. Main Camera
  2. UI Root
  3.    Scroll View
  4.       Grid
  5.  

I attach 'Manager.cs' to MainCamera, and  at start it load list of items into an array, then add the first 20 items to Grid
This script should also add more rows as the Grid scroll

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Manager : MonoBehaviour {
  6.  
  7.     public Transform panel;
  8.     public int total = 200;
  9.     public GameObject parent;
  10.  
  11.     public GameObject itemPrefab;
  12.  
  13.     public UIScrollView ScrollView;
  14.     public UIGrid Grid;
  15.  
  16.     public float cellWidth = 150;
  17.     public float cellHeight = 40;
  18.  
  19.     public int bundle = 20;
  20.     public float posY = 0f;
  21.     List<GameObject> preLoadedItemList;
  22.  
  23.     GameObject[] itemList;
  24.  
  25.     // Use this for initialization
  26.     void Start () {
  27.  
  28.         // Preloaded list of items, loaded in some way
  29.         preLoadedItemList = new List<GameObject>();
  30.         for (int i = 0; i<= total; i++) {
  31.             preLoadedItemList.Add(itemPrefab);
  32.         }
  33.  
  34.         // list of visible items
  35.         itemList = new GameObject[total];
  36.  
  37.         // the first 20 visible items
  38.         for(int i = 0; i<= bundle; i++)
  39.         {
  40.             AddItem(i);
  41.         }
  42.     }
  43.  
  44.  
  45.     void AddItem(int seq){
  46.  
  47.         if (seq < 0 || seq >= total) {
  48.             Debug.Log("Exit 1");    
  49.             return;
  50.         }
  51.         if (itemList[seq]) {
  52.             Debug.Log("Exit 2 seq: "+seq);  
  53.             return;
  54.         }
  55.  
  56.         GameObject item = NGUITools.AddChild(parent, preLoadedItemList[seq]);
  57.  
  58.         Grid.GetComponent<UIGrid>().Reposition();
  59.         ScrollView.ResetPosition();
  60.  
  61.         itemList[seq] = item;
  62.     }
  63.  
  64.  
  65.  
  66.     // check if I need to add another item into grid
  67.     void Update ()
  68.     {
  69.         //  Debug.Log ("height panel: "+panel.localPosition.y); // all times 236
  70.  
  71.         /* not working */
  72.         /*
  73.         posY = panel.localPosition.y;
  74.         int pos = Mathf.Abs(Mathf.FloorToInt(posY / cellHeight));
  75.  
  76.         Debug.Log ("POS: "+pos);
  77.  
  78.  
  79.         for (int i = -1; i < bundle; i++)
  80.         {          
  81.             int seq = i + pos;
  82.             AddItem(i + pos);
  83.         }
  84.     */
  85.     }
  86. }
  87.  

I Attach a second script to my prefabs, 'Item.cs'
The rule of Item.cs should be to remove itself (the row) when it disappear from the camera
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Item : MonoBehaviour {
  5.         Transform tr;
  6.         private float min = -400, max = 30;
  7.        
  8.         [HideInInspector]
  9.         public bool on = false;
  10.         Transform panel;
  11.        
  12.         void Start()
  13.         {
  14.                 tr = transform;
  15.                 panel = transform.parent;
  16.         }
  17.        
  18.         void OnOutside()
  19.         {
  20.                 Destroy(gameObject);
  21.         }
  22.        
  23.         void Update()
  24.         {
  25.  
  26.                 Vector3 pos = tr.localPosition;
  27.  
  28.                 if (pos.y > max || pos.y < min)
  29.                 {
  30.                         OnOutside();
  31.                 }
  32.         }
  33. }
  34.  

In the Update method I am not able to calculate when I should add a new row, could someone help me with this problem ?

Any help would be appreciated..

Thanks in advance!!

Pages: [1]