예제 #1
0
        public virtual bool Remove(GameObject obj)
        {
            attachedObjects.Remove(obj);
            ObjectRemoved?.Invoke(obj);

            return(true);
        }
예제 #2
0
 internal void DispatchObjectRemoved(DisplayObject target)
 {
     if (ObjectRemoved != null)
     {
         ObjectRemoved.Invoke(target);
     }
 }
예제 #3
0
 private static void Script_Destroyed(object obj)
 {
     if (obj is T script)
     {
         if (cachedObjects.Contains(script))
         {
             Debug.Log("Trying to destroy an object that has already been destroyed.");
         }
         else
         {
             foreach (var manager in managers)
             {
                 manager.Remove(script);
             }
             script.transform.SetParent(deadObjectContainer);
             script.gameObject.SetActive(false);
             cachedObjects.Enqueue(script);
             ObjectRemoved?.Invoke(script);
         }
     }
     else
     {
         Debug.LogError($"Somehow this factory subscribed to the Destroy event on an object of type {obj.GetType()} when it was supposed to be of type {typeof(T)}");
     }
 }
예제 #4
0
 private void Remove(string objectId)
 {
     lock (_objects)
     {
         _objects.Remove(objectId);
     }
     ObjectRemoved?.Invoke(this, objectId);
 }
예제 #5
0
        /// <summary>Invokes <see cref="ObjectRemoved"/> and <see cref="CollectionChanged"/> events.</summary>
        /// <param name="item">Removed item.</param>
        protected virtual void InvokeObjectRemoved(TObject item)
        {
            Verify.Argument.IsNotNull(item, nameof(item));

            item.MarkAsDeleted();
            ObjectRemoved?.Invoke(this, CreateEventArgs(item));
            CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(
                                          NotifyCollectionChangedAction.Remove, item));
        }
예제 #6
0
        /// <summary>
        /// Sets the terrain at the given objects location to the given object, overwriting any terrain already present there.
        /// </summary>
        /// <param name="terrain">Terrain to replace the current terrain with. <paramref name="terrain"/> must have its
        /// <see cref="IGameObject.IsStatic"/> flag set to true and its <see cref="IHasLayer.Layer"/> must be 0, or an exception will be thrown.</param>
        public void SetTerrain(IGameObject terrain)
        {
            if (terrain.Layer != 0)
            {
                throw new ArgumentException($"Terrain for Map must reside on layer 0.", nameof(terrain));
            }

            if (!terrain.IsStatic)
            {
                throw new ArgumentException($"Terrain for Map must be marked static via its {nameof(IGameObject.IsStatic)} flag.", nameof(terrain));
            }

            if (terrain.CurrentMap != null)
            {
                throw new ArgumentException($"Cannot add terrain to more than one {nameof(Map)}.", nameof(terrain));
            }

            if (!this.Contains(terrain.Position))
            {
                throw new ArgumentException($"Terrain added to map must be within the bounds of that map.");
            }

            if (!terrain.IsWalkable)
            {
                foreach (var obj in Entities.GetItems(terrain.Position))
                {
                    if (!obj.IsWalkable)
                    {
                        throw new Exception("Tried to place non-walkable terrain at a location that already has another non-walkable item.");
                    }
                }
            }

            var oldTerrain = _terrain[terrain.Position];

            if (oldTerrain != null)
            {
                oldTerrain.OnMapChanged(null);
                ObjectRemoved?.Invoke(this, new ItemEventArgs <IGameObject>(oldTerrain, oldTerrain.Position));
            }

            _terrain[terrain.Position] = terrain;

            terrain.OnMapChanged(this);
            ObjectAdded?.Invoke(this, new ItemEventArgs <IGameObject>(terrain, terrain.Position));
        }
        public void Remove <T>(T obj) where T : Sprite
        {
            if (obj == null)
            {
                return;
            }

            lock (syncLock)
            {
                if (obj is Aisling)
                {
                    _aislings.Remove(obj);
                }

                if (obj is Monster)
                {
                    _monsters.Remove(obj);
                }

                if (obj is Mundane)
                {
                    _mundanes.Remove(obj);
                }

                if (obj is Money)
                {
                    _money.Remove(obj);
                }

                if (obj is Item)
                {
                    _items.Remove(obj);
                }

                ObjectRemoved?.Invoke(obj);
            }
        }
