Ejemplo n.º 1
0
        private void Start()
        {
            _hpObservable.Value = maxHp * 0.7f;
            _hpObservable
            .TakeUntil(_hpObservable.Where(hp => hp <= 0))
            .Subscribe(hp =>
            {
                var colorSeed  = hp * 0.01f;
                renderer.color = new Color(1, 1, 1, colorSeed);
            },
                       () =>
            {
                DiedAsync.OnNext(Unit.Default);
                DiedAsync.OnCompleted();
                Debug.Log("Dead");
            }).AddTo(gameObject);
            _hpObservable.First(x => x < weakedHp).Subscribe(x => ResetAnim());

            this.UpdateAsObservable()
            .TakeUntil(_hpObservable.Where(hp => hp <= 0))
            .Where(_ => !isSayingHelloObservable.Value)
            .Select(_ => Input.GetMouseButtonDown(0)).Where(x => x)
            .Subscribe(_ =>
            {
                SayHello();
            }).AddTo(gameObject);
        }
Ejemplo n.º 2
0
        private void Start()
        {
            mediator = GetComponent <PlayerMediator>();

            specialPoint
            .Subscribe(x => mediator.OnSpecialChanged(x / maxSpecialPoint))
            .AddTo(this);

            // ポイントが最大になったらバフ
            specialPoint
            .Where(x => x >= maxSpecialPoint && !isBuffing)
            .Subscribe(_ => {
                isBuffing = true;
                mediator.StartBuff();
                CutInAsync().Forget();
            })
            .AddTo(this);

            // ポイントが0になったらバフ解除
            specialPoint
            .Where(x => x <= 0 && isBuffing)
            .Subscribe(_ => {
                isBuffing = false;
                mediator.StopBuff();
                bgmPlayer.Play(soundDatabase.MainBgm);
            })
            .AddTo(this);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        void Awake()
        {
            attribute = Attribute.None;
            emitter   = GetComponent <ShapeEmitter>();

            _hp.Where(x => x <= 0)
            .Subscribe(_ => Dead());
        }
Ejemplo n.º 5
0
    void InitAtOnce()
    {
        // 初期化は一度だけ行なう
        if (_initFlg)
        {
            return;
        }

        _maxWidth = _redHPBarTrans.sizeDelta.x;

        // 緑HPの変化の監視
        _greenHP
        .DistinctUntilChanged()
        .Subscribe(x => {
            // ダメージのポップ
            var dmg = _slider.value - x;
            // ダメージが1以上なら表示する
            if (dmg > 0 && _useDamagePop && DamagePoper.Instance != null)
            {
                DamagePoper.Instance.PopDamage(transform.parent, (int)dmg);
            }

            _slider.value = x;

            // 赤HPが緑HPより少なかったら緑HPに合わせる
            if (_redHP.Value < x)
            {
                _redHP.Value = x;
            }
        });

        // 赤HPの変化の監視
        _redHP
        .DistinctUntilChanged()
        .Subscribe(x => {
            // HPバーにサイズを適用する
            var size = new Vector2(_maxWidth * (x / _slider.maxValue), _redHPBarTrans.sizeDelta.y);
            // 最大サイズを越えないようにする
            if (size.x > _maxWidth)
            {
                size.x = _maxWidth;
            }
            _redHPBarTrans.sizeDelta = size;
        });

        // 赤HPがなくなったら非表示にする
        _redHP
        .Where(x => x <= 0)
        // ディレイをかける
        .Delay(TimeSpan.FromSeconds(_overLifeTime))
        .Subscribe(_ => {
            IsShow(false);
        });

        _initFlg = true;
    }
Ejemplo n.º 6
0
    private void Awake()
    {
        var levGen = new LevelGenerator(m_AsteroidPrefabs.Length);

        m_AllLevels = levGen.GetLevels(m_Saver, m_LevelPresets);

        NormalizedTimer
        .Where(x => x >= 1f)
        .Subscribe(LevelComplete);
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Start this instance.
 /// </summary>
 private void Start()
 {
     // bgm音量のsubscribeを作成.
     bgmVolume.Where(_ => bgmAudioSource != null)
     .Subscribe(v => {
         bgmAudioSource.volume = v;
     });
     // se音量のsubscribeを作成.
     seVolume.Where(_ => seAudioSource != null)
     .Subscribe(v => {
         seAudioSource.volume = v;
     });
 }
Ejemplo n.º 8
0
        protected override void OnInitialized()
        {
            _timeScale
            .Where(_ => !Paused)
            .Subscribe(scale => Time.timeScale = scale, Debug.LogError)
            .AddTo(this);
            _paused
            .Select(v => v ? 0 : TimeScale)
            .Subscribe(scale => Time.timeScale = scale, Debug.LogError)
            .AddTo(this);

            base.OnInitialized();
        }
Ejemplo n.º 9
0
    void Start()
    {
        rollCount.Value = (new System.Random()).Next(50, 150) / 10;
        rollCount.Where(x => x == 0)
        .Subscribe(x =>
        {
            State.Value     = RollState.Stoped;
            rollCount.Value = (new System.Random()).Next(50, 150) / 10;
        });
        Position.Value = transform.position;

        Debug.Log("Ball Start End");
    }
Ejemplo n.º 10
0
    internal void UpdateModel(AtomModel model)
    {
        _model            = model;
        _startTime        = Time.time;
        _originalMaxStock = _model.MaxStock;

        _atomMessage = new AtomMessage(_model.AtomicNumber, 1);

        AddReactor(timePercent);

        AddReactor
        (
            _model.rHarvestRate
            .Subscribe(rate =>
        {
            _model.Stock    = (int)(((float)_model.Stock / _model.MaxStock) * (_originalMaxStock * _model.HarvestRate));
            _model.MaxStock = (int)(_originalMaxStock * _model.HarvestRate);
            _harvestTime    = _model.AtomicWeight / _model.HarvestRate;
            _startTime      = -(timePercent.Value * _harvestTime) + Time.time;
        })
        );

        AddReactor
        (
            Observable.EveryUpdate()
            .Subscribe(_ => timePercent.Value = (Time.time - _startTime) / _harvestTime)
        );

        AddReactor
        (
            timePercent.Subscribe(percent => UISlider.value = UISlider.maxValue * percent)
        );

        AddReactor
        (
            _model.rStock.Where(_ => _model.Stock <= 0).Subscribe(_ => DestroyReactors())
        );

        AddReactor
        (
            timePercent
            .Where(value => value >= 1f)
            .Subscribe(_ =>
        {
            _startTime    = Time.time;
            _model.Stock -= 1;
            Messenger.Dispatch(AtomMessage.ATOM_HARVEST, _atomMessage);
        })
        );
    }
Ejemplo n.º 11
0
        private void Start()
        {
            height
            .Where(h => h >= 30.0f)
            .First()
            .Subscribe(h =>
            {
                // TakeOff
                PlayAnimation("TakeOff");
            }).AddTo(gameObject);

            BG.transform.ObserveEveryValueChanged(t => t.position)
            .Select(p => p.y)
            // 100分率にする
            .Select(y => Mathf.InverseLerp(0, maxHeight, -y) * 100)
            //.Do(h => Debug.Log(h))
            .Subscribe(y => height.Value = y)
            .AddTo(gameObject);

            speed
            .Skip(1)
            .TakeUntil(Goaled)
            .Subscribe(speed =>
            {
                speed           = (speed * force / 10) - force;
                bgRb2D.velocity = Vector2.down * speed;
            },
                       () =>
            {
                // ロケットの移動が終わったら背景のスクロールを止める
                bgRb2D.velocity = Vector2.zero;
            }).AddTo(gameObject);

            Goaled.Where(x => !x)
            .Subscribe(failed =>
            {
                rb2D.velocity = Vector2.down * 100.0f;
                Destroy(gameObject, 3.0f);
            }).AddTo(gameObject);
        }
Ejemplo n.º 12
0
        public void Start()
        {
            var gameTimerObj = GameObject.Find("GameTimer");

            if (gameTimerObj == null)
            {
                Debug.LogError("GameTimer GameObject is not found");
                return;
            }

            var gameTimer = gameTimerObj.GetComponent <GameTimer>();

            if (gameTimer == null)
            {
                Debug.LogError("GameTimer Component is not attached to GameTiemr GameObject");
                return;
            }

            remainedTimeSecond
            .Where(time => remainedTimeSecond.Value <= 0)
            .Subscribe(_ =>
            {
                isEnabled.Value = false;

                if (timerDisposable != null)
                {
                    timerDisposable.Dispose();
                }
            })
            .AddTo(gameObject);

            var index = 0;

            gameTimer.ElapsedTimeSecond
            .Subscribe(time =>
            {
                if (index < raiseTimeSecondList.Length && time >= raiseTimeSecondList[index])
                {
                    ++index;
                    Raise();
                }
            })
            .AddTo(gameObject);

            // SE
            feverAudio = GetComponent <AudioSource>();
            Assert.IsNotNull(feverAudio);

            var gameBGM = GameObject.Find("GameBGM").GetComponent <AudioSource>();

            Assert.IsNotNull(gameBGM);

            var feverStart = GameObject.Find("FeverStart").GetComponent <UI.FruitFever>();

            Assert.IsNotNull(feverStart);

            // Fever Start SE
            IsEnabled.Where(x => x == true).Subscribe(_ =>
            {
                float audioSize = feverAudio.clip.length;

                // show Fever Effect
                feverStart.ShowEffect();

                StartCoroutine(DurationBGMMute(gameBGM, audioSize));

                feverAudio.Play();
            }).AddTo(gameObject);
        }
Ejemplo n.º 13
0
 void Start()
 {
     _hp.Where(x => x <= 0)
     .Subscribe(_ => Dead());
 }
Ejemplo n.º 14
0
    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);
        });
    }