123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using UnityEngine;
- using System.Collections;
- public abstract class ListBase : MonoBehaviour
- {
- public Transform itemsAnchor;
- public GameObject listEmptyLabel;
- const float VERTICAL_SPACE_PER_ITEM = 150;
- const float OFFSET_Y = 100;
- #if UNITY_EDITOR
- void OnEnable()
- {
- CreateRandomRequests();
- }
- void CreateRandomRequests()
- {
- listEmptyLabel.SetActive(false);
- for (int i = 0; i < 5; i++)
- {
- PlaceItem(CreateRandomItemForTestingInEditor(i), i);
- }
- }
- #else
- void OnEnable()
- {
- if (HasItems())
- {
- listEmptyLabel.SetActive(false);
- CreateItems();
- } else
- {
- listEmptyLabel.SetActive(true);
- }
- }
- #endif
- protected abstract bool HasItems();
- protected abstract void CreateItems();
- protected abstract Transform CreateRandomItemForTestingInEditor(int index);
- protected void PlaceItem(Transform itemTransform, int row)
- {
- Vector3 originalScale = itemTransform.localScale;
- itemTransform.parent = itemsAnchor;
- itemTransform.localScale = originalScale;
- itemTransform.localPosition = new Vector3(0, (row * -VERTICAL_SPACE_PER_ITEM) + OFFSET_Y);
- //HACK:For some unknown reason, NGUI is creating a UIPanel on the second viewing on mobiles.
- //Removing it, otherwise no proper clipping is done by the parent UIPanel.
- }
- }
|