protected virtual void Awake() { _isOpen.Where(x => x).Subscribe(x => OnOpenAnyObserver.OnNext(this)).AddTo(this); _isOpen.Where(x => !x).Subscribe(x => OnCloseAnyObserver.OnNext(this)).AddTo(this); openCloseDisposable.AddTo(this); animations = GetComponents <DOTweenAnimation>(); SubscribeOnAnimationComplete(); }
private void Init() { SetNewShootTime(0.25f); m_CanShoot .Where(x => x) .Subscribe(_ => Shoot()); m_CanShoot .Where(x => !x) .Subscribe(_ => { //выглядит так, как будто будет забивать память новыми экземплярами Observable.Timer(m_ShootTimer).Subscribe(SetCanShoot); }); }
void Start() { characterController = GetComponent <CharacterController>(); // ジャンプ中でなければ移動 this.UpdateAsObservable() .Where(_ => !isJumping.Value) .Select(_ => new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))) .Where(x => x.magnitude > 0.1f) // ベクトルの長さを返す .Subscribe(x => Move(x.normalized)); // ジャンプ中でない場合ジャンプ this.UpdateAsObservable() .Where(_ => Input.GetKeyDown(KeyCode.Space) && !isJumping.Value && characterController.isGrounded) .Subscribe(_ => { Jump(); isJumping.Value = true; }); // 着地フラグが変化した時にジャンプ中フラグ戻す characterController .ObserveEveryValueChanged(x => x.isGrounded) .Where(x => x && isJumping.Value) .Subscribe(_ => isJumping.Value = false) .AddTo(gameObject); // ジャンプ中フラグがfalseになったら効果音を鳴らす isJumping.Where(x => !x) .Subscribe(_ => PlaySoundEffect()); }
public void Start() { player = GetComponent <Player>(); if (transform.parent == null) { Debug.LogError("parent is not found"); return; } playerCamera = transform.parent.GetComponentInChildren <Camera>(); shootAudio = GetComponents <AudioSource>() .Where(x => x.clip) .FirstOrDefault(x => Regex.IsMatch(x.clip.name, "shoo?t", RegexOptions.IgnoreCase)); Assert.IsNotNull(shootAudio); reloadAudio = GetComponents <AudioSource>() .Where(x => x.clip) .FirstOrDefault(x => Regex.IsMatch(x.clip.name, "reload", RegexOptions.IgnoreCase)); Assert.IsNotNull(reloadAudio); isReloading.Where(x => x == true).Subscribe(_ => { // Reload SE Play reloadAudio.Play(); }).AddTo(gameObject); }
// Use this for initialization void Start() { cardLayoutGroup = cardLayout.GetComponent <HorizontalLayoutGroup>(); cardLayoutOriginPos = cardLayout.transform.position; cardLayoutGroupOriginSpacing = cardLayoutGroup.spacing; isOpneCard.Where(x => x == true).Subscribe(x => OpenCard()); }
private void OnEnable() { ConnectSocket(); _isConnectedObserver = _isConnected.Subscribe(status => { if (status) { return; } _reconnectObserver = Observable.Interval(TimeSpan.FromSeconds(5)) .TakeUntil(_isConnected.Where(connected => connected)) .Subscribe(observer => { _activeClients = new List <UnityUser>(); ConnectSocket(); Debug.Log("Trying to reconnect " + _socket.State); }); }); _serverJsonObserver = _serverJson.Subscribe(value => { _activeClients = value?.FromJson <List <UnityUser> >(); var currentUser = _activeClients.Find(u => u.Id == SystemInfo.deviceUniqueIdentifier); _activeObject = string.IsNullOrEmpty(currentUser.LockedAsset) ? null : AssetDatabase.LoadMainAssetAtPath(currentUser.LockedAsset); Repaint(); }); }
public void Start() { strongAudio = GetComponent <AudioSource>(); Assert.IsNotNull(strongAudio); var gameBGM = GameObject.Find("GameBGM").GetComponent <AudioSource>(); Assert.IsNotNull(gameBGM); isEnabled.Where(x => x == true).Subscribe(_ => { float audioSize = strongAudio.clip.length; StartCoroutine(DurationBGMMute(gameBGM, audioSize)); strongAudio.Play(); }); remainedTimeSecond .Where(time => remainedTimeSecond.Value <= 0) .Subscribe(_ => { isEnabled.Value = false; if (timerDisposable != null) { timerDisposable.Dispose(); } }) .AddTo(gameObject); }
void Start() { gameOverText.text = string.Empty; restartText.text = string.Empty; // 绑定分数、游戏结束、重新开始的text score.SubscribeToText(scoreText, s => $"得分: {score}"); gameOver.Where(x => x).SubscribeToText(gameOverText, _ => "游戏结束"); restart.Where(x => x).SubscribeToText(restartText, _ => "按R键重新开始"); // 生成小行星 var spawnStream = Observable .Interval(TimeSpan.FromSeconds(spawnWait)) .Where(_ => !gameOver.Value) .Do(_ => { spawnPosition.x = Random.Range(-spawnValues.x, spawnValues.x); spawnPosition.z = spawnValues.z; spawnRotation = Quaternion.identity; Instantiate(hazards[Random.Range(0, hazards.Length)], spawnPosition, spawnRotation); }) .Take(hazardCount) .Delay(TimeSpan.FromSeconds(waveWait)) .RepeatSafe(); spawnStream.Subscribe().AddTo(this); // 重新开始游戏 var restartStream = Observable.EveryUpdate() .Where(_ => Input.GetKeyDown(KeyCode.R)) .Where(_ => restart.Value); restartStream.Subscribe(_ => SceneManager.LoadScene(0)); }
public void Execute(ILifeTime lifeTime) { //reset local value lifeTime.AddCleanUpAction(CleanUpNode); var input = portPair.InputPort; var output = portPair.OutputPort; var valueObservable = input.Receive <TData>(); var source = BindToDataSource(valueObservable); if (distinctInput) { source.Subscribe(x => valueData.Value = x). AddTo(lifeTime); } else { source.Subscribe(valueData.SetValueAndForceNotify). AddTo(lifeTime); } isFinalyze. Where(x => x). Do(x => output.Publish(valueData.Value)). Subscribe(). AddTo(lifeTime); }
void Start() { var serverIp = IPAddress.Parse(UnityEngine.Network.player.ipAddress).ToString(); serverText.text = serverIp; serverStartButton.onClick.AddListener(() => { serverStartButton.onClick.RemoveAllListeners(); clientStartButton.onClick.RemoveAllListeners(); GameStart(true); }); clientStartButton.onClick.AddListener(() => { serverStartButton.onClick.RemoveAllListeners(); clientStartButton.onClick.RemoveAllListeners(); GameStart(false); }); Network.Client.Instance.onAcceptConnect += AcceptSession; Network.Client.Instance.onCloseSession += CloseSession; startGame.Where(x => x).ObserveOnMainThread().Subscribe(_ => { UnityEngine.SceneManagement.SceneManager.LoadScene("GamePlay"); }).AddTo(gameObject); }
private void Start() { this.transform.localScale = Vector3.zero; m_timeline = GetComponent <Timeline>(); m_isStart.Where(_ => _).Subscribe(_ => m_coroutine = StartCoroutine(EnemyBehaviour())).AddTo(gameObject); m_isEnd.Where(_ => _).Subscribe(_ => StopCoroutine(m_coroutine)).AddTo(gameObject); }
protected override void Awake() { unitTable.Add(UNITASIGN.OWN, new List <Unit> ()); unitTable.Add(UNITASIGN.OPPONENT, new List <Unit> ()); gameTimeLabel.text = string.Format("Time : {0}", gameTotalTime); UpdateCost(totalCost); System.IDisposable disposable = null; int count = 4; disposable = Observable.Interval(System.TimeSpan.FromSeconds(1)).Subscribe(_ => { count--; countDown.text = count.ToString(); if (count == 0) { countDown.text = "Start!!"; } if (count == -1) { disposable.Dispose(); countDown.text = ""; gameStart = true; SetSpawnObservable(); SetObservable(); } }).AddTo(gameObject); var settings = new List <string> () { "red_large_carrier", "red_small_carrier", "red_unit_1", "red_unit_2", }; for (int i = 0; i < 4; i++) { var setting = UnitSettingLoader.GetSetting(settings [i]); buttonParent.Find("UnitButton_" + (i + 1).ToString()).GetComponent <UnitSpawn> ().SetParameter(setting.id); } if (Network.Client.Instance == null) { return; } Network.Client.Instance.onCloseSession += CloseSession; Network.Client.Instance.Reciever.OnRecvSpawnUnit += OnRecvSpawnUnit; closeSession.Where(x => x).ObserveOnMainThread().Subscribe(_ => { UnityEngine.SceneManagement.SceneManager.LoadScene("Title"); }); }
private void Awake() { GameSceneManager gameSceneManager = FindObjectOfType <GameSceneManager>(); BoolReactiveProperty isDrift = new BoolReactiveProperty(false); Vector3 prePos = Vector3.zero; Vector3 direction = Vector3.zero; if (mSmokes.Length <= 0) { return; } this.UpdateAsObservable() .Where(_ => gameSceneManager.SceneState == SceneState.REPLAY) .Subscribe(_ => { direction = transform.position - prePos; if (direction.magnitude < IGNORE_LENGTH) { isDrift.Value = false; return; } prePos = transform.position; float slipAngle = Vector3.Angle(direction, transform.forward); isDrift.Value = slipAngle > SMOKE_ANGLE && slipAngle < IGNORE_ANGLE; }) .AddTo(gameObject); this.OnEnableAsObservable().Subscribe(_ => StopParticles(mSmokes)); isDrift .Where(_ => gameSceneManager.SceneState == SceneState.REPLAY) .Where(_ => _) .Subscribe(_ => { PlayParticles(mSmokes); }) .AddTo(gameObject); isDrift .Where(_ => gameSceneManager.SceneState == SceneState.REPLAY) .Where(_ => !_) .Subscribe(_ => { StopParticles(mSmokes); }) .AddTo(gameObject); }
protected override void InitializeComponent(IUIContext context, bool isPlaying) { base.InitializeComponent(context, isPlaying); if (!isPlaying) { return; } _movable .Where(_ => Header != null) .Subscribe(v => Header.Interactable = v, Debug.LogError) .AddTo(this); _resizer = new ResizeHelper(this); _resizer.Initialize(); _resizer.Activate(); _resizable .Where(_ => _resizer != null) .Subscribe(v => _resizer.Active = v, Debug.LogError) .AddTo(this); _backdrop .Where(_ => BackdropImage != null) .Subscribe(v => v.Update(BackdropImage, DefaultBackdrop), Debug.LogError) .AddTo(this); var parentStatusChanged = Transform .OnTransformParentChangedAsObservable() .Select(_ => Transform.parent != null); var hasValidParent = new ReactiveProperty <bool>(Transform.parent != null).Merge(parentStatusChanged); var visible = new ReactiveProperty <bool>(enabled).Merge(OnVisibilityChange); var shouldBackdropExists = Observable .CombineLatest(_modal, visible, hasValidParent) .Select(i => i.All(v => v)) .DistinctUntilChanged(); shouldBackdropExists .Where(v => v && BackdropImage == null) .Subscribe(_ => ShowBackdrop(), Debug.LogError) .AddTo(this); shouldBackdropExists .Where(v => !v && BackdropImage != null) .Subscribe(_ => HideBackdrop(), Debug.LogError) .AddTo(this); }
public void Start() { InitScopingControl(); warpAudio = GetComponents <AudioSource>() .Where(x => x.clip) .FirstOrDefault(x => Regex.IsMatch(x.clip.name, "warp", RegexOptions.IgnoreCase)); Assert.IsNotNull(warpAudio); IsWarping.Where(x => x == true).Subscribe(_ => { warpAudio.Play(); }).AddTo(gameObject); }
// Use this for initialization void Start() { this.GetComponentInParent <Controllable>().LatestTarget().Subscribe(target => { // Stop any fire subs if (fireSubscription != null) { fireSubscription.Dispose(); fireSubscription = null; } if (target != null) { fireSubscription = EveryUpdate().Where(_ => CanFireAtTarget(target)).Subscribe(_ => Fire()); } }); // Not sure how I could later modify the reload time, save the sub and redo when damaged? weaponLoaded.Where(loaded => loaded == false).Delay(TimeSpan.FromSeconds(ReloadTime)).Subscribe(_ => weaponLoaded.Value = true); }
public override void Initialize(PersonProvider provider) { base.Initialize(provider); this.provider = provider; killSelfTime = provider.KillTime; InMitsu.Subscribe(x => { if (!x) { currentVelocityBonus = velocityDefaultE; direction.Value = new Vector2(Random.Range(-1, 1), Random.Range(-1, 1)); } }).AddTo(gameObject); direction .Select(x => x * currentVelocityBonus) .Subscribe(dir => rb2D.velocity = dir).AddTo(gameObject); DiedAsync.First().Subscribe(async _ => { anim.Play("Die"); provider.people.Remove(this); await UniTask.Delay(System.TimeSpan.FromMilliseconds(1100)); Destroy(gameObject); }, () => { }).AddTo(gameObject); transform.ObserveEveryValueChanged(t => t.position) .Where(p => p.x > 32 || p.x < -32 || p.y > 24 || p.y < -24) .Subscribe(_ => { // エリアから出たら、原点(0. 0)あたりにもどる var pos = new Vector2(Random.Range(-20, 20), Random.Range(-10, 10)); direction.Value = (pos - (Vector2)transform.position).normalized; }).AddTo(gameObject); isCatastorophy.Where(x => x).Subscribe(_ => transform.DOLocalMove(Vector3.zero, 10)).AddTo(gameObject); }
private void OnEnable() { // UniRx // reset life and dead flag currentLife = new FloatReactiveProperty(baseHealth); isDead.Value = false; // Move if not dead //this.UpdateAsObservable() // .Where(_ => !isDead.Value) // .Subscribe(x => Move()); // dead condition this.UpdateAsObservable() .Where(_ => currentLife.Value <= 0f || GameManager.GameOver) .Subscribe(_ => { isDead.Value = true; }); // if dead, start death coroutine isDead .Where(x => x) .Subscribe(x => StartCoroutine(OnDeath())); startTilePos = Astar.grid[MapData.startTile.x, MapData.startTile.y].worldPosition; endTilePos = Astar.grid[MapData.endTile.x, MapData.endTile.y].worldPosition; currentSpeed = baseSpeed; transform.position = new Vector3(startTilePos.x, SpawnOffsetY, startTilePos.z); animator.SetBool("Killed", false); animator.SetBool("isWalking", true); GoToGoal(); }
private IDisposable OnTimeWindowOpen() { P1TimeWindow.Where(open => open).Subscribe(b => { var client = ClientsList.First(x => x.Lane == 0); SetScores(client, client.Lane).AddTo(this); }).AddTo(this); P2TimeWindow.Where(open => open).Subscribe(b => { var client = ClientsList.First(x => x.Lane == 1); SetScores(client, client.Lane).AddTo(this); }).AddTo(this); P3TimeWindow.Where(open => open).Subscribe(b => { var client = ClientsList.First(x => x.Lane == 2); SetScores(client, client.Lane).AddTo(this); }).AddTo(this); return (P4TimeWindow.Where(open => open).Subscribe(b => { var client = ClientsList.First(x => x.Lane == 3); SetScores(client, client.Lane).AddTo(this); }).AddTo(this)); }
void IInitializable.Initialize() { // initialize Observable.EveryUpdate() .Where(_ => CriWareInitializer.IsInitialized()) .First() .SelectMany(_ => ADX2Utility.AddCueSheet(_settings.BuiltInCueSheet) .First()) .Subscribe(cueSheet => { if (cueSheet != null) { // add cue list var cueNameList = ADX2Utility.GetCueNameList(cueSheet.name); foreach (var cueName in cueNameList) { _cueSheetDictionary.Add(cueName, cueSheet.name); } // create sound source var source = new GameObject("BGM").AddComponent <CriAtomSource>(); source.use3dPositioning = false; source.loop = true; source.player.AttachFader(); _source.Value = source; } _initialized.Value = true; }) .AddTo(_disposable); Observable.Merge( _intent.OnPlayAsObservable().Select(x => x.ToString()), _intent.OnPlayForNameAsObservable()) .Where(_ => _initialized.Value) .Subscribe(x => { string cueSheet; if (!_cueSheetDictionary.TryGetValue(x, out cueSheet)) { Debug.unityLogger.LogError(GetType().Name, $"{x} is not found."); return; } _source.Value.cueSheet = cueSheet; _source.Value.Pause(false); _source.Value.Play(x); }) .AddTo(_disposable); _intent.OnPauseAsObservable() .Where(_ => _source.Value != null) .Subscribe(x => _source.Value.Pause(x)) .AddTo(_disposable); _intent.OnStopAsObservable() .Where(_ => _source.Value != null) .Subscribe(_ => _source.Value.Stop()) .AddTo(_disposable); // volume _volumeIntent.OnMasterVolumeAsObservable() .Subscribe(x => _masterVolume.Value = x) .AddTo(_disposable); _volumeIntent.OnVoiceVolumeAsObservable() .Subscribe(x => _volume.Value = x) .AddTo(_disposable); var initialize = _initialized .Where(x => x) .First() .Publish() .RefCount(); initialize .Where(_ => _source.Value != null) .SelectMany(_ => _masterVolume) .Subscribe(x => _source.Value.volume = x) .AddTo(_disposable); initialize .SelectMany(_ => _volume) .Subscribe(x => CriAtom.SetCategoryVolume(_settings.CategoryVolumeName, x)) .AddTo(_disposable); }
IObservable <int> IDialogModel.OnOpenAsObservable() { return(_isOpen .Where(x => x) .Select(_ => _stack.Count)); }
IObservable <Unit> ILoadingModel.OnShowAsObservable() { return(_isShow .Where(x => x) .AsUnitObservable()); }
IObservable <Unit> IAppMaintenanceController.OnMaintenanceAsObservable() { return(isMaintenance.Where(x => x).AsUnitObservable()); }
IObservable <Unit> IToastModel.OnOpenAsObservable() { return(_isOpen .Where(x => x) .AsUnitObservable()); }
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); }); }
public GameObject bullet;//Controlに変更して汎用化? void Start() { GameController game; bool enable_input = true; setup(); animator = GetComponent <Animator>(); rb2d = GetComponent <Rigidbody2D>(); move_Control = GetComponent <Alice_Move_Control>(); game = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>(); //フリーズ条件:talk game.talkEvent.Subscribe(f => { freezed.Value = f; }).AddTo(gameObject); //フリーズ条件:GameClear game.clearEvent.Subscribe(f => { if (f) { freezed.Value = true; animator.speed = 0; } }).AddTo(gameObject); //敵に衝突してダメージ this.OnCollisionStay2DAsObservable() .Where(collision => collision.collider.gameObject.tag == "Enemy") .Subscribe(collision => this.UpdateAsObservable().First().Where(_ => !freezed.Value && !is_inbincible.Value).Subscribe(_ => { DamageTrigger.OnNext(Unit.Default); is_inbincible.Value = true; }) ); DamageTrigger.Subscribe(_ => { is_inbincible.Value = true; animator.SetTrigger("Damaged"); FreezableFixedUpdate.Skip(150).Take(1).Subscribe(__ => is_inbincible.Value = false).AddTo(this); game.life.Value--; }).AddTo(gameObject); //射撃 FreezableUpdate.Where(_ => enable_input).Where(_ => Input.GetButtonDown("Fire2")) .Subscribe(p => { var b = Instantiate(bullet, rb2d.transform.position + new Vector3(0, 0.5f), rb2d.transform.rotation); b.GetComponent <Bullet_Control>().velocity = new Vector3(move_Control.front_way * 10, 0); b.transform.parent = transform.parent; animator.SetTrigger("Shoot"); }); //時間停止 FreezableUpdate.Where(_ => enable_input).Where(_ => Input.GetButtonDown("Fire3")) .Subscribe(p => { game.try_timeStop(); }); //無敵処理 is_inbincible.Where(p => p).Subscribe(i => gameObject.layer = LayerMask.NameToLayer("Player_Invincible")); is_inbincible.Where(p => !p).Subscribe(i => gameObject.layer = LayerMask.NameToLayer("Player")); }
protected override void OnInitialize() { cc = GetComponent <PlayerCharcterController>(); var rb = GetComponent <Rigidbody>(); // ジャンプ動作 InputEventProvider.JumpButton .Where(_ => Core.CurrentGameState.Value == GameState.Battle) .Where(x => x && Core.IsAlive.Value && !IsOnAir.Value && !isFreezed) .ThrottleFirst(TimeSpan.FromSeconds(1)) .Subscribe(_ => { cc.Jump(CurrentPlayerParameter.Value.JumpPower); _isJumping.Value = true; }); // 着地処理 cc.IsGrounded .Where(x => x && !isFreezed) .Subscribe(x => { if (_isHipDroping.Value) { _hipDroppedSubject.OnNext(Unit.Default); } StartCoroutine(FreezeCoroutine()); _isJumping.Value = false; _isHipDroping.Value = false; }); // 移動処理 InputEventProvider.MoveDirection .Where(_ => Core.CurrentGameState.Value == GameState.Battle) .Subscribe(x => { var value = (IsOnAir.Value || !Core.IsAlive.Value) ? Vector3.zero : x.normalized * CurrentPlayerParameter.Value.MoveSpeed; cc.Move(value); }); // ヒップドロップ動作 InputEventProvider.AttackButton .Where(_ => Core.CurrentGameState.Value == GameState.Battle) .Where(x => x && Core.IsAlive.Value && !_isHovering.Value && IsOnAir.Value) .Subscribe(x => { StartCoroutine(HoverCoroutine()); _isJumping.Value = false; }); this.FixedUpdateAsObservable() .Where(x => Core.IsAlive.Value && _isHovering.Value) .Subscribe(x => cc.Stop()); // 走行中かどうかの通知 InputEventProvider.MoveDirection .Where(x => Core.IsAlive.Value) .Subscribe(x => _isRunning.Value = !IsOnAir.Value && x.magnitude >= 0.1f); // 上空かどうかの通知 cc.IsGrounded .Where(x => Core.IsAlive.Value) .Subscribe(x => _isOnAir.Value = !x); // 空中停止中かどうか _isHovering .Where(x => !x && Core.IsAlive.Value && IsOnAir.Value) .Subscribe(x => { cc.ApplyForce(Vector3.down * 300); _isHipDroping.Value = true; }); // やられたときの処理 Core.IsAlive.Where(x => x).Subscribe(x => { _isRunning.Value = false; _isOnAir.Value = false; _isJumping.Value = false; _isHovering.Value = false; _isHipDroping.Value = false; }); Core.IsAlive.Subscribe(x => { rb.useGravity = x; if (!x) { //死んだ rb.constraints = RigidbodyConstraints.None; } else { rb.constraints = RigidbodyConstraints.FreezeRotation; transform.rotation = Quaternion.LookRotation(Vector3.back); } }); // ダメージ時の処理 Core.OnDamaged.Subscribe(x => { var force = x.Direction * x.Value * CurrentPlayerParameter.Value.FuttobiRate; cc.ApplyForce(force); }); //着地したら止める OnHipDropped.Subscribe(_ => cc.Stop()); }
private void InitCooldowns() { botonPescadoCooldown.Where(_ => botonPescadoCooldown.Value == true).Subscribe( _ => { disposableBotonComida = Observable .Timer(TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(30)) .Take(10) .Subscribe(time => { rellenoPescado.fillAmount -= 0.1f; } , ex => { Debug.Log("OnError:" + ex.Message); disposableBotonComida.Dispose(); }, () => //completado { rellenoPescado.fillAmount = 1; if (disposableBotonComida != null) { disposableBotonComida.Dispose(); } }).AddTo(this.gameObject); }).AddTo(this.gameObject); botonAguaCooldown.Where(_ => botonAguaCooldown.Value == true).Subscribe( _ => { disposableBotonAgua = Observable .Timer(TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(30)) .Take(10) .Subscribe(time => { rellenoAgua.fillAmount -= 0.1f; } , ex => { Debug.Log("OnError:" + ex.Message); disposableBotonAgua.Dispose(); }, () => //completado { rellenoAgua.fillAmount = 1; if (disposableBotonAgua != null) { disposableBotonAgua.Dispose(); } }).AddTo(this.gameObject); }).AddTo(this.gameObject); botonLimpiarCooldown.Where(_ => botonLimpiarCooldown.Value == true).Subscribe( _ => { disposableBotonLimpiar = Observable .Timer(TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(30)) .Take(10) .Subscribe(time => { rellenoLimpiar.fillAmount -= 0.1f; } , ex => { Debug.Log("OnError:" + ex.Message); disposableBotonLimpiar.Dispose(); }, () => //completado { rellenoLimpiar.fillAmount = 1; if (disposableBotonLimpiar != null) { disposableBotonLimpiar.Dispose(); } }).AddTo(this.gameObject); }).AddTo(this.gameObject); botonJugar_1_Cooldown.Where(_ => botonJugar_1_Cooldown.Value == true).Subscribe( _ => { disposableBotonJugar_1 = Observable .Timer(TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(30)) .Take(10) .Subscribe(time => { rellenoJugar_1.fillAmount -= 0.1f; } , ex => { Debug.Log("OnError:" + ex.Message); disposableBotonJugar_1.Dispose(); }, () => //completado { rellenoJugar_1.fillAmount = 1; if (disposableBotonJugar_1 != null) { disposableBotonJugar_1.Dispose(); } }).AddTo(this.gameObject); }).AddTo(this.gameObject); botonJugar_2_Cooldown.Where(_ => botonJugar_2_Cooldown.Value == true).Subscribe( _ => { disposableBotonJugar_2 = Observable .Timer(TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(30)) .Take(10) .Subscribe(time => { rellenoJugar_2.fillAmount -= 0.1f; } , ex => { Debug.Log("OnError:" + ex.Message); disposableBotonJugar_2.Dispose(); }, () => //completado { rellenoJugar_2.fillAmount = 1; if (disposableBotonJugar_2 != null) { disposableBotonJugar_2.Dispose(); } }).AddTo(this.gameObject); }).AddTo(this.gameObject); }
public IObservable <Unit> OnInitializedAsObservable() { return(_initialized .Where(x => x) .AsUnitObservable()); }
IObservable <Unit> ISoundController.OnInitializedAsObservable() { return(_initialized .Where(x => x) .AsUnitObservable()); }