Beispiel #1
0
    private void Fire(ITarget intendedTarget)
    {
        if (FireParticle)
        {
            FireParticle.Play();
        }

        for (int i = 0; i < Amount; i++)
        {
            Quaternion rotation = Muzzle.transform.rotation * Quaternion.Euler(UnityEngine.Random.Range(-Inaccuracy, Inaccuracy), UnityEngine.Random.Range(-Inaccuracy, Inaccuracy), 0f);
            GameObject proj     = _pool.GetObject(Muzzle.transform.position, rotation);

            _team.ApplyTeam(proj);
            proj.transform.position = Muzzle.transform.position;
            proj.transform.rotation = Muzzle.transform.rotation;

            Projectile projectile = proj.GetComponent <Projectile>();
            projectile.HitLayerMask = _hitLayerMask;
            projectile.Target       = intendedTarget;

            projectile.Damage     = Damage;
            projectile.DamageType = DamageType;
            projectile.Speed      = Speed;

            projectile.Fire(rotation * Vector3.forward);

            projectile.OnHit  += Projectile_OnHit;
            projectile.OnKill += Projectile_OnKill;
            projectile.OnEnd  += Projectile_OnEnd;

            OnProjectile?.Invoke(this, projectile);
        }

        OnFire?.Invoke(this);
    }
        private void AddPlayerListViewElement(PhotonPlayer player)
        {
            ListViewElementPhotonPlayer element = null;

            if (null != ListViewElementPool)
            {
                element = ListViewElementPool.GetObject();
            }

            if (null == element)
            {
                element = GameObject.Instantiate <ListViewElementPhotonPlayer>(ListViewElementPrefab);
            }
            else
            {
                element.gameObject.SetActive(true);
            }

            ListViewPlayers.AddControl(element.gameObject);

            string buttonText = GetPlayerListViewElementText(player);

            element.Text.text = buttonText;
            element.Player    = player;

            if (false == PhotonNetwork.offlineMode)
            {
                RoomLobbyPlayerState playerState =
                    (RoomLobbyPlayerState)player.CustomProperties[PlayerCustomPropertiesKey.RoomLobbyPlayerState.ToString()];
                SetListViewElementImageColor(element, playerState);
            }
        }
        public static T GetObjectSync <T>(this IObjectPool <T> pool) where T : class
        {
            var objTask = pool.GetObject();

            objTask.Wait();
            return(objTask.Result);
        }
        protected ListViewElementProject CreateListViewElement(SharedProject proj)
        {
            ListViewElementProject newElement = null;

            if (null != ListViewElementPool)
            {
                newElement = ListViewElementPool.GetObject();
            }

            if (null == newElement)
            {
                newElement = GameObject.Instantiate <ListViewElementProject>(ListViewElementPrefab);
                MousePointerEvents events = newElement.GetComponent <MousePointerEvents>();
                SubscribeToMouseEventPointers(events, proj, TooltipComponent);
            }
            else
            {
                MousePointerEvents events = newElement.GetComponent <MousePointerEvents>();
                events.RemoveAllListeners();
                SubscribeToMouseEventPointers(events, proj, TooltipComponent);
            }

            newElement.Project = proj;
            newElement.gameObject.SetActive(true);

            return(newElement);
        }
        public static Usage <T> UseObjectSync <T>(this IObjectPool <T> pool, CancellationToken token) where T : class
        {
            var objTask = pool.GetObject(token);

            objTask.Wait();
            return(new Usage <T>(pool, objTask.Result));
        }
