Exemple #1
0
        /// <summary>
        /// Gets a random item
        /// </summary>
        /// <returns>The result item</returns>
        public T GetItem()
        {
            var stoppingPofloat = GlobalRandom.NextFloat() * this.totalWeight;

            foreach (var item in this.items.ToList())
            {
                if (stoppingPofloat < item.Value)
                {
                    return(item.Key);
                }

                stoppingPofloat -= item.Value;
            }

            throw new Exception("Error getting item");
        }
Exemple #2
0
 /// <summary>
 /// Called once per frame
 /// </summary>
 protected void Update()
 {
     if (this._magnitude > 0)
     {
         this._magnitude = Utils.Lerp(this._magnitude, 0, this._deacyFactor);
         if (this._magnitude <= MinMagnitude)
         {
             this._magnitude = 0;
         }
         else
         {
             var randomAngle = GlobalRandom.NextFloat() * Mathf.PI * 2;
             var offset      = new Vector3(Mathf.Cos(randomAngle), Mathf.Sin(randomAngle), 0) * this._magnitude;
             this.transform.position = this._panFocus + offset;
         }
     }
 }