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 - maxtangli

Pages: [1]
1
Thanks very much for your reply :).

2
Hi, everyone.
I have to made a upScrollable/downScrollable indicator sprite.
Each time scrollView dragged or gameObjects added/removed, below is desired:

bool upScrollable = ?
bool bottomScrollable = ?
upScrollableSprite.enabled = upScrollable
bottomScrollableSprite.enabled = bottomScrollable

The quesion is how to get upScrollable/bottomScrollable ?

I tried two ways, both have defects:
1. use UIScrollBar
bool upScrollable = scrollBar.value > threshold
but threshold may varies for gameObjects count.

2. calculate with scroll.panel/ scroll.bounds.size.y / scroll.panel.GetViewSize() things.
It works, but too complex.

   public void setGameObjects(IEnumerable<GameObject> gameObjects) {
      scroll.ResetPosition();
      // clear existed
      // set new
      grid.Reposition();
      scroll.ResetPosition();

      yWhenTop = scroll.panel.clipOffset.y;
      StartCoroutine("delayedUpdateButtonVisibility");
   }

   // scroll.bounds.size seems won't update until next frame
   IEnumerator delayedUpdateButtonVisibility() {
      yield return new WaitForEndOfFrame();
      updateButtonVisibility();
   }

   float yWhenTop;
   public void updateButtonVisibility() {
      Debug.Log("updateButtonVisibility()");
      if (scroll.bounds.size.y <= scroll.panel.GetViewSize().y) { // contents less than one screen
         buttonPrev.gameObject.SetActive(false);
         buttonNext.gameObject.SetActive(false);
      } else {
         float yWhenBottom = yWhenTop - (scroll.bounds.size.y - scroll.panel.GetViewSize().y);
         buttonPrev.gameObject.SetActive(scroll.panel.clipOffset.y < yWhenTop);
         buttonNext.gameObject.SetActive(scroll.panel.clipOffset.y > yWhenBottom);
      }
   }

So what would the best practice be to indicate whether scrollView at top/bottom now?

3
Thanks for your answer.
Anticipate the coming of that feature :)

4
Suppose I have a Controller class to sort a datalist:

  1. public enum SortType {t1,t2...t20}
  2. public Class Controller {
  3.     public void sort(SortType t);
  4. }
  5.  

then I have 20 buttons to call sort.
It would be convenient by using UIButton inspector to set callback function and param,
but when I select sort method, the appeared arg0 turn to type of Object.

So what would be the best practice to use UIButon for this case?

I know I could attach a script for each button, but it still need extra code:
  1. class SortButton : Monobehavior {
  2.     public SortType type;
  3.     public Controller controller;
  4.     void OnClick() {controller.sort(type)}
  5. }
  6.  

Pages: [1]