public void MarkersShouldSetCorrectly() { const int MAX_MARKERS = 5; const int EXCLUSION_AREA = 1; var markerPrefab = new GameObject().AddComponent <UserMarkerObject>(); var overlay = new GameObject(); Func <float, float, Vector3> coordToMapPosFunc = (x, y) => { return(new Vector3(x, y, 0)); }; // create scenes to test var scenes = new List <HotScenesController.HotSceneInfo>(); scenes.Add(CreateSceneInfo(new Vector2Int(0, 0))); scenes.Add(CreateSceneInfo(new Vector2Int(3, 4))); scenes.Add(CreateSceneInfo(new Vector2Int(-4, -4))); // create handler MarkersHandler handler = new MarkersHandler(markerPrefab, overlay.transform, MAX_MARKERS, coordToMapPosFunc); Assert.AreEqual(MAX_MARKERS, handler.availableMarkers.Count); Assert.AreEqual(0, handler.usedMarkers.Count); // set exclusion area and set markers for scenes handler.SetExclusionArea(Vector2Int.zero, EXCLUSION_AREA); handler.SetMarkers(scenes); // check pools count and marker hidden by exclusion area Assert.AreEqual(MAX_MARKERS - scenes.Count, handler.availableMarkers.Count); Assert.AreEqual(scenes.Count, handler.usedMarkers.Count); Assert.AreEqual(scenes.Count - 1, GetActiveGameObjectsInParent(overlay.transform), "A marker should be hidden by exclusion area"); // move exclusion area and check markers hidden by exclusion area handler.SetExclusionArea(new Vector2Int(6, 6), EXCLUSION_AREA); Assert.AreEqual(scenes.Count, GetActiveGameObjectsInParent(overlay.transform), "All markers should be visible"); // remove a scene and check pools count scenes.RemoveAt(0); handler.SetMarkers(scenes); Assert.AreEqual(MAX_MARKERS - scenes.Count, handler.availableMarkers.Count); Assert.AreEqual(scenes.Count, handler.usedMarkers.Count); handler.Dispose(); UnityEngine.Object.Destroy(markerPrefab); UnityEngine.Object.Destroy(overlay); }
/// <summary> /// Constructor /// </summary> /// <param name="markerPrefab">prefab for markers</param> /// <param name="overlayContainer">parent for markers</param> /// <param name="coordToMapPosFunc">function to transform coords to map position</param> public MapGlobalUsersPositionMarkerController(UserMarkerObject markerPrefab, Transform overlayContainer, Func <float, float, Vector3> coordToMapPosFunc) { fetchScenesHandler = new FetchScenesHandler(UPDATE_INTERVAL_INITIAL, UPDATE_INTERVAL_FOREGROUND, UPDATE_INTERVAL_BACKGROUND); markersHandler = new MarkersHandler(markerPrefab, overlayContainer, MAX_MARKERS, coordToMapPosFunc); userPositionHandler = new UserPositionHandler(); markersContainer = overlayContainer; fetchScenesHandler.OnScenesFetched += OnScenesFetched; userPositionHandler.OnPlayerCoordsChanged += OnPlayerCoordsChanged; CommonScriptableObjects.rendererState.OnChange += OnRenderStateChanged; KernelConfig.i.EnsureConfigInitialized().Then(config => { commsRadius = (int)config.comms.commRadius + COMMS_RADIUS_THRESHOLD; OnPlayerCoordsChanged(userPositionHandler.playerCoords); }); OnRenderStateChanged(CommonScriptableObjects.rendererState.Get(), false); }