Exemple #1
0
        public void Destroy()
        {
            _isValid = false;

            try
            {
                OnDestroy?.Invoke(this);
            }
            catch (Exception e)
            {
                _runtime.GetLogger().Error(e);
            }
            _atoms.Clear();

            JSApi.JS_FreeValue(_ctx, _numberConstructor);
            JSApi.JS_FreeValue(_ctx, _stringConstructor);
            JSApi.JS_FreeValue(_ctx, _globalObject);
            JSApi.JS_FreeValue(_ctx, _operatorCreate);

            JSApi.JS_FreeValue(_ctx, _moduleCache);
            JSApi.JS_FreeValue(_ctx, _require);
            JSApi.JS_FreeContext(_ctx);

            if (_coroutines != null)
            {
                Object.DestroyImmediate(_coroutines);
                _coroutines = null;
            }

            _ctx = JSContext.Null;
        }
Exemple #2
0
        public static CacheItem <T> Crate(T t, string type = null, OnDestroy <T> onDestroy = null)
        {
            CacheItem <T> cacheItem = new CacheItem <T> ();

            cacheItem.init(t, type, onDestroy);
            return(cacheItem);
        }
 /// <summary>
 /// IDestructible interface.
 /// </summary>
 public void Destroy()
 {
     destroyed = true;
     attached  = false;
     connection.SendDetachRequest(instanceId);
     OnDestroy?.Invoke(this);
 }
Exemple #4
0
    private IEnumerator DestroyMe()
    {
        yield return(new WaitForSeconds(destroyTime));

        OnDestroy?.Invoke();
        Destroy(gameObject);
    }
Exemple #5
0
        /// <summary>
        /// 触发删除该集合中的actor武器
        /// </summary>
        public void Destroy(IEnumerable <UserData> list)
        {
            for (int i = 0; i < list.Count(); i++)
            {
                var weaponBaseContainer = list.ElementAt(i);

                OnDestroy?.Invoke(weaponBaseContainer.ActorID);

                if (level.GetActor(weaponBaseContainer.ActorID) is ISkillComponentContainer weapon)
                {
                    weapon.DestroySkill();
                }
                //Log.Trace("Destory 火控组件销毁一个武器"+weaponBaseContainer.ActorID+" 类型"+weaponBaseContainer.ActorType);
                skillInitList.Remove(weaponBaseContainer);
            }
            //foreach (var weaponBaseContainer in list)
            //{
            //    //var actor = level.GetActor(weaponBaseContainer.ActorID) as ISkillContainer;
            //    skillInitList.Remove(weaponBaseContainer);
            //    OnDestroy?.Invoke(weaponBaseContainer.ActorID);
            //    level.AddEventMessagesToHandlerForward(new DestroyEventMessage(weaponBaseContainer.ActorID));

            //    //actor?.DestroySkill();
            //}
        }
Exemple #6
0
 public void Destroy()
 {
     if (OnDestroy != null)
     {
         OnDestroy.Invoke(this, new OnDestroyEventArgs(this));
     }
 }
Exemple #7
0
        /// <summary>
        /// 触发删除该类型的所有Actor武器
        /// </summary>
        public void Destroy(int i)
        {
            List <UserData> weaponList = new List <UserData>();

            for (var j = 0; j < skillInitList.Count; j++)
            {
                if (skillInitList[j].ActorType == i)
                {
                    //判断该生成列表中的对象是否已经在世界中
                    if (level.ContainsID(skillInitList[j].ActorID))
                    {
                        weaponList.Add(skillInitList[j]);
                    }
                }
            }
            //从集合中删除
            foreach (var weaponBaseContainer in weaponList)
            {
                //var actor = level.GetActor(weaponBaseContainer.ActorID) as ISkillContainer;
                skillInitList.Remove(weaponBaseContainer);
                OnDestroy?.Invoke(weaponBaseContainer.ActorID);
                if (level.GetActor(weaponBaseContainer.ActorID) is ISkillComponentContainer weapon)
                {
                    weapon.DestroySkill();
                }
                //actor?.DestroySkill();
            }
        }
