//**************************************************************************************************** // //**************************************************************************************************** public void UpdateMapObjectsPosition() { UnityEngine.Plane[] planes = GeometryUtility.CalculateFrustumPlanes(m_camera); Vector2 bounds = new Vector2(m_BRCorner.x - m_TLCorner.x, m_TLCorner.z - m_BRCorner.z); WebMapObjectBase mapObj = null; m_selectables.Clear(); for (int flag = 0; flag < m_flags.Count; ++flag) { mapObj = m_flags[flag]; UpdateMapObjectPosition(bounds, mapObj); mapObj.UpdateVisibilityStatus(planes); } for (int pin = 0; pin < m_pins.Count; ++pin) { mapObj = m_pins[pin]; UpdateMapObjectPosition(bounds, mapObj); mapObj.UpdateVisibilityStatus(planes); } }
//**************************************************************************************************** // //**************************************************************************************************** public override bool AcceptDrop(IDragDrop drop) { if (drop is WebMapObjectBase) { WebMapObjectBase mapObject = drop as WebMapObjectBase; Localizable localizable = CreateMapObjectLocalizable((drop is WebMapFlag) ? OBJECT_TYPE.FLAG : OBJECT_TYPE.PIN); if (localizable != null) { localizable.m_coord.latitude = GetLatitudeFrom3DCoord(mapObject.transform.position); localizable.m_coord.longitude = GetLongitudeFrom3DCoord(mapObject.transform.position); localizable.m_coord.altitude = 0.0f; localizable.DBPush(); } DeleteMapObject(mapObject); return(true); } return(false); }
//**************************************************************************************************** // //**************************************************************************************************** public WebMapObjectBase ReuseOrCreateMapObject(List <WebMapObjectBase> pool, List <WebMapObjectBase> list, OBJECT_TYPE type, CREATE_MODE mode, Localizable localizable) { WebMapObjectBase mapObj = null; if ((pool != null) && (pool.Count > 0)) { mapObj = pool[pool.Count - 1]; pool.RemoveAt(pool.Count - 1); if (mapObj != null) { mapObj.localizable = localizable; if (list != null) { list.Add(mapObj); } } } else { mapObj = CreateMapObject(type, mode, localizable); } return(mapObj); }
//**************************************************************************************************** // //**************************************************************************************************** public void DeleteMapObject(WebMapObjectBase mapObject) { if (mapObject != null) { List <WebMapObjectBase> list = (mapObject.GetType() == typeof(WebMapFlag)) ? m_flags : m_pins; list.Remove(mapObject); GameObject.Destroy(mapObject.gameObject); } }
//**************************************************************************************************** // //**************************************************************************************************** public void UpdateMapObjectPosition(Vector2 bounds, WebMapObjectBase mapObject) { Localizable loc = (mapObject != null) ? mapObject.localizable : null; if (loc != null) { Vector3 pos = GetRelativePositionFromGeoCoords(bounds, loc.m_coord.longitude.deg, loc.m_coord.latitude.deg); mapObject.transform.position = new Vector3(pos.x, 0.0f, pos.z); } }
//**************************************************************************************************** // //**************************************************************************************************** public WebMapObjectBase CreateMapObject(OBJECT_TYPE type, CREATE_MODE mode, Localizable localizable) { GameObject mdl = Resources.Load <GameObject>(m_mapObjectModel[( int )type]); Quaternion q = Quaternion.AngleAxis(-90.0f, Vector3.right); GameObject Obj = (mdl != null) ? GameObject.Instantiate(mdl, Vector3.up * 32.0f, q, m_deposit.transform) as GameObject : null; if (Obj != null) { WebMapObjectBase mapObj = Obj.GetComponent <WebMapObjectBase>(); if (mapObj != null) { mapObj.localizable = localizable; if (mode == CREATE_MODE.CREATE_DRAG) { if (DragDropOperation.Begin(this, mapObj) == false) { DragDropOperation.Cancel(); } else { UpdateDrag(mapObj); return(mapObj); } } else { List <WebMapObjectBase> list = (type == OBJECT_TYPE.FLAG) ? m_flags : m_pins; list.Add(mapObj); return(mapObj); } } } return(null); }
//**************************************************************************************************** // //**************************************************************************************************** public void UpdateMapObjectsSelection() { if (Focusable.any) { return; } if (DragDropOperation.pending) { if (m_objSelection != null) { m_objSelection.SetActive(false); } return; } m_selectables.Clear(); for (int flag = 0; flag < m_flags.Count; ++flag) { m_flags[flag].UpdateSelectablesList(m_handpick.Point, m_selectables); } for (int pin = 0; pin < m_pins.Count; ++pin) { m_pins [pin].UpdateSelectablesList(m_handpick.Point, m_selectables); } float sqrMinDist = float.MaxValue; WebMapObjectBase selection = null; for (int sel = 0; sel < m_selectables.Count; ++sel) { if (sqrMinDist > m_selectables[sel].sqrDistFromCursor) { sqrMinDist = m_selectables[sel].sqrDistFromCursor; selection = m_selectables[sel]; } } if (m_objSelection != null) { m_objSelection.SetActive(selection != null); if (m_objSelection.activeInHierarchy) { float selectionScaleModifier = 0.7f + (0.3f * Mathf.Sin(Mathf.PI * ((Time.time % 0.250f) / 0.250f))); Vector3 selectionAnchorPos = selection.transform.position; m_objSelection.transform.position = new Vector3(selectionAnchorPos.x, 2.0f, selectionAnchorPos.z); m_objSelection.transform.localScale = XForm.LocalScaleForWorldScale((Vector3.one * selection.bounds.size.x) * selectionScaleModifier, m_objSelection.transform); } } if (selection != null) { if (Input.GetMouseButtonDown(0)) { if (HUDSites.Instance != null) { HUDSites.Instance.items.SelectItemUserDatas(selection.localizable); } POPUPItem.Instance.Show(null, selection.localizable); } } }