Beispiel #6
0
        public long MemoryStreamPool()
        {
            long l;

            using (var x = _objectPool.GetObject())
            {
                l = x.MemoryStream.Length;
            }
            return(l);
        }
        internal WeaponPickerDialog CreateWeaponPickerDialog(IObjectPool pool, IWeaponPod pod)
        {
            Debug.Assert(ActiveDialog is null);
            var dialog = pool.GetObject <WeaponPickerDialog>();

            dialog.Init(initContext, pod, weaponsSettings);
            dialog.Position(GetDialogTopLeft(pod.Bounds, View, dialog.Size));
            dialog.InitContent(initContentContext);
            return(dialog);
        }
        /// <summary>
        /// 得到tracker链接
        /// </summary>
        /// <returns></returns>
        public static TcpConnection GetTrackerConnection(string groupName)
        {
            bool isGetTcpConnection = true;

            do
            {
                IPEndPoint tracker;
                if (string.IsNullOrEmpty(groupName))//没有限制组的时候,负载均衡
                {
                    _trackerServerIndex++;
                    if (_trackerServerIndex >= TcpConnectionPoolManager.TrackerServers.Length)
                    {
                        _trackerServerIndex = 0;
                    }
                    tracker = TcpConnectionPoolManager.TrackerServers[_trackerServerIndex];
                }
                else
                {
                    IList <IPEndPoint> list = TcpConnectionPoolManager.GroupServer[groupName];
                    int index = sort.ContainsKey(groupName) ? sort[groupName] + 1 : 0;
                    if (index >= list.Count)
                    {
                        index = 0;
                    }
                    tracker         = list[index];
                    sort[groupName] = index;
                }

                IPAddress ip   = tracker.Address;
                int       port = tracker.Port;
                IObjectPool <TcpConnection> pool = TcpConnectionPoolManager.GetPool(ip.ToString(), port, true, false);
                try
                {
                    if (null != _logger)
                    {
                        _logger.InfoFormat("Tracker可用连接数:{0}", pool.NumIdle);
                    }
                    TcpConnection tcp = pool.GetObject(ip.ToString(), port);
                    if (null != tcp && tcp.Connected)
                    {
                        return(tcp);
                    }
                    isGetTcpConnection = false;
                }
                catch (Exception exc)
                {
                    if (null != _logger)
                    {
                        _logger.ErrorFormat("连接追踪器服务器时发生异常,异常信息为:{0}", exc.Message);
                    }
                    isGetTcpConnection = false;
                }
            } while (!isGetTcpConnection);
            return(null);
        }
Beispiel #9
0
        /// <summary>
        /// Compiles the input linqExpression into a Linq expression tree
        /// </summary>
        /// <param name="linqExpression">The linqExpression.</param>
        /// <returns></returns>
        public Action <object, object> CompileAction(LinqExpressionToRun linqExpression)
        {
            Guard.NotNull(() => linqExpression, linqExpression);
            Guard.NotNullOrEmpty(() => linqExpression.Linq, linqExpression.Linq);
            var compiler = _objectPool.GetObject();

            try
            {
                return(compiler.CompileAction(linqExpression));
            }
            catch (Exception error)
            {
                throw new CompileException($"Failed to compile linq expression {linqExpression.Linq}", error,
                                           linqExpression.Linq);
            }
            finally
            {
                _objectPool.ReturnObject(compiler);
            }
        }
Beispiel #10
0
        public static PooledObject <T> WaitForGet <T>(this IObjectPool <T> self)
        {
            PooledObject <T> result;

            while ((result = self.GetObject()) == null)
            {
                System.Threading.Thread.Sleep(0);
            }

            return(result);
        }
