/// <summary> /// Removes the given object from the game screens list of objects to handle. /// </summary> /// <typeparam name="T">The type of the object to be removed. Needs to inherit from IDraw or IUpdate</typeparam> /// <param name="toRemove">The object to be removed to the game screen</param> /// <returns>True if the given object could be removed, false otherwise</returns> public bool RemoveObject <T>(T toRemove) { var road = toRemove as Road; var platform = toRemove as PlatformBlank; var settler = toRemove as Settler; var freeMovingUnit = toRemove as FreeMovingUnit; if (!typeof(IDraw).IsAssignableFrom(typeof(T)) && !typeof(IUpdate).IsAssignableFrom(typeof(T)) && road == null && platform == null) { return(false); } if (typeof(ICollider).IsAssignableFrom(typeof(T))) { mMap.GetCollisionMap().RemoveCollider((ICollider)toRemove); } if (road != null && !road.Blueprint) { mMap.RemoveRoad(road); } if (platform != null && !platform.mBlueprint) { mMap.RemovePlatform(platform); mDirector.GetMilitaryManager.RemovePlatform(platform); } if (settler != null) { settler.BuildCommandCenter -= SettlerBuild; } // unsubscribe from this military unit when deleted if (freeMovingUnit != null && freeMovingUnit.Friendly) { mSelBox.SelectingBox -= freeMovingUnit.BoxSelected; } if (typeof(IRevealing).IsAssignableFrom(typeof(T))) { mFow.RemoveRevealingObject((IRevealing)toRemove); } if (typeof(ISpatial).IsAssignableFrom(typeof(T))) { mSpatialObjects.Remove((ISpatial)toRemove); return(true); } if (typeof(IDraw).IsAssignableFrom(typeof(T))) { mDrawables.Remove((IDraw)toRemove); } if (typeof(IUpdate).IsAssignableFrom(typeof(T))) { mUpdateables.Remove((IUpdate)toRemove); } return(true); }