void Start() { IsDebug.DistinctUntilChanged().Subscribe(d => { statusText.SetActive(d); }); }
void SetStream() { isDeferredShader = new ReactiveProperty <bool>(false); isDeferredShader .DistinctUntilChanged() .Subscribe(_ => { if (isDeferredShader.Value) { defaultMat.shader = deferredShader; } else { defaultMat.shader = forwardShader; } }); var changeSamplingStream = this.UpdateAsObservable(); changeSamplingStream .Subscribe(_ => { samplingInterval += 0.01f * Time.deltaTime; if (samplingInterval > 1f) { samplingInterval -= 1f; } defaultMat.SetFloat(samplingIntervalID, samplingInterval); }); }
protected override bool Create() { if (!base.Create()) { return(false); } _squareBitMask = LayerMask.GetMask("BoardSquare"); _hoveredSquare.DistinctUntilChanged().Subscribe(sq => _hoverSquare.Value = sq); HoverSquare.Subscribe(sq => { OverlayView.Clear(); if (sq == null) { return; } var p = Agent.At(sq.Coord); if (p == null) { return; } ShowSquares(sq.Coord); }); HoverPiece.Subscribe(p => { if (p != null) { Info($"Dragging {p} @{HoverSquare.Value}"); } }); return(true); }
void Start() { instance = this; this.UpdateAsObservable().Where(_ => timerCount > 0).Subscribe(_ => { timerCount -= Time.deltaTime; TimerText.text = "Time:" + ((int)timerCount / 60).ToString() + ":" + (timerCount % 60).ToString(); if (timerCount < 0) { ShowResult(); Destroy(gameObject, 5f); } }, () => { ObjectPools.Instance.ResetPools(); FlyCharacterManager.Instance.ResetCharacter(); SceneManager.LoadScene("StartScene"); } ); attackCount.DistinctUntilChanged().Subscribe(x => AttackCountText.text = "Attack" + x.ToString()); attackedCount.DistinctUntilChanged().Subscribe(x => AttackedCountText.text = "Attacked" + x.ToString()); }
void Start() { ArrowType.DistinctUntilChanged().Subscribe(x => { _arrowGameObject.transform.rotation = Quaternion.Euler(0f, x == Type.Left ? 0f : 180f, 0f); }); }
/// <summary> /// 更新前処理 /// </summary> void Start() { StartCoroutine(WaitStartAnimation()); IsDead .DistinctUntilChanged() .Where(x => x == true) .Where(_ => m_invincible != true) .Subscribe(_ => { Debug.Log("死ゾ"); GetComponent <BreakBlock>().Break(); }); }
void Awake() { model = NotesEditorModel.Instance; rectTransform = GetComponent <RectTransform>(); rectTransform.localPosition = model.NoteToScreenPosition(notePosition); var image = GetComponent <Image>(); noteType.DistinctUntilChanged() .Select(type => type == NoteTypes.Long) .Subscribe(isLongNote => image.color = isLongNote ? Color.cyan : new Color(175 / 255f, 1, 78 / 255f)); this.UpdateAsObservable() .Select(_ => model.NoteToScreenPosition(notePosition)) .DistinctUntilChanged() .Subscribe(pos => rectTransform.localPosition = pos); var mouseDownObservable = onMouseDownObservable .Where(_ => model.ClosestNotePosition.Value.Equals(notePosition)); var editObservable = mouseDownObservable .Where(editType => editType == NoteTypes.Normal) .Where(editType => noteType.Value == editType) .Merge(mouseDownObservable .Where(editType => editType == NoteTypes.Long)); editObservable.Where(editType => editType == NoteTypes.Normal) .Subscribe(_ => model.NormalNoteObservable.OnNext(notePosition)); editObservable.Where(editType => editType == NoteTypes.Long) .Subscribe(_ => model.LongNoteObservable.OnNext(notePosition)); var longNoteLateUpdateObservable = this.LateUpdateAsObservable() .Where(_ => noteType.Value == NoteTypes.Long); longNoteLateUpdateObservable .Where(_ => next != null) .Select(_ => model.NoteToScreenPosition(next.notePosition)) .Merge(longNoteLateUpdateObservable .Where(_ => next == null) .Where(_ => model.EditType.Value == NoteTypes.Long) .Where(_ => model.LongNoteTailPosition.Value.Equals(notePosition)) .Select(_ => model.ScreenToCanvasPosition(Input.mousePosition))) .Select(nextPosition => new Line[] { new Line(model.NoteToScreenPosition(notePosition), nextPosition, 0 < nextPosition.x - model.NoteToScreenPosition(notePosition).x ? Color.cyan : Color.red) }) .Subscribe(lines => GLLineRenderer.RenderLines(notePosition.ToString(), lines)); }
public MemoryBrowser(object root) { Kernel.Instance.Inject(this); // TODO prevent simple-values here rxBreadcrumbs.Add(root); Current = root; // this will trigger the UpdateCurrentSnapshot currentProperty.DistinctUntilChanged().Subscribe(_ => { rxCurrentSnapShot.Clear(); UpdateCurrentSnapshot(); }).AddTo(compDisp); }
void Start() { instance = this; this.UpdateAsObservable().Subscribe(_ => { timerCount -= Time.deltaTime; TimerText.text = "Time:" + ((int)timerCount / 60).ToString() + ":" + (timerCount % 60).ToString(); //if (timerCount < 0) SceneManager.LoadScene("神霊廟"); }); attackCount.DistinctUntilChanged().Subscribe(x => AttackCountText.text = "Attack" + x.ToString()); attackedCount.DistinctUntilChanged().Subscribe(x => AttackedCountText.text = "Attacked" + x.ToString()); }
void Start() { ResetQuestion(); HasQuestion .DistinctUntilChanged() .Where(_ => canQuestion) .Where(has => !has) .Subscribe(_ => { Debug.Log("HasQuestion call SetQuestion"); SetQuestion(); }) .AddTo(this); }
void SetStream() { isWhaleWatching = new ReactiveProperty <bool>(false); isWhaleWatching .DistinctUntilChanged() .Subscribe(_ => { if (isWhaleWatching.Value) { SetScanMode(scanMode); } else { SetScanMode(0); SetRendererEnabled(true); } }); }
protected override bool Create() { if (!base.Create()) { return(false); } if (Image != null) { _backgroundColor = new Ref <Color>(() => Image.color, c => Image.color = c); } else { _backgroundColor = new Ref <Color>(() => Color.cyan, c => { }); } _squareOver.DistinctUntilChanged().Subscribe(s => _squareOverFiltered.Value = s); return(true); }
public Machine(object initialState = null, bool disposeOnCompleted = false) { _initialState = initialState; _disposeOnCompleted = disposeOnCompleted; _state = new ReactiveProperty <object>(initialState); State = _state.ToReadOnlyReactiveProperty(); Transitions = _state .DistinctUntilChanged() .PairWithPrevious() .Select(x => new Transition(x.Item1, x.Item2)); this.Entering <IMachine>() .Subscribe(x => x.Start()) .AddTo(Disposables); this.Exiting <IMachine>() .Subscribe(x => x.Complete()) .AddTo(Disposables); Transitions .Subscribe(x => Log.Debug($"{Name} - {x.Source ?? "null"} -> {x.Target ?? "null"}")) .AddTo(Disposables); }
public InputLayer(string name, IInputLayer parent = null) { Name = name; var isEnabledObservable = _refCount.Select(x => x == 0); // Also take parent's state into account, if any if (parent != null) { ((InputLayer)parent)._children.Add(this); isEnabledObservable = isEnabledObservable .CombineLatest(parent.IsEnabled, (x, y) => x && y); } _isEnabled = isEnabledObservable.ToReactiveProperty(); if (Log.IsDebugEnabled) { _isEnabled .DistinctUntilChanged() .Subscribe(x => Log.Debug($"{Name} IsEnabled: {x}")); } }
public IObservable <DungeonState> OnChangeActiveStateAsObservable() { return(activeStateProperty.DistinctUntilChanged()); }
void initUniRxPrograming() { RX_LastMoveFrom = new Vector2ReactiveProperty(CurrentPoint); RX_LastMoveTo = new Vector2ReactiveProperty(CurrentPoint); RX_currentPoint = new Vector2ReactiveProperty(CurrentPoint); RX_LastClickCell.Subscribe(_ => { RX_targetEntity.Value = null; }); //如何过滤过快的点击切换路径? //假若RX_LastClickCell的输入频率是 0.3s 内来了 10个数据(玩家0.3s内点击了10个可以移动的地方) //则以最后一个数据为准作为通知 RX_LastClickCell.Throttle(TimeSpan.FromSeconds(0.2f)).Subscribe(_ => { RX_PathChanged.Value = true; }); RX_currentPoint.Subscribe(point => { mapController.SetStartPoint(Vector2Int.CeilToInt(point)); }); RX_LastMoveTo.Subscribe((to) => { m_Transform.LookAt(HexCoords.GetHexVisualCoords(Vector2Int.CeilToInt(to))); RX_moveFromA2BPer.Value = 0; RX_moveSpeed.Value = 1; }); RX_LastMoveTo.Buffer(RX_LastMoveTo.Where(point => point == RX_currentPoint.Value).Throttle(TimeSpan.FromSeconds(C_TimeToReachOnePoint))).Subscribe(_ => { RX_moveSpeed.Value = 0; }); #region 控制移动 RX_moveFromA2BPer.Skip(1).Subscribe(per => { entityVisual.Run2(); Vector3 fromVisualPos = Coords.PointToVisualPosition(Vector2Int.CeilToInt(RX_LastMoveFrom.Value)); Vector3 toVisualPos = Coords.PointToVisualPosition(Vector2Int.CeilToInt(RX_LastMoveTo.Value)); Vector3 v = Vector3.Lerp(fromVisualPos, toVisualPos, RX_moveFromA2BPer.Value); m_Transform.position = v; //float near_start_or_near_dst = -0.5f + per; if (per >= 0.5f) { RX_currentPoint.Value = RX_LastMoveTo.Value; } else { RX_currentPoint.Value = RX_LastMoveFrom.Value; } }); var idle = RX_moveSpeed.Where(speed => speed == 0); var confused = idle.Where(_ => { return(false); }); idle.Subscribe(_ => { entityVisual.Idle2(); }); #endregion //0 0.5 0.9 1 1 1 0 0.6 1 -> 0 0.5 0.9 1 0 0.6 1 RX_reachFragment = RX_moveFromA2BPer.DistinctUntilChanged(); RX_reachFragment.Subscribe(_ => { //Debug.Log(_); }); RX_reachFragment.Where(per => per == 1).Subscribe(_ => { RXEnterCellPoint(Vector2Int.CeilToInt(RX_currentPoint.Value)); } ); RX_moveFromA2BPer.Buffer(RX_moveFromA2BPer.Where(per => per == 1).Throttle(TimeSpan.FromSeconds(0.3f))) .Where(buffer => GameCore.GetGameStatus() == GameStatus.Run && buffer.Count >= 2).Subscribe(_ => { if (GameEntityMgr.GetSelectedEntity() == this) { ShowEyeSight(); } }); RX_PathChanged.Where(changed => changed).Subscribe(_ => { //allowMove = false; RX_PathChanged.Value = false; Disposable_movementTimeLine?.Dispose(); IList <ICell> path = mapController.CalculatePath(); //Disposable_movementTimeLine = Observable.FromCoroutine(MoveM).Subscribe(unit => Disposable_movementTimeLine = Observable.FromCoroutine((tok) => MoveMS(path)).SelectMany(aftermove).Subscribe(); //RX_moveAlongPath(path, tellmeHowToMove(UseForClickCellMove)); //Disposable_movementTimeLine = Observable.EveryUpdate().CombineLatest(RX_reachFragment, (frame, per) => //{ // return per; //}).Where(per => per >= 1).Where(per => //{ // if (!controllRemote.PTiliMove(1)) // { // Disposable_movementTimeLine.Dispose(); // return false; // } // return true; //}).StartWith(1).Subscribe(h => //{ // Debug.Log("reach and show next fragment"); // if (path.Count > 1) // { // RX_LastMoveFrom.Value = path[0].Point; // RX_LastMoveTo.Value = path[1].Point; // path.RemoveAt(0); // } // else // { // Disposable_movementTimeLine.Dispose(); // } //}); //if (path.Count > 0) //{ // //转变为 (1-2)-(2-3)-(3-4)-(4-5)队列 // var rawPath = path.ToObservable<ICell>(); // var skipheader = rawPath.Skip(1); // var from_to_pathset = rawPath.Zip(skipheader, (raw, skip) => // { // return new FromAndTo(raw.Point, skip.Point); // }); // //要求路线按每隔 XXs 发出1个,其中第一段希望立即发出 这个时间没有基于gamecore状态 // var timeLine = Observable.EveryUpdate().CombineLatest(RX_reachFragment, (frame, per) => // { // return per; // }).Where(per => per == 1); // Disposable_movementTimeLine = timeLine.Subscribe(async (__) => // { // var s = await from_to_pathset.ToYieldInstruction(); // Debug.Log(__ + s.from.ToString() + " " + s.to); // RX_LastMoveFrom.Value = s.from; // RX_LastMoveTo.Value = s.to; // }); // Disposable_movementTimeLine = timeLine.StartWith(1).Zip(from_to_pathset, (time, from_to) => // { // return new { from_to = from_to, per = time }; // }).Where(zip => zip.per == 1).Do(zip => // { // Debug.Log("change next "); // var from_to = zip.from_to; // RX_LastMoveFrom.Value = from_to.from; // RX_LastMoveTo.Value = from_to.to; // }, // () => // { // }).Subscribe(); //} }); RX_alive.Value = BeAlive(); var onDeath = RX_alive.Where(alive => !alive); onDeath.Subscribe(_ => { Disposable_moveFromA2BPer.Dispose(); }, () => { }); //检测当前选中的玩家和第一个被点击的非玩家对象 var getFrameStream = Observable.EveryUpdate(); var selectEntityStream = getFrameStream.Select(_ => GameEntityMgr.GetSelectedEntity()); // 1 0 2 0 1 var onSelectEntityChangedStream = selectEntityStream.DistinctUntilChanged().Where(newEntity => newEntity != null); // 1 0 2 0 1 => 1 2 1 var selectEntityChooseNPCStream = RX_targetEntity.DistinctUntilChanged(); //1 0 2 onSelectEntityChangedStream.Subscribe(_ => { //Debug.Log(_.entityID); }); selectEntityChooseNPCStream.Subscribe(_ => { }); //选中玩家后,第一次选中不同的npc var rx_selectPlayer_then_npc = onSelectEntityChangedStream.CombineLatest(selectEntityChooseNPCStream, (frameDuringSelected, choosenpc) => { //int error = -1; //if (choosenpc == null) // return error; //if (choosenpc.BeAlive()) //{ // return choosenpc.entityID; //} //return error; return(choosenpc); }) /*.DistinctUntilChanged()*/.Where(combineResults => /*combineResults != -1*/ combineResults != null); rx_selectPlayer_then_npc.Subscribe(npc => { Debug.Log(npc.entityID); //move to entity then attack IList <ICell> path2reachEntity = mapController.GetPathFinder().FindPathOnMap(mapController.GetMap().GetCell(CurrentPoint), mapController.GetMap().GetCell(npc.CurrentPoint), mapController.GetMap()); ForgetMovement(); Disposable_movementTimeLine = Observable.FromCoroutine((tok) => MoveMS(path2reachEntity)).SelectMany(aftermove).Subscribe(); //RX_moveAlongPath(path2reachEntity, tellmeHowToMove(UseForBattleMove)); //Observable.FromCoroutine(playerAction2Entity).Subscribe(); }); var rx_selectPlayer_then_mapcell = getFrameStream.CombineLatest(RX_LastClickCell.DistinctUntilChanged(), (frameDuringSelected, selectPoint) => { return(selectPoint); }).DistinctUntilChanged(); rx_selectPlayer_then_mapcell.Subscribe(Cell => { //Debug.Log(Cell); }); }
void SetupStream() { onModel = new ReactiveProperty <bool>(false); onShadow = new ReactiveProperty <bool>(false); onParticle = new ReactiveProperty <bool>(false); onModel .DistinctUntilChanged() .Subscribe(_ => { if (onModel.Value) { SetModel(0); SetParticle(0); whaleRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; movementM.onSetScale = false; } else { movementM.onSetScale = true; } }); onShadow .DistinctUntilChanged() .Subscribe(_ => { if (onShadow.Value) { HideModel(); SetParticle(0); whaleRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly; } else { } }); onParticle .DistinctUntilChanged() .Subscribe(_ => { if (onParticle.Value) { HideModel(); SetModel(0); whaleRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly; } else { } }); isWhaleWatching = new ReactiveProperty <bool>(false); isWhaleWatching .DistinctUntilChanged() .Subscribe(_ => { if (isWhaleWatching.Value) { courseM.WatchingZoneEnter(); fdm.HideText(); } else { courseM.WatchingZoneExit(); fdm.HideText(); } }); var setParticleColorStream = this.UpdateAsObservable(); setParticleColorStream .Where(_ => onParticle.Value) .Subscribe(_ => wpm.SetHSVColor(wsm.shadowHSV.h)); var setModelColorStream = this.UpdateAsObservable(); setModelColorStream .Where(_ => onModel.Value) .Subscribe(_ => wmm.SetModelColor(wsm.gridHSV.GetHSV())); var lightSetStream = this.UpdateAsObservable(); lightSetStream .Subscribe(_ => SetLightDirection()); var inputKeyStream = this.UpdateAsObservable(); inputKeyStream .Subscribe(_ => { bool onDrawManual = false; if (Input.GetKey(KeyCode.Alpha1)) { SetModel(1); } else if (Input.GetKey(KeyCode.Alpha2)) { SetModel(2); } else if (Input.GetKey(KeyCode.Alpha3)) { SetModel(3); } else if (Input.GetKey(KeyCode.Alpha4)) { SetModel(4); } else if (Input.GetKey(KeyCode.Alpha5)) { SetModel(5); } else if (Input.GetKey(KeyCode.Alpha6)) { SetModel(6); } else if (Input.GetKey(KeyCode.Alpha7)) { SetModel(7); } else if (Input.GetKey(KeyCode.Alpha8)) { SetModel(8); } else if (Input.GetKey(KeyCode.Alpha9)) { SetModel(9); } else if (Input.GetKey(KeyCode.Alpha0)) { SetModel(10); } else if (Input.GetKeyDown(KeyCode.Q)) { SetModelDraw(); } else if (Input.GetKeyDown(KeyCode.E)) { SetGrid(0); } else if (Input.GetKeyDown(KeyCode.R)) { SetGrid(1); } else if (Input.GetKeyDown(KeyCode.T)) { SetGrid(2); } else if (Input.GetKeyDown(KeyCode.Y)) { SetGrid(3); } else if (Input.GetKeyDown(KeyCode.U)) { SetGrid(4); } else if (Input.GetKeyDown(KeyCode.I)) { SetGrid(5); } else if (Input.GetKeyDown(KeyCode.O)) { SetGrid(6); } else if (Input.GetKeyDown(KeyCode.P)) { SetGrid(7); } else if (Input.GetKeyDown(KeyCode.F)) { SetParticle(1); } else if (Input.GetKeyDown(KeyCode.G)) { SetParticle(2); } else if (Input.GetKeyDown(KeyCode.H)) { SetParticle(3); } else if (Input.GetKeyDown(KeyCode.J)) { SetParticle(4); } else if (Input.GetKeyDown(KeyCode.K)) { wmm.SwicthBatchRenderer(); } else if (Input.GetKeyDown(KeyCode.L)) { } else if (Input.GetKey(KeyCode.Z)) { onDrawManual = true; } else if (Input.GetKeyDown(KeyCode.X)) { movementM.ChangeSpeedScale(); } else if (Input.GetKeyDown(KeyCode.C)) { wmm.SwitchCulling(); } else if (Input.GetKeyDown(KeyCode.V)) { courseM.ChangeScanMode(); } else if (Input.GetKeyDown(KeyCode.B)) { wsm.SetGridAllScreen(); } else if (Input.GetKey(KeyCode.N)) { wsm.ChangeScreenColor(); } else if (Input.GetKey(KeyCode.M)) { wsm.ChangeScreenSVC(); } else if (Input.GetKey(KeyCode.Comma)) { wsm.ChangeGridColor(); } else if (Input.GetKey(KeyCode.Period)) { wsm.ChangeGridSVC(); } else if (Input.GetKey(KeyCode.Slash)) { } else if (Input.GetKey(KeyCode.Backslash)) { } manualObj.SetActive(onDrawManual); }); }
public SettingsRunner() { Singleton <PropertyManager> .Instance.AddRootContext(this); SceneLoader instance = SceneLoader.Instance; BindingManager bind = BindingManager.Instance; InitializeVolumes(bind); Language.Value = PersistentSingleton <LocalizationService> .Instance.Text("UI.Language." + PlayerData.Instance.Language); PlayerID.Value = PlayerData.Instance.PlayerId; Version.Value = Application.version; Android.Value = true; PersistentSingleton <PlayFabService> .Instance.LoggedOnPlayerId.Subscribe(delegate { PFLogged.Value = true; }).AddTo(instance); PlayerData.Instance.PFId.CombineLatest(PFLogged, (string id, bool pf) => new { id, pf }).Subscribe(tuple => { if (tuple.id == string.Empty) { PlayerID.Value = "ID: " + PlayerData.Instance.PlayerId; } else if (tuple.pf) { PlayerID.Value = "ID: " + tuple.id; } else { PlayerID.Value = "ID: " + tuple.id + " (Disconnected)"; } }).AddTo(instance); MasterVolume.DistinctUntilChanged().Subscribe(delegate(float vol) { bind.MasterVolume.SetVolume(vol); PlayerPrefs.SetFloat("MasterVolume", vol); }).AddTo(instance); MusicVolume.DistinctUntilChanged().Subscribe(delegate(float vol) { bind.MusicVolume.SetVolume(vol); PlayerPrefs.SetFloat("MusicVolume", vol); }).AddTo(instance); SFXVolume.DistinctUntilChanged().Subscribe(delegate(float vol) { bind.SFXVolume.SetVolume(vol); PlayerPrefs.SetFloat("SFXVolume", vol); }).AddTo(instance); SFXUIVolume.DistinctUntilChanged().Subscribe(delegate(float vol) { bind.UIVolume.SetVolume(vol); PlayerPrefs.SetFloat("SFXUIVolume", vol); }).AddTo(instance); SFXAmbVolume.DistinctUntilChanged().Subscribe(delegate(float vol) { bind.AmbientVolume.SetVolume(vol); PlayerPrefs.SetFloat("SFXAmbVolume", vol); }).AddTo(instance); SFXEnvVolume.DistinctUntilChanged().Subscribe(delegate(float vol) { bind.EnvironmentVolume.SetVolume(vol); PlayerPrefs.SetFloat("SFXEnvVolume", vol); }).AddTo(instance); MasterVolumeString = (from vol in MasterVolume select Mathf.RoundToInt(vol * 100f).ToString() + "%").TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); MusicVolumeString = (from vol in MusicVolume select Mathf.RoundToInt(vol * 100f).ToString() + "%").TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); SFXVolumeString = (from vol in SFXVolume select Mathf.RoundToInt(vol * 100f).ToString() + "%").TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); SFXUIVolumeString = (from vol in SFXUIVolume select Mathf.RoundToInt(vol * 100f).ToString() + "%").TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); SFXAmbVolumeString = (from vol in SFXAmbVolume select Mathf.RoundToInt(vol * 100f).ToString() + "%").TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); SFXEnvVolumeString = (from vol in SFXEnvVolume select Mathf.RoundToInt(vol * 100f).ToString() + "%").TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); if (PersistentSingleton <GameAnalytics> .Instance != null) { PersistentSingleton <GameAnalytics> .Instance.MusicVolume = MusicVolume; PersistentSingleton <GameAnalytics> .Instance.SFXVolume = SFXVolume; } }