// Update is called once per frame void Update() { // return if no lighthouse was selected since last update if (m_selectedLighthouse == null) { return; } // get current mouseposition var worldlocation = Camera.main.ScreenPointToRay(Input.mousePosition).origin; worldlocation.z = -2f; // move lighthouse to mouse position // will update visibility polygon m_selectedLighthouse.Pos = worldlocation; // see if lighthouse was released if (Input.GetMouseButtonUp(0)) { //check whether lighthouse is over the island if (!LevelPolygon.ContainsInside(m_selectedLighthouse.Pos)) { // destroy the lighthouse m_solution.RemoveLighthouse(m_selectedLighthouse); Destroy(m_selectedLighthouse.gameObject); UpdateLighthouseText(); } // lighthouse no longer selected m_selectedLighthouse = null; CheckSolution(); } }
public void InitLevel() { // clear old level m_solution.Clear(); m_selectedLighthouse = null; m_advanceButton.Disable(); // create new level var level = m_levels[m_levelCounter]; LevelPolygon = level.Polygon; m_maxNumberOfLighthouses = level.MaxNumberOfLighthouses; m_levelMesh.Polygon = LevelPolygon; // update text box UpdateLighthouseText(); }
/// <summary> /// Update the vision polygon for the given lighthouse. /// Calculates the visibility polygon. /// </summary> /// <param name="m_lighthouse"></param> public void UpdateVision(ArtGalleryLightHouse m_lighthouse) { if (LevelPolygon.ContainsInside(m_lighthouse.Pos)) { // calculate new visibility polygon var vision = VisibilitySweep.Vision(LevelPolygon, m_lighthouse.Pos); if (vision == null) { throw new Exception("Vision polygon cannot be null"); } // update lighthouse visibility m_lighthouse.VisionPoly = vision; m_lighthouse.VisionAreaMesh.Polygon = new Polygon2DWithHoles(vision); } else { // remove visibility polygon from lighthouse m_lighthouse.VisionPoly = null; m_lighthouse.VisionAreaMesh.Polygon = null; } }
/// <summary> /// Add lighthouse to solution. /// </summary> /// <param name="m_lighthouse"></param> public void AddLighthouse(ArtGalleryLightHouse m_lighthouse) { m_lighthouses.Add(m_lighthouse); }
/// <summary> /// Remove the given lighthouse from the solution /// </summary> /// <param name="m_lighthouse"></param> public void RemoveLighthouse(ArtGalleryLightHouse m_lighthouse) { m_lighthouses.Remove(m_lighthouse); Destroy(m_lighthouse); }
/// <summary> /// Set given lighthouse as selected one /// </summary> /// <param name="a_select"></param> internal void SelectLighthouse(ArtGalleryLightHouse a_select) { m_selectedLighthouse = a_select; }