Exemple #8
0
        public void Destroy()
        {
            lock (this)
            {
                if (!_isValid)
                {
                    return;
                }
                _isValid = false;
                try
                {
                    OnDestroy?.Invoke(this);
                }
                catch (Exception e)
                {
                    _logger?.WriteException(e);
                }
            }

            _timerManager.Destroy();
            _objectCache.Destroy();
            _typeDB.Destroy();

            GC.Collect();
            GC.WaitForPendingFinalizers();
            ExecutePendingActions();

            // _rwlock.EnterWriteLock();
            for (int i = 0, count = _contextRefs.Count; i < count; i++)
            {
                var contextRef = _contextRefs[i];
                contextRef.target.Destroy();
            }

            _contextRefs.Clear();
            _mainContext = null;
            // _rwlock.ExitWriteLock();


            if (_asyncManager != null)
            {
                _asyncManager.Destroy();
                _asyncManager = null;
            }

            JSApi.JS_FreeRuntime(_rt);
            var id = _runtimeId;

            _runtimeId = -1;
            _rt        = JSRuntime.Null;

            try
            {
                OnAfterDestroy?.Invoke(id);
            }
            catch (Exception e)
            {
                _logger?.WriteException(e);
            }
        }
Exemple #9
0
 public void init(T t, string type = null, OnDestroy <T> onDestroy = null)
 {
     _isFree    = true;
     _type      = type;
     _instance  = t;
     _onDestroy = onDestroy;
 }
Exemple #10
0
 private void Start()
 {
     _position     = GetComponent <Transform>().position;
     _destroyer    = GetComponent <OnDestroy>();
     _dialogueData = GetComponentInChildren <DialogueData>();
     _image        = GetComponent <SpriteRenderer>();
 }
Exemple #11
0
 public void Destroy()
 {
     Close();
     Receiver             = null;
     receiveNetworkBuffer = null;
     OnDestroy?.Invoke(this);
     OnDestroy = null;
 }
Exemple #12
0
 public virtual void Destroy()
 {
     foreach (Component c in components)
     {
         c.Destroy();
     }
     OnDestroy?.Invoke(this);
 }
Exemple #13
0
 public void DestroyFirefly()
 {
     GameManager.Instance.DestroyFireflyEvent += delegate {
         OnDestroy.Invoke();
         Destroy(gameObject);
         gm.fireflies.Remove(this);
         positions.Terminer();
     };
 }
Exemple #14
0
 public void Damage(float amount)
 {
     health = Mathf.Clamp(health - amount, 0, config.MaxHealth);
     OnHealthChanged?.Invoke(health, amount);
     if (health <= 0)
     {
         OnDestroy?.Invoke();
     }
 }
Exemple #15
0
 /// <summary>
 /// Signal to the client that the battle has ended along with whether the attackers or defenders won.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private async void OnEndOfBattle(object sender, EndOfBattleEventArgs args)
 {
     var tasks = new List <Task>
     {
         _battleHubContext.Clients.Users(args.ParticipantIds).SendAsync("endBattle", args.DidAttackersWin),
         Task.Run(() => OnDestroy?.Invoke(this, new EventArgs()))
     };
     await Task.WhenAll(tasks);
 }
Exemple #16
0
        public void Destroy()
        {
            if (myState == ObjectState.OnFire)
            {
                myState = ObjectState.Chared;
            }

            OnDestroy?.Invoke(this, myState);
        }
Exemple #17
0
        public virtual void Destoy()
        {
            if (Destroyed)
            {
                return;
            }

            OnDestroy?.Invoke(this);
            Destroyed = true;
        }
Exemple #18
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent <PlayerController>())
     {
         if (InputInventory.Instance.AddToInventory(MyInput))
         {
             OnDestroy?.Invoke();
             Destroy(gameObject);
         }
     }
 }
 private void Update()
 {
     if (!hasFocus)
     {
         if (Input.anyKeyDown)
         {
             OnDestroy?.Invoke();
             GameObject.Destroy(this);
         }
     }
 }
Exemple #20
0
    public void Destroy(Owner damageSourceOwner)
    {
        if (IsDestroyed)
        {
            return;
        }

        Instantiate(_explosion, transform.position, Quaternion.identity).GetComponent <Explosion>().SetOwner(damageSourceOwner);
        IsDestroyed = true;
        OnDestroy?.Invoke(damageSourceOwner);
    }
Exemple #21
0
    private void DestroyBlock()

    {
        if (IsNeedToCreateBonus())
        {
            int randIndex = Random.Range(0, pickUpPrefabs.Length);
            Instantiate(pickUpPrefabs[randIndex], transform.position, Quaternion.identity);
        }

        Destroy(gameObject);
        OnDestroy?.Invoke(this);
    }
Exemple #22
0
 private void Hit() // проверка удара
 {
     currentHits++;
     if (currentHits == NumberHit) // если удар последний
     {
         OnDestroy?.Invoke(this);
         Destroy(gameObject);
     }
     else
     {
         UpdateView();
     }
 }