예제 #8
0
파일: Map.cs 프로젝트: masonwheeler/GoRogue
        /// <summary>
        /// Constructor.  Constructs map with the given terrain layer, determining width/height based on the width/height of that terrain layer.
        /// </summary>
        /// <remarks>
        /// Because of the way polymorphism works for custom classes in C#, the <paramref name="terrainLayer"/> parameter MUST be of type
        /// <see cref="ISettableMapView{IGameObject}"/>, rather than <see cref="ISettableMapView{T}"/> where T is a type that derives from or implements
        /// <see cref="IGameObject"/>.  If you need to use a map view storing type T rather than IGameObject, use the
        /// <see cref="CreateMap{T}(ISettableMapView{T}, int, Distance, uint, uint, uint)"/> function to create the map.
        /// </remarks>
        /// <param name="terrainLayer">The <see cref="ISettableMapView{IGameObject}"/> that represents the terrain layer for this map.  After the
        /// map has been created, you should use the <see cref="SetTerrain(IGameObject)"/> function to modify the values in this map view, rather
        /// than setting the values via the map view itself -- if you re-assign the value at a location via the map view, the
        /// <see cref="ObjectAdded"/>/<see cref="ObjectRemoved"/> events are NOT guaranteed to be called, and many invariants of map may not be properly
        /// enforced.</param>
        /// <param name="numberOfEntityLayers">Number of non-terrain layers for the map.</param>
        /// <param name="distanceMeasurement"><see cref="Distance"/> measurement to use for pathing/measuring distance on the map.</param>
        /// <param name="layersBlockingWalkability">Layer mask containing those layers that should be allowed to have items that block walkability.
        /// Defaults to all layers.</param>
        /// <param name="layersBlockingTransparency">Layer mask containing those layers that should be allowed to have items that block FOV.
        /// Defaults to all layers.</param>
        /// <param name="entityLayersSupportingMultipleItems">Layer mask containing those layers that should be allowed to have multiple objects at the same
        /// location on the same layer.  Defaults to no layers.</param>
        public Map(ISettableMapView <IGameObject> terrainLayer, int numberOfEntityLayers, Distance distanceMeasurement, uint layersBlockingWalkability = uint.MaxValue,
                   uint layersBlockingTransparency = uint.MaxValue, uint entityLayersSupportingMultipleItems = 0)
        {
            _terrain = terrainLayer;
            Explored = new ArrayMap <bool>(_terrain.Width, _terrain.Height);

            _entities = new LayeredSpatialMap <IGameObject>(numberOfEntityLayers, 1, entityLayersSupportingMultipleItems);

            LayersBlockingWalkability  = layersBlockingWalkability;
            LayersBlockingTransparency = layersBlockingTransparency;

            _entities.ItemAdded   += (s, e) => ObjectAdded?.Invoke(this, e);
            _entities.ItemRemoved += (s, e) => ObjectRemoved?.Invoke(this, e);
            _entities.ItemMoved   += (s, e) => ObjectMoved?.Invoke(this, e);

            if (layersBlockingTransparency == 1)             // Only terrain so we optimize
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsTransparent);
            }
            else
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsTransparent);
            }

            if (layersBlockingWalkability == 1)             // Similar, only terrain blocks, so optimize
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsWalkable);
            }
            else
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsWalkable);
            }

            _fov  = new FOV(TransparencyView);
            AStar = new AStar(WalkabilityView, distanceMeasurement);
        }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnObjectRemoved(HlaObjectEventArgs e)
 {
     ObjectRemoved?.Invoke(this, e);// Raise the event.
 }
예제 #10
0
 public static void RemoveObject(GameObject gameObject)
 {
     sceneObjects.Remove(gameObject);
     SceneObjectListChanged?.Invoke(gameObject, new EventArgs());
     ObjectRemoved?.Invoke(gameObject, new EventArgs());
 }