Example #1
0
        void OnDrawGizmos()
        {
            if (Application.isPlaying)
            {
                if (this.drawGizmos && this.gizmoCategories != null)
                {
                    if (this.cachedGizmoWeights == null)
                    {
                        this.cachedGizmoWeights = new Dictionary <string, List <WeightedItem> >();
                    }

                    var categories = this.gizmoCategories.Split(',');

                    foreach (var category in categories)
                    {
                        // Get the cached gizmo weights.
                        List <WeightedItem> weights;
                        if (!this.cachedGizmoWeights.TryGetValue(category, out weights))
                        {
                            weights = new List <WeightedItem>();
                            this.cachedGizmoWeights.Add(category, weights);
                        }

                        // Update the cached gizmo weights.
                        if (this.gizmoLastUpdated + this.gizmoUpdateInterval <= Time.time)
                        {
                            weights.Clear();
                            this.FillAndPrepareWeights(category, weights, true);
                            this.gizmoLastUpdated = Time.time;
                        }

                        WeightedItem topWeightItem = null;
                        float        topWeight     = 0f;

                        foreach (var weightItem in weights)
                        {
                            this.DrawWeightedItemGizmos(weightItem);

                            if (weightItem.Weight > topWeight)
                            {
                                topWeightItem = weightItem;
                                topWeight     = weightItem.Weight;
                            }
                        }

                        if (this.drawTopWeightGizmo && topWeightItem != null)
                        {
                            var s = new Vector3(this.gizmoMaxSize, this.gizmoMaxHeight, this.gizmoMaxSize);
                            Gizmos.color = Color.green;
                            Gizmos.DrawWireCube(topWeightItem.Target.TargetPosition + Vector3.up * s.y / 2f, s);

                            topWeightItem = null;
                            topWeight     = 0f;
                        }
                    }
                }
            }
        }
Example #2
0
        private void DrawWeightedItemGizmos(WeightedItem weightItem)
        {
            if (weightItem.Target != null)
            {
                var w = Mathf.Min(weightItem.Weight, this.gizmoMaxWeight);
                var p = weightItem.Target.TargetPosition;
                var s = this.gizmoMaxSize / this.gizmoMaxWeight * w;
                var h = this.gizmoMaxHeight / this.gizmoMaxWeight * w;
                var c = Color.Lerp(Color.red, Color.green, 1f / this.gizmoMaxWeight * w);
                c.a = 0.75f;

                Gizmos.color = c;
                Gizmos.DrawCube(p + Vector3.up * h / 2f, new Vector3(s, h, s));
            }
        }
Example #3
0
        public static WeightedItem WeightByDistance(this WeightedItem item, Vector3 origin, float maxDist, float scale)
        {
            if (maxDist <= 0f)
            {
                throw new System.ArgumentOutOfRangeException("maxDist", maxDist, "maxDist must be greater than zero");
            }

            var dist       = Vector3.Distance(origin, item.Target.TargetPosition);
            var distWeight = scale * (1f - (1f / maxDist * Mathf.Min(dist, maxDist)));

            var newItem = new WeightedItem(item);

            newItem.Weight += distWeight;

            return(newItem);
        }
Example #4
0
        public static WeightedItem WeightByInterpolation(this WeightedItem item, Vector3 origin, float maxDist, float scale, Interpolate.EaseType easeType)
        {
            var easeFunc = Interpolate.Ease(easeType);
            var start    = 0f;
            var dist     = scale;
            var duration = maxDist;

            var elapsed    = Vector3.Distance(origin, item.Target.TargetPosition);
            var distWeight = scale - easeFunc(start, dist, elapsed, duration);

            var newItem = new WeightedItem(item);

            newItem.Weight += distWeight;

            return(newItem);
        }
Example #5
0
        public static IEnumerable <WeightedItem> WeightByInterpolation(this IEnumerable <WeightedItem> items, Vector3 origin, float maxDist, float scale, Interpolate.EaseType easeType)
        {
            var easeFunc = Interpolate.Ease(easeType);
            var start    = 0f;
            var dist     = scale;
            var duration = maxDist;

            foreach (var item in items)
            {
                var elapsed    = Vector3.Distance(origin, item.Target.TargetPosition);
                var distWeight = scale - easeFunc(start, dist, elapsed, duration);

                var newItem = new WeightedItem(item);
                newItem.Weight += distWeight;

                yield return(newItem);
            }
        }