Esempio n. 1
0
        private IObservable <AudioEventType> OnAudioEventAsObservable()
        {
            TimePair = AudioSource
                       .ObserveEveryValueChanged(x => x.time)
                       .Pairwise()
                       .ToReactiveProperty();
            switch (AudioEventType)
            {
            case AudioEventType.Play:
            case AudioEventType.Stop:
            case AudioEventType.Pause:
            case AudioEventType.UnPause:
                return(AudioSource
                       .ObserveEveryValueChanged(x => x.isPlaying)
                       .Select(x => DetectAudioEventType(x, AudioSource.clip))
                       .Where(x => AudioEventType == x));

            case AudioEventType.Loop:
                return(TimePair
                       .Where(xs => AudioSource.isPlaying && xs.Current < xs.Previous && xs.Previous > 0.0f)
                       .Select(_ => AudioEventType.Loop));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        public BattleInputService(IEquipmentInput equipmentInput)
        {
            this.equipmentInput = equipmentInput;

            isTouched = Observable.EveryUpdate()
                        .Select(_ => Input.GetMouseButton(0))
                        .Where(_ => !IsTouchingUI)
                        .ToReactiveProperty()
                        .AddTo(disposables);

            isTouched.Where(b => b)
            .Subscribe(_ => touchStartPosition = Input.mousePosition)
            .AddTo(disposables);

            isTouched.Where(b => b)
            .Subscribe(_ => touchStartTime = DateTime.Now)
            .AddTo(disposables);
        }
Esempio n. 3
0
 IObservable <Unit> onClickAsObservable()
 {
     return(isTouched
            .Where(value =>
     {
         if (value)
         {
             return false;
         }
         var touchTime = DateTime.Now - touchStartTime;
         var dragAmount = Input.mousePosition - touchStartPosition;
         return touchTime < touchTimeThresholdForClick &&
         dragAmount.sqrMagnitude < SqrDragAmountThresholdForClick;
     })
            .AsUnitObservable());
 }