コード例 #1
0
ファイル: Map.cs プロジェクト: msruzy/WickedEngine-1
        /// <summary>
        /// Finds a collection of objects in the map using a delegate.
        /// </summary>
        /// <remarks>
        /// This method performs basically the same process as FindObject, but instead
        /// of returning the first object for which the delegate returns true, it returns
        /// a collection of all objects for which the delegate returns true.
        /// </remarks>
        /// <param name="finder">The delegate used to search for the object.</param>
        /// <returns>A collection of all MapObjects for which the delegate returned true.</returns>
        public IEnumerable <MapObject> FindObjects(MapObjectFinder finder)
        {
            foreach (var layer in Layers)
            {
                MapObjectLayer objLayer = layer as MapObjectLayer;
                if (objLayer == null)
                {
                    continue;
                }

                foreach (var obj in objLayer.Objects)
                {
                    if (finder(objLayer, obj))
                    {
                        yield return(obj);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: msruzy/WickedEngine-1
        /// <summary>
        /// Finds an object in the map using a delegate.
        /// </summary>
        /// <remarks>
        /// This method is used when an object is desired, but there is no specific
        /// layer to find the object on. The delegate allows the caller to create
        /// any logic they want for finding the object. A simple example for finding
        /// the first object named "goal" in any layer would be this:
        ///
        /// var goal = map.FindObject((layer, obj) => return obj.Name.Equals("goal"));
        ///
        /// You could also use the layer name or any other logic to find an object.
        /// The first object for which the delegate returns true is the object returned
        /// to the caller. If the delegate never returns true, the method returns null.
        /// </remarks>
        /// <param name="finder">The delegate used to search for the object.</param>
        /// <returns>The MapObject if the delegate returned true, null otherwise.</returns>
        public MapObject FindObject(MapObjectFinder finder)
        {
            foreach (var layer in Layers)
            {
                MapObjectLayer objLayer = layer as MapObjectLayer;
                if (objLayer == null)
                {
                    continue;
                }

                foreach (var obj in objLayer.Objects)
                {
                    if (finder(objLayer, obj))
                    {
                        return(obj);
                    }
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: Teclys23/stormsword
        /// <summary>
        /// Finds a collection of objects in the map using a delegate.
        /// </summary>
        /// <remarks>
        /// This method performs basically the same process as FindObject, but instead
        /// of returning the first object for which the delegate returns true, it returns
        /// a collection of all objects for which the delegate returns true.
        /// </remarks>
        /// <param name="finder">The delegate used to search for the object.</param>
        /// <returns>A collection of all MapObjects for which the delegate returned true.</returns>
        public IEnumerable<MapObject> FindObjects(MapObjectFinder finder)
        {
            foreach (var layer in Layers)
            {
                MapObjectLayer objLayer = layer as MapObjectLayer;
                if (objLayer == null)
                    continue;

                foreach (var obj in objLayer.Objects)
                {
                    if (finder(objLayer, obj))
                        yield return obj;
                }
            }
        }
コード例 #4
0
ファイル: Map.cs プロジェクト: Teclys23/stormsword
        /// <summary>
        /// Finds an object in the map using a delegate.
        /// </summary>
        /// <remarks>
        /// This method is used when an object is desired, but there is no specific
        /// layer to find the object on. The delegate allows the caller to create 
        /// any logic they want for finding the object. A simple example for finding
        /// the first object named "goal" in any layer would be this:
        /// 
        /// var goal = map.FindObject((layer, obj) => return obj.Name.Equals("goal"));
        /// 
        /// You could also use the layer name or any other logic to find an object.
        /// The first object for which the delegate returns true is the object returned
        /// to the caller. If the delegate never returns true, the method returns null.
        /// </remarks>
        /// <param name="finder">The delegate used to search for the object.</param>
        /// <returns>The MapObject if the delegate returned true, null otherwise.</returns>
        public MapObject FindObject(MapObjectFinder finder)
        {
            foreach (var layer in Layers)
            {
                MapObjectLayer objLayer = layer as MapObjectLayer;
                if (objLayer == null)
                    continue;

                foreach (var obj in objLayer.Objects)
                {
                    if (finder(objLayer, obj))
                        return obj;
                }
            }

            return null;
        }
コード例 #5
0
ファイル: Map.cs プロジェクト: Sharparam/DiseasedToast
 public IEnumerable<MapObject> FindObjects(MapObjectFinder finder)
 {
     return from layer in _layers.OfType<MapObjectLayer>() from mapObject in layer.Objects where finder(layer, mapObject) select mapObject;
 }
コード例 #6
0
ファイル: Map.cs プロジェクト: Sharparam/DiseasedToast
 public MapObject FindObject(MapObjectFinder finder)
 {
     return _layers.OfType<MapObjectLayer>().Select(layer => layer.Objects.FirstOrDefault(obj => finder(layer, obj))).FirstOrDefault(mapObject => mapObject != null);
 }