예제 #1
0
        private IEnumerator GetMetadata()
        {
            if (_meta != null)
            {
                yield break;
            }
            var req = UnityWebRequest.Get(MetadataUrl);

            yield return(req.SendWebRequest());

            if (!string.IsNullOrEmpty(req.error))
            {
                Fail();
                yield break;
            }

            var json = req.downloadHandler.text;

            Debug.Log($"Received metadata: {json}");
            _meta = JsonUtility.FromJson <PromoMetadata>(json);
            if (Developers.Enabled && SkipCaching)
            {
                _meta.version = StencilRandom.Range(0, int.MaxValue);
            }
        }
예제 #2
0
        public static T WeightedRandom <T>(this ICollection <T> coll, float?total = null) where T : IWeightHaver
        {
            total = total ?? coll.Sum(w => w.GetWeight());
            var rand = StencilRandom.Range(0f, total.Value);
            var test = 0f;

            foreach (var p in coll)
            {
                var w = p.GetWeight();
                if (rand >= test && rand < w + test)
                {
                    return(p);
                }
                test += w;
            }

            return(default(T));
        }