Ejemplo n.º 1
0
        public Component GetClosestComponent(int x, int y, ComponentFilter cf)
        {
            Component        result           = null;
            int              componentType    = cf.Type;
            List <Component> components       = m_vComponents[componentType];
            Vector           v                = new Vector(x, y);
            double           maxLengthSquared = 0;

            if (components.Count > 0)
            {
                foreach (var c in components)
                {
                    if (cf.TestComponent(c))
                    {
                        GameObject go            = c.GetParent();
                        double     lengthSquared = (v - go.GetPosition()).LengthSquared;
                        if (lengthSquared < maxLengthSquared || result == null)
                        {
                            maxLengthSquared = lengthSquared;
                            result           = c;
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Component GetClosestComponent(int x, int y, ComponentFilter cf)
        {
            Component        component = null;
            int              type      = cf.Type;
            List <Component> list      = this.m_vComponents[type];
            Vector           vector    = new Vector((double)x, (double)y);
            double           num       = 0.0;

            if (list.Count > 0)
            {
                foreach (Component current in list)
                {
                    if (cf.TestComponent(current))
                    {
                        GameObject parent        = current.GetParent();
                        double     lengthSquared = (vector - parent.GetPosition()).LengthSquared;
                        if (lengthSquared < num || component == null)
                        {
                            num       = lengthSquared;
                            component = current;
                        }
                    }
                }
            }
            return(component);
        }