示例#1
0
    /// <summary>
    /// Initiates a bluetooth scan
    /// </summary>
    public void BeginScanForDice()
    {
        if (_state != State.Idle)
        {
            Debug.LogError("Die Manager not ready to start scanning");
            return;
        }

        if (dieCreationFunc == null)
        {
            Debug.LogError("Die Manager - No die creation factory registered");
            return;
        }

        // Begin scanning
        _state = State.Scanning;

        // Notify of all the already known advertising dice
        foreach (var die in _dice.Values)
        {
            if (die.state == Die.State.Advertising)
            {
                onDieDiscovered?.Invoke(die.die);
            }
        }

        BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(new string[] { serviceGUID }, OnDeviceDiscovered, null, false, true);
    }
示例#2
0
    private IEnumerator DieCoroutine()
    {
        yield return(new WaitForSeconds(1f));

        isDead = true;
        dieEvent.Invoke(this);

        ParticleSystem particles = GetComponentInChildren <ParticleSystem>();

        particles.Play();

        ShockWave sw = Instantiate(dieShockWavePrefab);

        sw.transform.position = this.transform.position;
    }
示例#3
0
 private void Die()
 {
     die = true;
     DieEvent.Invoke();
     dieSound.Play();
     animator.SetTrigger("Die");
 }
示例#4
0
文件: Ship.cs 项目: VKalnik/Asteroids
 public void Die()
 {
     if (DieEvent != null)
     {
         DieEvent.Invoke(this, new EventArgs());
     }
 }
示例#5
0
 public void SetHp(float points)
 {
     Currenthealth = points;
     if (Currenthealth <= 0)
     {
         DieEvent?.Invoke();
     }
     ChangeView();
 }
示例#6
0
 public void Damage(float damage)
 {
     Currenthealth -= damage;
     if (Currenthealth <= 0)
     {
         DieEvent?.Invoke();
     }
     ChangeHealthEvent?.Invoke(Currenthealth);
 }
示例#7
0
 public void Damage(float value)
 {
     Hitpoints = Mathf.Max(0f, Hitpoints - value);
     HitpointsChangeEvent?.Invoke(Hitpoints);
     if (Hitpoints <= 0f)
     {
         DieEvent?.Invoke();
         Kill();
     }
 }
示例#8
0
    void OnDeviceDisconnected(string address)
    {
        // Check that this isn't an error-triggered disconnect, if it is, skip sending messages to the die
        if (_dice.TryGetValue(address, out Die die))
        {
            System.Action <Die> finishDisconnect = (d) =>
            {
                // Notify the die!
                d.die.OnDisconnected();
                onDieDisconnected?.Invoke(d.die);

                _dice.Remove(address);
            };

            switch (die.state)
            {
            case Die.State.Disconnecting:
                // This is perfectly okay
                finishDisconnect(die);
                break;

            case Die.State.Advertising:
                Debug.LogError("Disconnecting " + die.die.name + " is in incorrect state " + die.state);
                break;

            case Die.State.Connecting:
            case Die.State.Connected:
                Debug.LogWarning("Die " + die.die.name + " disconnected before subscribing");
                finishDisconnect(die);
                break;

            case Die.State.Subscribing:
                Debug.LogWarning("Die " + die.die.name + " disconnected while subscribing");

                // Clear error handler etc...
                onBluetoothError -= OnCharacteristicSubscriptionError;
                finishDisconnect(die);

                // Only kick off the next subscription IF this was the 'current' subscription attempt
                // Otherwise there will still be a subscription success/fail event and we'll trigger
                // the next one then.
                StartNextSubscribeToCharacteristic();
                break;

            case Die.State.Ready:
            default:
                finishDisconnect(die);
                break;
            }
        }
        else
        {
            Debug.LogError("Unknown die " + address + " disconnected!");
        }
    }
        protected virtual void Die()
        {
            alive = false;

            DieEvent?.Invoke(this);
#if DEBUG
            Debug.Log($"{this.GetInstanceID()} | {this.name} died.");
#endif

            Destroy(this.gameObject);
        }
示例#10
0
 public void Damage(float damage)
 {
     if (Currenthealth - damage <= 0)
     {
         DieEvent?.Invoke();
     }
     else
     {
         PhotonView?.RPC("DamageRPC", RpcTarget.All, damage);
     }
 }
示例#11
0
    private void OnCollisionEnter(Collision collision)
    {
        PlayerController pc = collision.collider.GetComponent <PlayerController>();

        if (pc != null && isAlive)
        {
            pc.guy.currentHealth = Mathf.Clamp(pc.guy.currentHealth + health, 0, pc.guy.maxHealth);
            isAlive = false;
            DieEvent?.Invoke(this.gameObject);
            Destroy(this.gameObject);
        }
    }
示例#12
0
        public void Damage(float value)
        {
            _health = Mathf.Max(0f, _health - value);

            ChangeHealthEvent?.Invoke(_health);

            if (_health > 0f)
            {
                return;
            }

            DieEvent?.Invoke();
        }
示例#13
0
        public void ElecticDamage(float value)
        {
            Hitpoints = Mathf.Max(0f, Hitpoints - (value - value * (ElecticResistance / 100)));

            ChangeEvent?.Invoke(Hitpoints);

            if (Hitpoints > 0f)
            {
                return;
            }

            DieEvent?.Invoke();
        }
示例#14
0
        public void PureDamage(float value)
        {
            Hitpoints = Mathf.Max(0f, Hitpoints - value);

            ChangeEvent?.Invoke(Hitpoints);

            if (Hitpoints > 0f)
            {
                return;
            }

            DieEvent?.Invoke();
        }
