Beispiel #1
0
        void RemoveTool(PaintGunItem item, int index)
        {
            ToolRemoved?.Invoke(item);

            Tools.RemoveAtFast(index);
            itemPool.Return(item);

            if (Tools.Count == 0)
            {
                SetUpdateMethods(UpdateFlags.UPDATE_DRAW, false);

                if (spawnedRifles.Count == 0)
                {
                    SetUpdateMethods(UpdateFlags.UPDATE_AFTER_SIM, false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Tool unRegister
        /// </summary>
        /// <param name="info">Tool information</param>
        /// <returns>result</returns>
        public bool UnRegisterTool(HcToolInfo info)
        {
            var lockTakenScan     = false;
            var lockTakenRegister = false;

            try
            {
                // lock
                Monitor.TryEnter(ScannedTools, Timeout, ref lockTakenScan);
                Monitor.TryEnter(RegisteredTools, Timeout, ref lockTakenRegister);
                // check lock taken
                if (!lockTakenScan || !lockTakenRegister)
                {
                    return(false);
                }

                // get register tool
                var register = FindToolInfo(RegisteredTools, info.Mac);
                if (register == null)
                {
                    return(false);
                }
                // remove register tool
                RegisteredTools.Remove(register);
                // tool removed event
                ToolRemoved?.Invoke(info);

                return(true);
            }
            finally
            {
                // unlock
                if (lockTakenScan)
                {
                    Monitor.Exit(ScannedTools);
                }
                if (lockTakenRegister)
                {
                    Monitor.Exit(RegisteredTools);
                }
            }
        }