Example #1
0
 // Token: 0x06008AB0 RID: 35504 RVA: 0x0035DCAF File Offset: 0x0035C0AF
 public static int LoopValue(int value, int start, int end)
 {
     return(MathfEx.LoopValue(ref value, start, end));
 }
Example #2
0
 public static void FocusAdd(
     this Component component,
     bool isTabKey,
     Func <bool> isFocus,
     Func <int> next,
     Func <Tuple <bool, int> > direct,
     int firstIndex,
     params Selectable[] sels)
 {
     if (((IList <Selectable>)sels).IsNullOrEmpty <Selectable>())
     {
         Debug.LogError((object)"FocusRegister Selection None");
     }
     else
     {
         Selectable lastCurrent = sels.SafeGet <Selectable>(firstIndex);
         ObservableExtensions.Subscribe <Selectable>((IObservable <M0>)Observable.Select <GameObject, Selectable>((IObservable <M0>)ObserveExtensions.ObserveEveryValueChanged <Component, GameObject>((M0)component, (Func <M0, M1>)(_ => EventSystem.get_current().get_currentSelectedGameObject()), (FrameCountType)0, false), (Func <M0, M1>)(go => Object.op_Inequality((Object)go, (Object)null) ? (Selectable)go.GetComponent <Selectable>() : (Selectable)null)), (Action <M0>)(sel =>
         {
             if (((IEnumerable <Selectable>)sels).Contains <Selectable>(sel))
             {
                 lastCurrent = sel;
             }
             else
             {
                 if (!isFocus() || !Object.op_Inequality((Object)lastCurrent, (Object)null))
                 {
                     return;
                 }
                 lastCurrent.Select();
             }
         }));
         Action <int, bool> focus = (Action <int, bool>)((index, isDirect) =>
         {
             bool flag = index >= 0;
             if (!isDirect)
             {
                 index += sels.Check <Selectable>((Func <Selectable, bool>)(v => Object.op_Equality((Object)v, (Object)lastCurrent)));
             }
             MathfEx.LoopValue(ref index, 0, sels.Length - 1);
             if (!sels[index].IsInteractable() && ((IEnumerable <Selectable>)sels).Any <Selectable>((Func <Selectable, bool>)(p => p.IsInteractable())))
             {
                 if (!flag)
                 {
                     index = Mathf.Min(sels.Length, index + 1);
                 }
                 IEnumerable <int> ints1 = Enumerable.Range(index, sels.Length - index);
                 IEnumerable <int> ints2 = Enumerable.Range(0, index);
                 index = (!flag ? ints2.Reverse <int>().Concat <int>(ints1.Reverse <int>()) : ints1.Concat <int>(ints2)).FirstOrDefault <int>((Func <int, bool>)(i => sels[i].IsInteractable()));
             }
             sels[index].Select();
         });
         if (isTabKey)
         {
             ObservableExtensions.Subscribe <Unit>(Observable.Where <Unit>(Observable.Where <Unit>((IObservable <M0>)ObservableTriggerExtensions.UpdateAsObservable(component), (Func <M0, bool>)(_ => isFocus())), (Func <M0, bool>)(_ => Input.GetKeyDown((KeyCode)9))), (Action <M0>)(_ => focus(Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303) ? -1 : 1, false)));
         }
         if (!next.IsNullOrEmpty())
         {
             ObservableExtensions.Subscribe <Unit>(Observable.Where <Unit>((IObservable <M0>)ObservableTriggerExtensions.UpdateAsObservable(component), (Func <M0, bool>)(_ => isFocus())), (Action <M0>)(_ =>
             {
                 int num = next();
                 if (num == 0)
                 {
                     return;
                 }
                 focus(num, false);
             }));
         }
         if (direct.IsNullOrEmpty())
         {
             return;
         }
         ObservableExtensions.Subscribe <Unit>(Observable.Where <Unit>((IObservable <M0>)ObservableTriggerExtensions.UpdateAsObservable(component), (Func <M0, bool>)(_ => isFocus())), (Action <M0>)(_ =>
         {
             Tuple <bool, int> tuple = direct();
             if (!tuple.Item1)
             {
                 return;
             }
             focus(tuple.Item2, true);
         }));
     }
 }