Exemplo n.º 1
0
    public static void ReloadScene()
    {
        SceneManager.sceneLoaded += OnActiveSceneChangedCallback;

        SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);

        OnSceneIsEnding.Raise();
    }
Exemplo n.º 2
0
 private void OnDestroy()
 {
     if (!_isApplicationQuitting)
     {
         OnScrimDestroyed.Raise(transform.parent);
     }
 }
Exemplo n.º 3
0
        private void HandleItem(ItemActor itemActor)
        {
            _log.ErrorIfNull(itemActor, $"{itemActor} has tag {Tags.Item} but does not have an item component.");

            foreach (var interaction in itemActor.Interactions)
            {
                switch (interaction)
                {
                case InteractionTypes.Collect:
                    var collectibleItem = itemActor as ICollectible;
                    _log.ErrorIfNull(collectibleItem, $"{itemActor} has interaction {interaction} but does not implement {typeof(ICollectible).Name}.");
                    OnItemsCollected.Raise(collectibleItem.CollectedItems);
                    break;

                case InteractionTypes.Damage:
                    var damagingItem = itemActor as IDamaging;
                    _log.ErrorIfNull(damagingItem, $"{itemActor} has interaction {interaction} but does not implement {typeof(IDamaging).Name}.");
                    OnDamageTaken.Raise(damagingItem.Damage);
                    break;

                case InteractionTypes.Healing:
                    var healingItem = itemActor as IHealing;
                    _log.ErrorIfNull(healingItem, $"{itemActor} has interaction {interaction} but does not implement {typeof(IHealing).Name}.");
                    OnHealingApplied.Raise(healingItem.Healing);
                    break;

                default: _log.Error($"Unknown interaction '{interaction}'."); break;
                }
            }

            itemActor.HandledItem();
        }
Exemplo n.º 4
0
        public Space Build()
        {
            var space = SerializableSpace.Deserialize(_serializedSpaceJson).ToObject();

            OnCustomSpaceBuilt.Raise(space);

            return(space);
        }
Exemplo n.º 5
0
 protected override void UpdateOverlaps()
 {
     base.UpdateOverlaps();
     if (IsColliding)
     {
         OnFootTouch.Raise();
     }
     else
     {
         OnFootLeave.Raise();
     }
 }
Exemplo n.º 6
0
        public void SetState(ChunkState newState)
        {
            if (State == ChunkState.Constructing)
            {
                // Make sure we are set correctly
                if (newState == ChunkState.Constructing)
                {
                    State = newState;
                }
                // The only transition out of constructing is to Ready
                else if (newState == ChunkState.Ready)
                {
                    State = ChunkState.Ready;
                }
                else
                {
                    State = ChunkState.Constructing;
                    _log.Warning($"Chunk is not ready to be {newState}.  Ignoring.");
                }
            }
            else if (State != ChunkState.Constructing)
            {
                if (newState == ChunkState.Constructing)
                {
                    throw new InvalidOperationException($"Chunk cannot be returned to `Constructing` from {State}.");
                }
                else
                {
                    State = newState;
                }
            }

            var isActive = State == ChunkState.Active;

            gameObject.SetActive(isActive);
            foreach (var enemy in Enemies)
            {
                enemy.SetActive(isActive);
            }

            if (State == ChunkState.Ready)
            {
                OnChunkReady.Raise(this);
            }
            else if (State == ChunkState.Active)
            {
                OnChunkActivated.Raise(this);
            }
        }
Exemplo n.º 7
0
        private void Update()
        {
            if (_attachedObject == null)
            {
                transform.position += (transform.right * _movespeedPerSecond * Time.deltaTime);
            }

            _lifeRemaining -= Time.deltaTime;

            if (_lifeRemaining <= 0)
            {
                Explode();
                OnDroneLifespanEnded.Raise(this);
            }
        }
Exemplo n.º 8
0
 protected void OnDestroy()
 {
     if (!_isQuitting)
     {
         if (_isLoadingNewScene)
         {
             OnWorldObjectUnloaded();
         }
         else
         {
             OnWorldObjectDestroyed.Raise(this);
             OnWorldObjectDestroy();
         }
     }
 }
Exemplo n.º 9
0
        private void OnTriggerEnter2D(Collider2D collider)
        {
            if (collider.gameObject.layer == LayerMask.NameToLayer(Layers.WorldObject))
            {
                var worldObject = collider.GetComponent <WorldObject>();

                if (worldObject)
                {
                    OnWorldObjectBumped.Raise(worldObject);
                }
                else
                {
                    _log.Warning($"{worldObject.name} is on the World Object layer but is not a World Object.");
                }
            }
        }
Exemplo n.º 10
0
        public void ApplyDamage(int amount)
        {
            if (amount < _damageResistance)
            {
                return;
            }
            else
            {
                amount -= _damageResistance;
            }

            if (!_isTakingDamage && amount > 0)
            {
                ApplyDeduct(amount);
                if (Health.IsAlive)
                {
                    OnDamage();
                    OnActorDamaged.Raise(this);
                    _isTakingDamage = true;
                    Timekeeper.SetTimer(_damageInvulnerabilityDuration, () => _isTakingDamage = false);
                }
            }
        }
Exemplo n.º 11
0
        protected void HandleHazard(Hazard hazard)
        {
            _log.ErrorIfNull(hazard, $"{hazard} has tag {Tags.Hazard} but does not have a hazard component.");

            foreach (var effect in hazard.Effects)
            {
                switch (effect)
                {
                case HazardEffects.Damage:
                    var damagingHazard = hazard as IDamaging;
                    _log.ErrorIfNull(damagingHazard, $"{hazard} has effect {effect} but does not implement {typeof(IDamaging).Name}.");
                    OnDamageTaken.Raise(damagingHazard.Damage);
                    break;

                case HazardEffects.Impulse:
                    var knockbackHazard = hazard as IImpulsive;
                    _log.ErrorIfNull(knockbackHazard, $"{hazard} has effect {effect} but does not implement {typeof(IImpulsive).Name}.");
                    _rigidbody.velocity = knockbackHazard.GetImpulse(transform.position, _rigidbody.velocity);
                    break;

                default: _log.Error($"Unknown effect '{effect}'."); break;
                }
            }
        }
Exemplo n.º 12
0
 private void OnClick() => OnRequestWeaponEquipmentToggle.Raise(_weapon, !_isEquipped);
Exemplo n.º 13
0
 private void OnClick() => OnRequestPurchase.Raise(_transaction);
Exemplo n.º 14
0
 protected override void OnWorldObjectDestroy() => OnItemDestroyed.Raise(this);
Exemplo n.º 15
0
 protected void Die()
 {
     OnActorDeath.Raise(this);
     OnDeath();
 }
Exemplo n.º 16
0
        public void Register(Block block)
        {
            BlockMap[block.Position] = block;
            block.transform.SetParent(transform, true);

            block.OnBlockDestroyed  += OnBlockDestroyed;
            block.OnBlockCrumbled   += OnBlockCrumbled;
            block.OnBlockStabilized += OnBlockStabilized;

            OnChunkChanged.Raise(this);
        }