Exemple #23
0
 public void DealDamage(int damage, DamageType type)
 {
     _health -= damage;
     if (!Alive)
     {
         OnDestroy.SafeInvoke(this, type);
         Destroy(gameObject);
     }
     else
     {
         var ratio = 1f - (float)(_health - 1) / (_initialHealth - 1);
         _colorComponent.UpdateColor(ratio);
     }
 }
 private void OnDisable()
 {
     OnDestroy?.Invoke();
     foreach (var sequence in sequences)
     {
         sequence.ResetSequence();
         sequence.onStartSequence    -= StartSequence;
         sequence.onCompletedSection -= OnCorrectSequence;
         foreach (var section in sequence.commands)
         {
             section.onCorrectInput -= OnCorrectInput;
         }
     }
 }
Exemple #25
0
 public void Destroy()
 {
     Close();
     //OnClose = null;
     //OnConnect = null;
     //OnReceive = null;
     receiveNetworkBuffer = null;
     //sock.OnReceive -= Sock_OnReceive;
     //sock.OnClose -= Sock_OnClose;
     //sock.OnConnect -= Sock_OnConnect;
     sock.Receiver = null;
     sock          = null;
     OnDestroy?.Invoke(this);
     OnDestroy = null;
 }
Exemple #26
0
        public void Destroy()
        {
            if (!_isValid)
            {
                return;
            }
            _isValid = false;

            try
            {
                OnDestroy?.Invoke(this);
            }
            catch (Exception e)
            {
                _runtime.GetLogger()?.WriteException(e);
            }
            _stringCache.Destroy();
            _atoms.Clear();

            JSApi.JS_FreeValue(_ctx, _numberConstructor);
            JSApi.JS_FreeValue(_ctx, _stringConstructor);
            JSApi.JS_FreeValue(_ctx, _functionConstructor);
            JSApi.JS_FreeValue(_ctx, _globalObject);
            JSApi.JS_FreeValue(_ctx, _operatorCreate);

            JSApi.JS_FreeValue(_ctx, _moduleCache);
            JSApi.JS_FreeValue(_ctx, _require);
            JSApi.JS_FreeContext(_ctx);
            var id = _contextId;

            _contextId = -1;

            if (_coroutines != null)
            {
                _coroutines.Destroy();
                _coroutines = null;
            }

            _ctx = JSContext.Null;
            try
            {
                OnAfterDestroy?.Invoke(id);
            }
            catch (Exception e)
            {
                _runtime.GetLogger()?.WriteException(e);
            }
        }
Exemple #27
0
        /// <summary>
        /// Removes the player's entity from the map in preparation for a log out.
        /// </summary>
        public void EndConnection()
        {
            lock (_lock)
            {
                if (IsActive)
                {
                    LastAccessed = DateTime.Now;
                    _currentMapManager.RemoveEntity(Entity);
                    _currentMapManager.GameTick       -= OnGameTick;
                    _mapBattleManager.OnCreatedBattle -= OnCreatedBattle;
                    IsActive = false;
                }
            }

            OnDestroy?.Invoke(this, new System.EventArgs());
        }
Exemple #28
0
    // public INetworkReceiver<NetworkConnection> Receiver { get; set; }

    public virtual void Destroy()
    {
        // remove references
        //sock.OnClose -= Socket_OnClose;
        //sock.OnConnect -= Socket_OnConnect;
        //sock.OnReceive -= Socket_OnReceive;
        sock?.Destroy();
        //Receiver = null;
        Close();
        sock = null;

        OnClose   = null;
        OnConnect = null;
        //OnDataReceived = null;
        OnDestroy?.Invoke(this);
        OnDestroy = null;
    }
Exemple #29
0
 public void Dispose()
 {
     Hide();
     Res.Release();
     OnClose();
     for (int i = 0; i < _subViews.Count; i++)
     {
         _subViews[i].OnClose();
     }
     Binding.Reset();
     OnDestroy?.Invoke();
     ViewModel?.OnViewDestroy();
     if (Go != null)
     {
         Object.Destroy(Go.gameObject);
     }
 }
Exemple #30
0
    public override void TakeDamage(object sender, EventArgs e)
    {
        if (_hitpoint > 0)
        {
            _hitpoint--;
            //Debug.Log("hit");
        }
        else
        {
            // HP limiter
            _hitpoint = 0;

            // Fire up dead event
            OnDestroy?.Invoke(this, EventArgs.Empty);
            _isAlive = false;
        }
    }