Esempio n. 1
0
        public T QueryRandomNodeOfType <T>() where T : I_EnvironmentNode
        {
            EnvironmentQueryResult pois = QueryNodesOfType <T>();

            if (pois.Count() > 0)
            {
                I_EnvironmentNode randomPoi = pois.AtIndex(Random.Range(0, pois.Count()));
                return((T)randomPoi);
            }

            return(default(T));
        }
Esempio n. 2
0
        public T QueryClosestNodeOfType <T>(Vector2 _pos, out float _sqrDistance) where T : I_EnvironmentNode
        {
            EnvironmentQueryResult pois = QueryNodesOfType <T>();
            float closestDistance       = float.MaxValue;
            int   closestIndex          = -1;

            for (int i = 0; i < pois.Count(); i++)
            {
                Vector2 posXZ    = pois.GetPositionXZ(i);
                float   distance = Vector2.SqrMagnitude(_pos - posXZ);
                closestIndex = i;
            }

            _sqrDistance = closestDistance;
            if (closestIndex == -1)
            {
                return(default(T));
            }
            return((T)pois.AtIndex(closestIndex));
        }