public ItemDetailViewModel(Item item = null) { Title = item?.Text; Item = item; CEP = new ReactiveProperty <string>(""); CEPBusca = CEP.Throttle(TimeSpan.FromMilliseconds(500)) .Where(x => !string.IsNullOrWhiteSpace(x) && x.Length == 9) .DistinctUntilChanged() .Select(x => x.Replace("-", "").Trim()) .ToReadOnlyReactiveProperty(); var result = CEPBusca.Select(Write) .Switch() .Do(x => Debug.WriteLine(x)) .ToReactiveProperty(); }
public WorldRunner() { Singleton <PropertyManager> .Instance.AddRootContext(this); SceneLoader instance = SceneLoader.Instance; BindingManager bind = BindingManager.Instance; CurrentChunk = PlayerData.Instance.MainChunk.CombineLatest(PlayerData.Instance.BonusChunk, (int main, int bonus) => (bonus <= -1) ? new ChunkStruct(main, bonus: false) : new ChunkStruct(bonus, bonus: true)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); MainBiomeConfig = (from chunk in PlayerData.Instance.MainChunk select Singleton <EconomyHelpers> .Instance.GetBiomeConfig(chunk)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); CurrentBiomeConfig = (from cs in CurrentChunk select Singleton <EconomyHelpers> .Instance.GetBiomeConfig(cs.Index)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); MainChunk = PlayerData.Instance.MainChunk; RelativeChunk = PlayerData.Instance.MainChunk; InBaseCamp = (from chunk in CurrentChunk select chunk.Index == 0).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); BiomeName = (from cnfg in CurrentBiomeConfig select PersistentSingleton <LocalizationService> .Instance.Text("Biome.Name." + cnfg.BiomeIndex)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); ProgressString = (from chunk in CurrentChunk where chunk.Index >= 0 select Mathf.FloorToInt(chunk.Index % 10 / 10) + 1 into curr select curr.ToString() + "/" + 1.ToString()).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); CurrentProgress = (from chunk in CurrentChunk select(float)((chunk.Index - CurrentBiomeConfig.Value.Chunk) % 10) + 1f).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); CurrentProgressInt = CurrentProgress.Select(Mathf.RoundToInt).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); (from seq in MapSequence.Pairwise() where !seq.Current && seq.Previous select seq).Delay(TimeSpan.FromSeconds(1.5)).Subscribe(delegate { bind.ChunkProgressNotification.SetActive(value: true); }).AddTo(instance); (from chunk in CurrentChunk.Pairwise() select chunk.Previous.Index < chunk.Current.Index into chunkChanged where chunkChanged select chunkChanged).Delay(TimeSpan.FromSeconds(3.0)).Subscribe(delegate { bind.ChunkProgressNotification.SetActive(value: true); }).AddTo(instance); (from chunk in CurrentChunk.Pairwise() select chunk.Previous.Index < chunk.Current.Index into progressed where progressed select progressed).Subscribe(delegate(bool progressed) { HaveProgressedInCurrentSession.SetValueAndForceNotify(progressed); }).AddTo(instance); }
public StopWatchModel() { Debug.WriteLine("StopWatchModel ctor"); IsRunning = _isRunning.ToReadOnlyReactiveProperty(); IsVisibleMillis = _isVisibleMillis.ToReadOnlyReactiveProperty(); _timeFormat = IsVisibleMillis .Select(v => v ? @"mm\:ss\.fff" : @"mm\:ss") .ToReactiveProperty(); FormattedTime = _time.CombineLatest(_timeFormat, (time, format) => TimeSpan.FromMilliseconds(time).ToString(format)) .ToReadOnlyReactiveProperty(); FormattedLaps = _laps.CombineLatest(_timeFormat, (laps, f) => laps.Select((x, i) => TimeSpan.FromMilliseconds(x).ToString(f))) .ToReadOnlyReactiveProperty(); }
void Start () { if (component != null) score = component.score_data; if (win == null) win = GameSettingsComponent.working_rules.win_condition; if (id_text != null || id_text_3d != null){ rx_id_text = LanguageController.controller.rx_load_text("basket_single") .CombineLatest(rx_score.SelectMany(rx_score.SelectMany(s=>s.rx_id)), (text, id)=>{ return text+" #"+id.ToString(); }).ToReadOnlyReactiveProperty<string>(); rx_id_text.Subscribe((text)=>{ if (id_text != null) id_text.text = text; if (id_text_3d != null) id_text_3d.text = text; }); } if (count != null || count_3d != null){ rx_count_text = rx_score .SelectMany(s=>s.rx_count) .Select(value=>value.ToString()) .ToReadOnlyReactiveProperty<string>(); rx_count_text.Subscribe((text)=>{ if (count != null) count.text = text; if (count_3d != null) count_3d.text = text; }); } if (weight != null || weight_3d != null){ rx_weight_text = rx_score .SelectMany(s=>s.rx_weight) .Select(value=>value.ToString("0.00")) .ToReadOnlyReactiveProperty<string>(); rx_weight_text.Subscribe((text)=>{ if (weight != null) weight.text = text; if (weight_3d != null) weight_3d.text = text; }); } condition = rx_score.SelectMany(s=>{ return s.rx_weight.CombineLatest(s.rx_overflow, (w,overflow)=>{ return new UniRx.Tuple<float,bool>(w,overflow); }); }).CombineLatest (rx_win, (tuple, wc) => { float w = tuple.Item1; bool overflow = tuple.Item2; if (overflow){ return BasketCondition.Overflow; } if (wc.basket_weight.is_accept(w)){ return BasketCondition.Accepted; } else { if (wc.basket_weight.is_over(w)){ return BasketCondition.Overweight; } else { return BasketCondition.Underweight; } } }).ToReadOnlyReactiveProperty<BasketCondition>(); rx_with_win = rx_score.CombineLatest(rx_win, (s, w)=>{ return new UniRx.Tuple<BasketSingleScore, GameSettings.WinCondition>(s,w); }); rx_with_win.Subscribe((tuple)=>{ if (flat_score_text != null){ ScoreDetailedForm.format_score_text(flat_score_text, tuple.Item2.evaluate_basket_flat(tuple.Item1)); } if (range_score_text != null){ ScoreDetailedForm.format_score_text(range_score_text, tuple.Item2.evaluate_basket_range(tuple.Item1)); } if (total_score_text != null){ ScoreDetailedForm.format_score_text(total_score_text, tuple.Item2.evaluate_basket(tuple.Item1)); } }); rx_tooltip_text = condition.Select(c=>language_keys[c]).ToReadOnlyReactiveProperty<string>(); rx_tooltip_text.Subscribe((key)=>{ if (tooltip != null){ tooltip.key = key; } }); rx_sprite = condition.Select(c=>sprites[c]).ToReadOnlyReactiveProperty<Sprite>(); rx_sprite.Subscribe ((sprite) => { if (icon != null) icon.sprite = sprite; if (icon_3d != null) icon_3d.sprite = sprite; }); if (opacity != null){ opacity.opacity = off_opacity; } }
public static ReadOnlyReactiveProperty <IEnumerable <string> > ToNumberedLaps( this ReadOnlyReactiveProperty <IEnumerable <string> > self) { return(self.Select(laps => laps.Select((x, i) => $"{i + 1}. {x}")) .ToReadOnlyReactiveProperty()); }
public HeroRunner(int heroIndex) { SceneLoader instance = SceneLoader.Instance; UIIngameNotifications IngameNotifications = BindingManager.Instance.IngameNotifications; HeroIndex = heroIndex; BerryIndex.SetValueAndForceNotify(HeroIndex % 5); m_heroConfig = PersistentSingleton <Economies> .Instance.Heroes[HeroIndex]; m_heroState = HeroStateFactory.GetOrCreateHeroState(HeroIndex); Level = m_heroState.Level; LifetimeLevel = m_heroState.LifetimeLevel; Tier = m_heroState.Tier; Berries = m_heroState.Berries; UnusedBerries = m_heroState.UnusedBerries; (from lvl in Level where lvl > LifetimeLevel.Value select lvl).Subscribe(delegate(int lvl) { LifetimeLevel.Value = lvl; }).AddTo(instance); Rank = (from tier in Tier select(int) Singleton <EconomyHelpers> .Instance.GetRank(tier)).TakeUntilDestroy(instance).ToReactiveProperty(); LocalizedName = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("Companion.Name." + HeroIndex)); LocalizedNameDesc = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("Companion.Name.Desc." + HeroIndex)); MiniMilestoneTitle = new ReactiveProperty <string>(LocalizedName + " " + PersistentSingleton <LocalizationService> .Instance.Text("Attribute.Milestone") + "!"); ChunkIndex = new ReactiveProperty <int>(m_heroConfig.UnlockAtChunk); FoundOnce = (from level in LifetimeLevel select level >= 1).TakeUntilDestroy(instance).ToReactiveProperty(); Found = (from level in Level select level >= 1).TakeUntilDestroy(instance).ToReactiveProperty(); IsNextLevelMilestone = (from lvl in Level select Singleton <EconomyHelpers> .Instance.IsMilestone(heroIndex, lvl + 1)).TakeUntilDestroy(instance).ToReactiveProperty(); UnlockedPerkCount = (from heroLevel in Level select Singleton <EconomyHelpers> .Instance.GetUnlockedPerkCount(heroLevel)).TakeUntilDestroy(instance).ToReactiveProperty(); PerkUnlockTriggered = (from pair in UnlockedPerkCount.Pairwise() where pair.Previous != pair.Current where pair.Current > 0 select new PerkUnlockedInfo(HeroIndex, pair.Current - 1)).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty(); if (heroIndex > 0) { (from _ in PerkUnlockTriggered where LifetimeLevel.Value > Level.Value select _).Subscribe(delegate(PerkUnlockedInfo perk) { IngameNotifications.InstantiatePerkNotification(perk); }).AddTo(instance); } MiniMilestoneTriggered = (from lvl in Level.Pairwise() select Singleton <EconomyHelpers> .Instance.GetMiniMilestoneOrNull(HeroIndex, lvl.Previous, lvl.Current) into cfg where cfg != null select cfg).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty(); MiniMilestoneText = MiniMilestoneTriggered.Select(delegate(BonusMultConfig cfg) { if (IngameNotifications.CurrentHeroIndex == HeroIndex && IngameNotifications.CurrentNotification != null && IngameNotifications.CurrentNotification.activeSelf) { m_currentMiniMilestoneMultiplier *= cfg.Amount; return(GetMilestoneString(cfg.BonusType, m_currentMiniMilestoneMultiplier)); } m_currentMiniMilestoneMultiplier = cfg.Amount; return(GetMilestoneString(cfg.BonusType, m_currentMiniMilestoneMultiplier)); }).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty(); MiniMilestoneText.Subscribe(delegate { IngameNotifications.InstantiateMiniMilestoneNotification(this); }).AddTo(instance); HeroTierUpgradeTriggered = (from pair in Tier.Pairwise() where pair.Previous != pair.Current select HeroIndex).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty(); MilestoneProgress = (from level in Level select Singleton <EconomyHelpers> .Instance.GetMilestoneProgress(level)).TakeUntilDestroy(instance).ToReactiveProperty(); BerryProgress = (from tier_berry in Tier.CombineLatest(Berries, (int tier, int berries) => new { tier, berries }) select Singleton <EconomyHelpers> .Instance.GetBerryProgress(tier_berry.tier, tier_berry.berries)).TakeUntilDestroy(instance).ToReactiveProperty(); BerryRequirement = (from tier_berry in Tier.CombineLatest(Berries, (int tier, int berries) => new { tier, berries }) select Singleton <EconomyHelpers> .Instance.GetBerryRequirementText(tier_berry.tier, tier_berry.berries)).TakeUntilDestroy(instance).ToReactiveProperty(); TierUpAvailable = (from berry_tier in Berries.CombineLatest(UnusedBerries, (int berries, int unused) => berries + unused).CombineLatest(Tier, (int berries, int tier) => new { berries, tier }) select berry_tier.berries >= Singleton <EconomyHelpers> .Instance.GetTierBerryDeltaReq(berry_tier.tier)).TakeUntilDestroy(instance).ToReactiveProperty(); NextMilestoneText = (from lvl in Level where lvl >= 1 select Singleton <EconomyHelpers> .Instance.GetNextMilestoneText(HeroIndex, lvl)).TakeUntilDestroy(instance).ToReactiveProperty(); }