// ------------------------------------------------------------------------------------------------ /// <summary> /// Called most of the time the sim is running to highlight whatever is under the mouse currently. /// If it's part of set, then highlight is updated on selected set. I.e. if we have mouse-dragged /// to select a bunch of stuff, subsequently doing a mouse-over one of them will highlight all of them /// </summary> /// <returns></returns> public void UpdateHilight(UN_Camera cam) // ------------------------------------------------------------------------------------------------ { //SM_ISelectable obj = CheckForObjectUnderMouse(cam); //if (obj == null) //{ // UnHilightAll(); //} //else if (obj.IsHilighted == false) // the object wasn't hilighted before //{ // UnHilightAll(); // clear out old set // // if this object is a member of a set, then hilight all of them // if (obj.IsSelected && _selected.Count > 1) // { // foreach (var v in _selected) // { // SetHilighted(v); // } // } // else // { // SetHilighted(obj); // } //} // otherwise we were already hilighted and have nothing to do. }
// ----------------------------------------------------------------------------------------- public bool FindTerrainPointUnderMouse(UN_Camera cam, ref Vector3 where) // ----------------------------------------------------------------------------------------- { if (Dbg.Assert(cam != null)) { return(false); } Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (!Physics.Raycast(ray, out hitInfo, 300, _terrainLayerMask)) { return(false); } where = hitInfo.point; return(true); }
// ------------------------------------------------------------------------------------------------ /// <summary> /// Simply returns the 'best' ISelectable under the mouse /// </summary> /// <returns></returns> protected SM_ISelectable CheckForObjectUnderMouse(UN_Camera cam) // ------------------------------------------------------------------------------------------------ { if (Dbg.Assert(cam != null)) { return(null); } Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); if (hits == null) { return(null); } int bestNdx = -1; float bestDst = float.MaxValue; SM_ISelectable bestSelect = null; for (int i = 0; i < hits.Length; i++) { if (hits[i].distance < bestDst) { if (CheckParentsForSelectable(hits[i].transform, ref bestSelect)) { bestNdx = i; } } } if (bestNdx < 0) { return(null); } return(bestSelect); }
// ----------------------------------------------------------------------------------------- /// <summary> /// should be called when we're curious if the mouse is selecting something else /// </summary> /// <param name="mode"></param> public bool SelectSingleUnderMouse(UN_Camera camera) // ----------------------------------------------------------------------------------------- { return(SetSelected(CheckForObjectUnderMouse(camera))); }