Esempio n. 1
0
    public List <CelestialBody> GetClosestCelestialBodies(CelestialBody.CelestialType celestialType, int maxResults, Vector3 position)
    {
        List <CelestialBody> resultsList  = new List <CelestialBody>();
        List <float>         distanceList = new List <float>();

        if (maxResults > 0)
        {
            foreach (KeyValuePair <uint, CelestialBody> celestialBody in m_CelestialBodies)
            {
                if ((celestialBody.Value.Type & celestialType) != CelestialBody.CelestialType.Invalid)
                {
                    float distance = (celestialBody.Value.transform.position - position).sqrMagnitude;

                    int index = 0;
                    for ( ; index < distanceList.Count; ++index)
                    {
                        if (distance < distanceList[index])
                        {
                            break;
                        }
                    }
                    distanceList.Insert(index, distance);
                    resultsList.Insert(index, celestialBody.Value);
                }
            }

            if (maxResults < resultsList.Count)
            {
                resultsList.RemoveRange(maxResults, resultsList.Count - maxResults);
            }
        }

        return(resultsList);
    }
Esempio n. 2
0
    public List <CelestialBody> GetCelestialBodies(CelestialBody.CelestialType celestialType)
    {
        List <CelestialBody> celestialBodyList = new List <CelestialBody>();

        foreach (KeyValuePair <uint, CelestialBody> celestialBody in m_CelestialBodies)
        {
            if (CelestialBody.CelestialType.Invalid != (celestialBody.Value.Type & celestialType))
            {
                celestialBodyList.Add(celestialBody.Value);
            }
        }

        return(celestialBodyList);
    }
Esempio n. 3
0
 public bool CelestialTypeIsActive(CelestialBody.CelestialType type)
 {
     return((type & m_CelestialFilter) != CelestialBody.CelestialType.Invalid);
 }
Esempio n. 4
0
    public static List <CelestialBody> GetClosestBodiesToPosition(List <CelestialBody> inputList, int maxResults, CelestialBody.CelestialType type, Vector3 position)
    {
        List <CelestialBody> resultsList  = new List <CelestialBody>();
        List <float>         distanceList = new List <float>();

        if (maxResults > 0)
        {
            foreach (CelestialBody body in inputList)
            {
                if ((body.Type & type) != CelestialBody.CelestialType.Invalid)
                {
                    float distance = (body.transform.position - position).sqrMagnitude;

                    int index = 0;
                    for ( ; index < distanceList.Count; ++index)
                    {
                        if (distance < distanceList[index])
                        {
                            break;
                        }
                    }
                    distanceList.Insert(index, distance);
                    resultsList.Insert(index, body);
                }
            }

            if (maxResults < resultsList.Count)
            {
                resultsList.RemoveRange(maxResults, resultsList.Count - maxResults);
            }
        }

        return(resultsList);
    }
Esempio n. 5
0
 public List <CelestialBody> GetClosestBodies(int maxEntries, CelestialBody.CelestialType celestialFilter, Vector3 position)
 {
     return(m_VirtualManager.GetClosestCelestialBodies(celestialFilter, maxEntries, position));
 }
Esempio n. 6
0
    public CelestialBody GetClosestCelestialBody(CelestialBody.CelestialType celestialType, Vector3 position)
    {
        List <CelestialBody> celestialBodyList = GetClosestCelestialBodies(celestialType, 1, position);

        return((0 < celestialBodyList.Count) ? celestialBodyList[0] : null);
    }