public override void OnInspectorGUI() { ARObject obj = (ARObject)target; SerializedProperty title = this.serializedObject.FindProperty("Title"); EditorGUILayout.PropertyField(title, true); serializedObject.ApplyModifiedProperties(); if (GUILayout.Button("Add reflection")) { CCReflectFloat f = new CCReflectFloat(); obj.ReflectFloats.Add(f); } else if (GUILayout.Button("Clear reflections")) { obj.ReflectFloats.Clear(); } else { SerializedProperty reflectFloats = this.serializedObject.FindProperty("ReflectFloats"); EditorGUILayout.PropertyField(reflectFloats, true); serializedObject.ApplyModifiedProperties(); } }
private void printAllObjectStats() { ARObjects = GameObject.FindGameObjectsWithTag("ARObject"); foreach (GameObject ARObject in ARObjects) { Debug.Log(string.Format(ARObject.ToString() + ":\n" + "Position:\n" + "x:{0:0.######}\n" + "y:{1:0.######}\n" + "z:{2:0.######}\n" + "Rotation:\n" + "xr:{3:0.######}\n" + "yr:{4:0.######}\n" + "zr:{5:0.######}\n" + "Scale\n" + "xs:{6:0.######}\n" + "ys:{7:0.######}\n" + "zs:{8:0.######}\n", ARObject.transform.position.x, ARObject.transform.position.y, ARObject.transform.position.z, ARObject.transform.rotation.x, ARObject.transform.rotation.y, ARObject.transform.rotation.z, ARObject.transform.localScale.x, ARObject.transform.localScale.y, ARObject.transform.localScale.z )); } }
public void Init(ARObject arObject, System.Action <ARObject> onPressed) { obj = arObject; onPressedAction = onPressed; title.text = arObject.Title; button.onClick.AddListener(ButtonPressed); }
void Update() { List <Touch> touches = TouchHelper.GetTouches(); if (touches.Count > 0) { var touch = touches[0]; if (touch.phase == TouchPhase.Began) { var ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { ARObject arObj = hit.collider.GetComponent <ARObject>(); if (arObj == null) { arObj = hit.collider.GetComponentInParent <ARObject>(); } if (arObj != null) { SelectObject(arObj); } } } } }
public void adminHandler() { Renderer selectedRenderer = m_selectedObject.GetComponent <Renderer>(); // GUI's Y is flipped from the mouse's Y Rect screenRect = _WorldBoundsToScreen(Camera.main, selectedRenderer.bounds); float yMin = Screen.height - screenRect.yMin; float yMax = Screen.height - screenRect.yMax; screenRect.yMin = Mathf.Min(yMin, yMax); screenRect.yMax = Mathf.Max(yMin, yMax); if (GUI.Button(screenRect, "<size=30>Remove</size>")) { m_objectList.Remove(m_selectedObject.gameObject); Destroy(m_selectedObject.gameObject); // m_selectedObject.SendMessage("Hide"); m_selectedObject = null; m_selectedRect = new Rect(); } else { m_selectedRect = screenRect; } }
/// <summary> /// Correct all saved marks when loop closure happens. /// /// When Tango Service is in learning mode, the drift will accumulate overtime, but when the system sees a /// preexisting area, it will do a operation to correct all previously saved poses /// (the pose you can query with GetPoseAtTime). This operation is called loop closure. When loop closure happens, /// we will need to re-query all previously saved marker position in order to achieve the best result. /// This function is doing the querying job based on timestamp. /// </summary> private void _UpdateMarkersForLoopClosures() { // Adjust mark's position each time we have a loop closure detected. foreach (GameObject obj in m_objectList) { ARObject tempObject = obj.GetComponent <ARObject>(); if (tempObject.m_timestamp != -1.0f) { TangoCoordinateFramePair pair; TangoPoseData relocalizedPose = new TangoPoseData(); pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE; PoseProvider.GetPoseAtTime(relocalizedPose, tempObject.m_timestamp, pair); Matrix4x4 uwTDevice = m_poseController.m_uwTss * relocalizedPose.ToMatrix4x4() * m_poseController.m_dTuc; Matrix4x4 uwTObject = uwTDevice * tempObject.m_deviceTObject; obj.transform.position = uwTObject.GetColumn(3); obj.transform.rotation = Quaternion.LookRotation(uwTObject.GetColumn(2), uwTObject.GetColumn(1)); } } }
void ObjectSelected(ARObject obj) { gameObject.SetActive(false); GameObject arObj = Instantiate(obj).gameObject; arObj.gameObject.AddComponent <ObjectPlacer>(); contextView.SelectObject(arObj.GetComponent <ARObject>()); }
private void AnimateKitten() { Debug.Log("-> AnimateKitten()"); //resetToActive (GameObject.FindGameObjectsWithTag ("ARObject")); foreach (GameObject ARObject in ARObjects) { ARObject.SetActive(true); } }
public void SetupWithObject(ARObject obj) { currentObj = obj; foreach (CCReflectFloat refFloat in currentObj.ReflectFloats) { FloatModifierUIEntry entry = Instantiate(entryPrefab).GetComponent <FloatModifierUIEntry>(); entry.SetupWithReflector(refFloat); entry.transform.SetParent(targetParent); } gameObject.SetActive(true); }
private string createARObjectStatsDictionary() { Dictionary <string, string> result = new Dictionary <string, string> (); ARObjects = GameObject.FindGameObjectsWithTag("ARObject"); foreach (GameObject ARObject in ARObjects) { string ARObjName = ARObject.ToString().Split(' ') [0]; string objStats = MyDictionaryToJson(createObjectStatDictionary(ARObject)); result.Add(ARObjName, objStats); } return(MyDictionaryToJson(result)); }
private void addToList(ARObject arObject) { if (APPManager.Instance.CurrStatus == StatusAPP.Init) { return; } ARObjectData data = new ARObjectData(); data.Id = 0; data.Lat = arObject.Lat; data.Long = arObject.Long; data.Message = arObject.Message; lstARObject.Add(data); }
void TaskOnClick() { GameObject[] ARObjects = GameObject.FindGameObjectsWithTag("ARObject"); foreach (GameObject ARObject in ARObjects) { ARObject.SetActive(false); } string filename = "Screenshot" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg"; ScreenCapture.CaptureScreenshot(filename); foreach (GameObject ARObject in ARObjects) { ARObject.SetActive(true); } }
public void Show(ARObject obj) { if (obj != null) { gameObject.SetActive(true); isShowed = true; GetDirectionTo(obj.transform.position); formRect.sizeDelta = new Vector2(formRect.sizeDelta.x, 0); formMask.enabled = true; formImage.color = Color.white; StartCoroutine(showout()); } else { Hide(); } }
private void setInfo(GameObject ArObject, double lat, double longi) { // TODO: Guardar nombre, id, latitud, longitud MessageLocation messLoc = ArObject.GetComponent <MessageLocation>(); messLoc.Lat = lat; messLoc.Long = longi; messLoc.Message = "Escribir descripcion..."; messLoc.latitud.text = messLoc.Lat.ToString(); messLoc.longitud.text = messLoc.Long.ToString(); messLoc.setDescription(messLoc.Message); // Agregar a la lista ARObject baseClassAR = (ARObject)messLoc; addToList(messLoc); }
private void showImagePanel() { checkIfSwiped(); imagePanel.GetComponentInChildren <Image>().sprite = m_selectedObject.m_images[imageIndex]; imagePanel.gameObject.SetActive(true); Rect backFromImage = new Rect(0, 0, 400, 150); if (GUI.Button(backFromImage, "<size=50>back</size>")) { imagePanel.gameObject.SetActive(false); stationPanel.gameObject.SetActive(false); m_selectedObject = null; m_selectedRect = new Rect(); } else { //m_selectedRect = backFromImage; } }
/// <summary> /// Unity Update function. /// /// Mainly handle the touch event and place mark in place. /// </summary> public void Update() { if (m_saveThread != null && m_saveThread.ThreadState != ThreadState.Running) { // After saving an Area Description or mark data, we reload the scene to restart the game. _UpdateMarkersForLoopClosures(); _SaveObjectToDisk(); #pragma warning disable 618 Application.LoadLevel(Application.loadedLevel); #pragma warning restore 618 } if (Input.GetKey(KeyCode.Escape)) { #pragma warning disable 618 Application.LoadLevel(Application.loadedLevel); #pragma warning restore 618 } if (!m_initialized) { return; } if (EventSystem.current.IsPointerOverGameObject(0) || GUIUtility.hotControl != 0) { return; } if (Input.touchCount == 1) { Touch t = Input.GetTouch(0); Vector2 guiPosition = new Vector2(t.position.x, Screen.height - t.position.y); Camera cam = Camera.main; RaycastHit hitInfo; if (t.phase != TouchPhase.Began) { return; } if (m_selectedRect.Contains(guiPosition)) { // do nothing, the button will handle it } else if (Physics.Raycast(cam.ScreenPointToRay(t.position), out hitInfo)) { // Found a marker, select it (so long as it isn't disappearing)! GameObject tapped = hitInfo.collider.gameObject; m_selectedObject = tapped.GetComponent <ARObject>(); if (!tapped.GetComponent <Animation>().isPlaying) { m_selectedObject = tapped.GetComponent <ARObject>(); } } else if (admin) { // Place a new point at that location, clear selection m_selectedObject = null; StartCoroutine(_WaitForDepthAndFindPlane(t.position)); // Because we may wait a small amount of time, this is a good place to play a small // animation so the user knows that their input was received. //RectTransform touchEffectRectTransform = Instantiate(m_prefabTouchEffect) as RectTransform; // touchEffectRectTransform.transform.SetParent(m_canvas.transform, false); Vector2 normalizedPosition = t.position; normalizedPosition.x /= Screen.width; normalizedPosition.y /= Screen.height; // touchEffectRectTransform.anchorMin = touchEffectRectTransform.anchorMax = normalizedPosition; } } }
private void Awake() { arObject = GetComponent <ARObject>(); }
void SelectObject(ARObject obj) { contextMenu.SelectObject(obj); }
/// <summary> /// Wait for the next depth update, then find the plane at the touch position. /// </summary> /// <returns>Coroutine IEnumerator.</returns> /// <param name="touchPosition">Touch position to find a plane at.</param> private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition) { // MobileNativeMessage msg = new MobileNativeMessage("Test", "should place object"); m_findPlaneWaitingForDepth = true; // Turn on the camera and wait for a single depth update. m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM); while (m_findPlaneWaitingForDepth) { yield return(null); } m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED); // Find the plane. Camera cam = Camera.main; Vector3 planeCenter; Plane plane; if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane)) { yield break; } // Ensure the location is always facing the camera. This is like a LookRotation, but for the Y axis. Vector3 up = plane.normal; Vector3 forward; if (Vector3.Angle(plane.normal, cam.transform.forward) < 175) { Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized; forward = Vector3.Cross(right, up).normalized; } else { // Normal is nearly parallel to camera look direction, the cross product would have too much // floating point error in it. forward = Vector3.Cross(up, cam.transform.right); } // Instantiate object. newObject = Instantiate(m_currentObject, planeCenter, Quaternion.LookRotation(up)); newObject.transform.Rotate(m_currentObject.transform.rotation.eulerAngles); ARObject objectScript = newObject.GetComponent <ARObject>(); objectScript.m_type = m_currentObject.GetComponent <ARObject>().m_type; objectScript.m_timestamp = (float)m_poseController.m_poseTimestamp; Matrix4x4 uwTDevice = Matrix4x4.TRS(m_poseController.m_tangoPosition, m_poseController.m_tangoRotation, Vector3.one); Matrix4x4 uwTObject = Matrix4x4.TRS(newObject.transform.position, newObject.transform.rotation, Vector3.one); objectScript.m_deviceTObject = Matrix4x4.Inverse(uwTDevice) * uwTObject; m_objectList.Add(newObject); m_selectedObject = null; }
public void Dismiss() { currentObject = null; RemoveWidgets(); gameObject.SetActive(false); }
/// <summary> /// Unity OnGUI function. /// /// Mainly for removing markers. /// </summary> public void OnGUI() { if (m_selectedObject != null && admin) { Renderer selectedRenderer = m_selectedObject.GetComponent <Renderer>(); // GUI's Y is flipped from the mouse's Y Rect screenRect = _WorldBoundsToScreen(Camera.main, selectedRenderer.bounds); float yMin = Screen.height - screenRect.yMin; float yMax = Screen.height - screenRect.yMax; screenRect.yMin = Mathf.Min(yMin, yMax); screenRect.yMax = Mathf.Max(yMin, yMax); if (GUI.Button(screenRect, "<size=30>Remove</size>")) { m_objectList.Remove(m_selectedObject.gameObject); Destroy(m_selectedObject.gameObject); // m_selectedObject.SendMessage("Hide"); m_selectedObject = null; m_selectedRect = new Rect(); } else { m_selectedRect = screenRect; } } else { m_selectedRect = new Rect(); } #if UNITY_EDITOR // Handle text input when there is no device keyboard in the editor. if (m_displayGuiTextInput) { Rect textBoxRect = new Rect(100, Screen.height - 200, Screen.width - 200, 100); Rect okButtonRect = textBoxRect; okButtonRect.y += 100; okButtonRect.width /= 2; Rect cancelButtonRect = okButtonRect; cancelButtonRect.x = textBoxRect.center.x; GUI.SetNextControlName("TextField"); GUIStyle customTextFieldStyle = new GUIStyle(GUI.skin.textField); customTextFieldStyle.alignment = TextAnchor.MiddleCenter; m_guiTextInputContents = GUI.TextField(textBoxRect, m_guiTextInputContents, customTextFieldStyle); GUI.FocusControl("TextField"); if (GUI.Button(okButtonRect, "OK") || (Event.current.type == EventType.keyDown && Event.current.character == '\n')) { m_displayGuiTextInput = false; m_guiTextInputResult = true; } else if (GUI.Button(cancelButtonRect, "Cancel")) { m_displayGuiTextInput = false; m_guiTextInputResult = false; } } #endif }
public void SelectObject(ARObject obj) { objectNameLabel.text = obj.Title; currentObject = obj; gameObject.SetActive(true); }