예제 #1
0
    public Character Initialize <T>(UInt32 id, string name_) where T : Actor, new()
    {
        if (!isInitialized)
        {
            isInitialized = true;
            name          = name_;
            tag           = "Character";
            Actor         = new T();
            ID            = id;
            Instances[ID] = this;
            Animator      = GetComponent <Animator>();
            Collider      = GetComponent <Collider>();
            Rigidbody     = gameObject.AddComponent <Rigidbody>();
            ActionManager = gameObject.AddComponent <ActionManager>();

            ActionManager.Action(ActionType.Normal);

            statusCanvas = Instantiate(ObjectManager.StatusCanvas).GetComponent <StatusCanvas>().Initialize(this);

            HP.Pairwise().Subscribe(hp =>
            {
                if (hp.Previous <= 0 && hp.Current > 0)
                {
                    IsAlive.Value = true;
                }

                if (hp.Previous > 0 && hp.Current <= 0)
                {
                    IsAlive.Value = false;
                }
            });

            IsAlive.Subscribe(isAlive =>
            {
                if (isAlive)
                {
                    Animator.SetTrigger("Normal");
                }
                else
                {
                    Animator.SetTrigger("Death");
                }

                Collider.enabled = CanAct.Value = isAlive;
            });
        }

        return(this);
    }
예제 #2
0
        void Awake()
        {
            _currentPlayerParameter = new ReactiveProperty <PlayerParameters>(DefaultPlayerParameter);

            cameraMultiTarget = GetComponent <CameraMultiTargetObjective>();

            _onInitializeAsyncSubject.Subscribe(_ =>
            {
                IsAlive.Where(x => x).Skip(1)
                .Subscribe(__ =>
                {
                    //生き返ったら座標を書き換える

                    var p = _respawnPoints[UnityEngine.Random.Range(0, _respawnPoints.Length)];
                    transform.position = p;
                });

                //画面外に出たら死ぬ
                this.ObserveEveryValueChanged(x => x.transform.position.y)
                .Where(x => x < -3 && this.IsAlive.Value)
                .Subscribe(__ => Kill(NonPlayerAttacker.Default))
                .AddTo(this);

                //ダメージを受けたら誰からのダメージか記憶する
                OnDamaged
                .Do(x => _lastDamagedAttacker = x.Attacker)
                .Throttle(TimeSpan.FromSeconds(3))
                .Subscribe(__ => _lastDamagedAttacker = null);

                IsAlive.Subscribe(x => cameraMultiTarget.EnableTracking = x);

                //死んだ
                OnDead
                .Subscribe(__ =>
                {
                    //死んだら4秒後に復活
                    Observable.Timer(TimeSpan.FromSeconds(2))
                    .Subscribe(___ => _isAlive.Value = true);
                });

                this.OnTriggerEnterAsObservable()
                .Where(__ => IsAlive.Value)
                .Subscribe(x =>
                {
                    var i = x.GetComponent <ItemBase>();
                    if (i != null)
                    {
                        _pickUpItemSubject.OnNext(i.ItemEffect);
                        i.PickedUp();
                    }
                });

                this.OnTriggerEnterAsObservable()
                .Where(__ => IsAlive.Value)
                .Subscribe(x =>
                {
                    var i = x.GetComponent <ItemBase>();
                    if (i != null)
                    {
                        _pickUpItemSubject.OnNext(i.ItemEffect);
                        i.PickedUp();
                    }
                });
            });
        }