ScrollLongRectBar.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ScrollLongRectBar : MonoBehaviour {
  4. public ScrollPage mScrollPage;
  5. private GameObject mPreSelect;
  6. private GameObject mPreDot;
  7. private int mPageCount;
  8. private int mSelectIndex;
  9. private GameObject mSelectItem;
  10. // Use this for initialization
  11. void Awake() {
  12. mPreSelect = Gow.c(gameObject).Find("select");
  13. mPreDot = Gow.c(gameObject).Find("dot");
  14. Gow.c(gameObject.transform.parent.gameObject ).PostPrefab(mPreSelect );
  15. Gow.c(gameObject.transform.parent.gameObject ).PostPrefab(mPreDot );
  16. mScrollPage.OnPageChanged += OnPageChange;
  17. mScrollPage.OnPageStart += OnPageStart;
  18. }
  19. void OnPageStart(int selectIndex ){
  20. mPageCount = mScrollPage.GetPageCount();
  21. mSelectIndex = 0;
  22. mSelectItem = Tools.createGameObjectTr(mPreSelect, gameObject );
  23. mSelectItem.SetActive(true);
  24. for (int i = 1; i < mPageCount; i++){
  25. GameObject pageItem = Tools.createGameObjectTr(mPreDot, gameObject );
  26. pageItem.SetActive(true );
  27. }
  28. OnPageChange(selectIndex );
  29. }
  30. void OnPageChange(int selectIndex ){
  31. //Debug.LogWarning("new index is " + selectIndex );
  32. if (selectIndex == mSelectIndex ){
  33. return;
  34. }
  35. mSelectIndex = selectIndex;
  36. mSelectItem.transform.SetSiblingIndex(mSelectIndex );
  37. }
  38. }