Beispiel #11
0
        public static Enemy GetEnemyFromPool <TSettings>(IObjectPool pool, TSettings settings)
            where TSettings : Settings.Enemy
        {
            Enemy enemy;

            switch (settings)
            {
            case Settings.CreepyWorm creepyWorm:
                enemy = pool.GetObject <CreepyWorm>();
                break;

            case Settings.Skeleton skeleton:
                enemy = pool.GetObject <Skeleton>();
                break;

            default:
                throw new ArgumentException($"No matching enemy for {typeof(TSettings)}", nameof(settings));
            }
            return(enemy);
        }
        private ListViewElementWorker CreateWorkerListViewElement(LocalWorker companyWorker)
        {
            ListViewElementWorker newElement = null;

            if (null != WorkerListViewElementsPool)
            {
                newElement = WorkerListViewElementsPool.GetObject();
            }

            if (null == newElement)
            {
                newElement = UIWorkers.CreateWorkerListViewElement(companyWorker, ListViewWorkerElementPrefab, TooltipComponent);
                UIElementDrag drag = newElement.GetComponent <UIElementDrag>();
                drag.DragParentTransform = gameObject.GetComponent <RectTransform>();
            }

            newElement.gameObject.SetActive(true);
            newElement.Text.text = GetWorkerListViewElementText(companyWorker);
            newElement.Worker    = companyWorker;

            return(newElement);
        }
Beispiel #13
0
        private void SpawnCharacter(LocalWorker companyWorker)
        {
            if (SpawnPoints != null && SpawnPoints.Length > 0)
            {
                int        randomIndex     = Random.Range(0, SpawnPoints.Length);
                Transform  randomTransform = SpawnPoints[randomIndex];
                Vector2    spawnPos        = randomTransform.position;
                GameObject newCharacter    = null;

                if (null != CharactersPool)
                {
                    newCharacter = CharactersPool.GetObject();
                }

                if (null == newCharacter)
                {
                    newCharacter = GameObject.Instantiate(CharacterPrefab, spawnPos, Quaternion.identity);
                }

                newCharacter.gameObject.SetActive(true);
                CharacterText textComponent = newCharacter.GetComponentInChildren <CharacterText>();
                textComponent.Text              = string.Format("{0} {1}", companyWorker.Name, companyWorker.Surename);
                companyWorker.AbsenceStarted   += OnWorkerAbsenceStarted;
                companyWorker.AbsenceFinished  += OnWorkerAbsenceFinished;
                companyWorker.PhysicalCharacter = newCharacter;
                SpawnedCharacters.Add(companyWorker);
            }
#if DEVELOPMENT_BUILD || UNITY_EDITOR
            else
            {
                string debugInfo =
                    string.Format("[{0}] Failed to spawn character in game world (no spawn points defined)",
                                  this.GetType().Name,
                                  MAX_SPAWN_RETRIES);
                Debug.Log(debugInfo);
            }
#endif
        }
        public static TcpConnection GetStorageConnection(string groupName)
        {
            StorageServerInfo           storageServerInfo = TrackerClient.GetStoreStorage(groupName);
            IObjectPool <TcpConnection> pool = TcpConnectionPoolManager.GetPool(storageServerInfo.IpAddress, storageServerInfo.Port, false, true);

            try
            {
                TcpConnection storageConnection = pool.GetObject(storageServerInfo.IpAddress, storageServerInfo.Port);
                storageConnection.Index = storageServerInfo.StorePathIndex;
                if (null != _logger)
                {
                    _logger.InfoFormat("Storage可用连接数为:{0}", pool.NumIdle);
                }
                return(storageConnection);
            }
            catch (Exception exc)
            {
                if (null != _logger)
                {
                    _logger.WarnFormat("连接Storage服务器时发生异常,异常信息为:{0}", exc.Message);
                }
                throw;
            }
        }
 /// <summary>
 ///   Retrieves an object from the pool.
 /// </summary>
 /// <returns>An object from the pool.</returns>
 public override T Get() => _adaptedObjectPool.GetObject();
 public static Task <T> GetObject <T>(this IObjectPool <T> pool) where T : class
 {
     return(pool.GetObject(CancellationToken.None));
 }
        public static async Task <Usage <T> > UseObject <T>(this IObjectPool <T> pool) where T : class
        {
            var obj = await pool.GetObject();

            return(new Usage <T>(pool, obj));
        }
        public static async Task <Usage <T> > UseObject <T>(this IObjectPool <T> pool, CancellationToken token) where T : class
        {
            var obj = await pool.GetObject(token);

            return(new Usage <T>(pool, obj));
        }