示例#15
0
        public void FireDamage(float value)
        {
            Hitpoints = Mathf.Max(0f, Hitpoints - (value - value * (FireResistance / 100)));
            StartCoroutine(TickDamageRoutine(value));

            ChangeEvent?.Invoke(Hitpoints);

            if (Hitpoints > 0f)
            {
                return;
            }

            DieEvent?.Invoke();
        }
示例#16
0
    private void LateUpdate()
    {
        if (!(CurrentHealth < 0))
        {
            return;
        }

        DieEvent.Invoke(gameObject);
        OnDie.Invoke();

        if (DestroyObjOnDie)
        {
            Destroy(gameObject);
        }
    }
示例#17
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag(ground))
        {
            isOnGround = true;
            playerAnimator.SetBool("IsJumping", false);
            playerAnimator.SetBool("IsRunning", true);
        }

        else if (collision.gameObject.CompareTag(enemy))
        {
            DieEvent?.Invoke();
            gameObject.SetActive(false);
        }
    }
示例#18
0
        private IEnumerator TickDamageRoutine(float damageValue)
        {
            {
                yield return(new WaitForSeconds(1));

                for (int i = _timer; i > 0; i--)
                {
                    Hitpoints -= (damageValue * 0.05f);
                    if (Hitpoints <= 0)
                    {
                        DieEvent?.Invoke();
                    }
                    yield return(new WaitForSeconds(1));
                }
            }
        }
示例#19
0
 public void Die()
 {
     if (isPlayer)
     {
         Debug.LogWarning("GAME OVER!");
         this.transform.position = spawnPoint.position;
         Spawner.SCORE_POINTS    = 0;
         currentHealth           = maxHealth;
     }
     else
     {
         DieEvent?.Invoke(this.gameObject);
         GameObject go = GameObject.Instantiate(shutteredCapsule);
         go.transform.position = this.transform.position;
         Destroy(this.gameObject);
     }
 }
示例#20
0
        public void IceDamage(float value)
        {
            Hitpoints = Mathf.Max(0f, Hitpoints - (value - value * (IceResistance / 100)));
            var movement = GetComponentInParent <Movement>();

            if (movement.Speed > 0)
            {
                movement.SetSpeed(movement.Speed - (movement.Speed * 0.1f));
            }

            ChangeEvent?.Invoke(Hitpoints);

            if (Hitpoints > 0f)
            {
                return;
            }

            DieEvent?.Invoke();
        }
示例#21
0
 private void OnMouseDown()
 {
     if (!_isFreezed)
     {
         clicksToDestroy--;
         HitEvent?.Invoke();
         if (clicksToDestroy <= 0)
         {
             gameProxy.AddScore(score);
             DieEvent?.Invoke();
             explodable.generateFragments();
             foreach (var fragment in explodable.fragments)
             {
                 fragment.AddComponent <ObjectCleaner>();
             }
             gameProxy.AddTime(timeAddedOnDestroy);
             gameProxy.ExplosionForce.doExplosion(transform.position);
             explodable.explode();
         }
     }
 }
示例#22
0
        public bool Hit(IEnumerable <ContactPoint2D> contactPoints)
        {
            var topHit = true;

            foreach (var contact in contactPoints)
            {
                if (Vector2.Dot(contact.normal, Vector2.up) < 0.7f)
                {
                    topHit = false;
                    break;
                }
            }

            if (topHit)
            {
                Collider.enabled = false;
                DieEvent?.Invoke();
                PlayDeathSound();
                Animator.SetTrigger(Die1);
            }

            return(topHit);
        }
示例#23
0
 public void Die(Transform visualTransform = null)
 {
     IsDead = true;
     if (questId > 0)
     {
         NpcInteractableEvent?.Invoke(questId);
     }
     DieEvent?.Invoke(this);
     if (visualTransform != null)
     {
         var chest = Instantiate(chestInWorld, visualTransform.position, quaternion.identity);
         foreach (var item in DropItems)
         {
             chest.itemProps.Add(new ItemProp
             {
                 item   = item.item.GetCopy(),
                 amount = item.amount
             });
         }
         chest.PopUp(visualTransform.position);
     }
     IncomeEvent?.Invoke(Income);
     gameObject.SetActive(!IsDead);
 }
示例#24
0
    void OnCharacteristicSubscriptionChanged(string characteristic)
    {
        Die sub = _dice.Values.FirstOrDefault(d => d.state == Die.State.Subscribing);

        if (sub != null)
        {
            // Clean up error handler
            onBluetoothError -= OnCharacteristicSubscriptionError;

            sub.state = Die.State.Ready;
            sub.die.OnConnected();
            onDieConnected?.Invoke(sub.die);

            StartNextSubscribeToCharacteristic();
        }
        else
        {
            sub = _dice.Values.FirstOrDefault(d => d.state == Die.State.Disconnecting);
            if (sub == null)
            {
                Debug.LogError("Subscription success but no subscribing die");
            }
        }
    }
示例#25
0
 void OnDieDisconnected(Central.IDie die)
 {
     onDieDisconnected?.Invoke((Die)die);
 }
示例#26
0
 void OnDieReady(Central.IDie die)
 {
     onDieConnected?.Invoke((Die)die);
 }
示例#27
0
        void Die()
        {
            DieEvent?.Invoke();

            Destroy(gameObject);
        }
示例#28
0
 public void Die()
 {
     Push();
     DieEvent?.Invoke(this);
 }
示例#29
0
 //  死亡
 public void PlayerDie()
 {
     OnDie.Invoke();
     GetComponent <PlayerShooting>().enabled = false;
 }
示例#30
0
 private void Dead()
 {
     DieEvent?.Invoke(parametersSO.team);
     Destroy(this);
 }