1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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.
- UIPanel itemUIPanel = itemTransform.GetComponent<UIPanel>();
- if (itemUIPanel != null)
- {
- Destroy(itemUIPanel);
- }
- }
- }
|