private new void Update() { // If the player has not touched the screen, we are done with this update. Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } // Should not handle input if the player is pointing on UI. if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { return; } // Ray cast against the location the player touched to search for planes. const TrackableHitFlags hitFlags = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, hitFlags, out TrackableHit hit)) { // Use hit pose and camera pose to check if hit test is from the // back of the plane, if it is, no need to create the anchor. if ((hit.Trackable is DetectedPlane) && Vector3.Dot(firstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("Hit at back of the current DetectedPlane"); } else { // Verify if any product as been selected. if (!CollectionManager.Instance.activeProduct) { return; } // Only 1 object at the time if (m_InstantiatedModel != null) { Destroy(m_InstantiatedModel.transform.parent.gameObject); ManipulationSystem.Instance.SelectedObject = null; } GameObject model = CollectionManager.Instance.activeProduct; // Instantiate window model at the hit pose. var windowObject = Instantiate(model, hit.Pose.position, hit.Pose.rotation); // Instantiate manipulator. var manipulator = Instantiate(manipulatorCatalogWindow, hit.Pose.position, hit.Pose.rotation); // Make window model a child of the manipulator. windowObject.transform.parent = manipulator.transform; // Create an anchor to allow ARCore to track the hit point as understanding of // the physical world evolves. var anchor = hit.Trackable.CreateAnchor(hit.Pose); // Make manipulator a child of the anchor. manipulator.transform.parent = anchor.transform; // Select the placed object. manipulator.GetComponent <Manipulator>().Select(); // Add to List m_InstantiatedModel = windowObject; // Set active product to null ( prevent over usage of models ) CollectionManager.Instance.activeProduct = null; // Create windows if (windowObject.GetComponent <ModelConfigurator>()) { // Open Configurator GUI UiManager.Instance.appHud.Set_Configurator(windowObject.GetComponent <ModelConfigurator>()); // List of the windows in the object List <Window> windows = windowObject.GetComponent <ModelConfigurator>().Windows; for (int i = 0; i < windows.Count; i++) { // Create example of a window GameObject window = windows[i].gameObject; // Instantiate inside window model at the hit pose. var insideWindowObject = Instantiate(window, hit.Pose.position, hit.Pose.rotation); // Instantiate manipulator. Vector3 manipulatorPos = window.transform.position; var windowManipulator = Instantiate(manipulatorInnerWindow, manipulatorPos, hit.Pose.rotation); // Add the WindowLimiter Script windowManipulator.AddComponent <WindowMovementLimiter>(); WindowMovementLimiter wml = windowManipulator.GetComponent <WindowMovementLimiter>(); switch (windows.Count) { case 2: wml.SetDistances(i, -0.5f, +0.5f); break; case 3: switch (i) { case 0: wml.SetDistances(i, -1.0f, -1.0f); break; case 1: wml.SetDistances(i, -1.0f, +0.0f); break; case 2: wml.SetDistances(i, -1.0f, +1.0f); break; default: break; } break; case 4: switch (i) { case 0: wml.SetDistances(i, -1.5f, -1.5f); break; case 1: wml.SetDistances(i, -1.5f, -0.5f); break; case 2: wml.SetDistances(i, -1.5f, +0.5f); break; case 3: wml.SetDistances(i, -1.5f, +1.5f); break; default: break; } break; default: break; } // Make window element position go back to normal insideWindowObject.transform.Find("Elements").localPosition = window.transform.Find("Elements").localPosition; // Make window model a child of the manipulator insideWindowObject.transform.parent = windowManipulator.transform; // Make manipulator a child of the anchor. windowManipulator.transform.parent = windowObject.transform; // Show new Windows insideWindowObject.SetActive(true); // Hide old windows window.SetActive(false); // Connect new windows to ModelConfigurator windowObject.GetComponent <ModelConfigurator>().Windows[i] = insideWindowObject.GetComponent <Window>(); } } else if (windowObject.GetComponent <ModelConfiguratorBiCorner>()) { // Open Configurator GUI UiManager.Instance.appHud.Set_Configurator(windowObject.GetComponent <ModelConfiguratorBiCorner>().Sides[0]); foreach (ModelConfigurator m in windowObject.GetComponent <ModelConfiguratorBiCorner>().Sides) { for (int i = 0; i < m.Windows.Count; i++) { // Create example of a window GameObject window = m.Windows[i].gameObject; // Instantiate inside window model at the hit pose. var insideWindowObject = Instantiate(window, hit.Pose.position, hit.Pose.rotation); // Instantiate manipulator. Vector3 manipulatorPos = window.transform.position; var windowManipulator = Instantiate(manipulatorInnerWindow, manipulatorPos, hit.Pose.rotation); // Add Window limiter to inner windows windowManipulator.AddComponent <WindowMovementLimiter>(); WindowMovementLimiter wml = windowManipulator.GetComponent <WindowMovementLimiter>(); if (m == windowObject.GetComponent <ModelConfiguratorBiCorner>().Sides[0]) { if (i == 0) { wml.SetDistances(i, -0.5f, -0.5f); } else { wml.SetDistances(i, -0.5f, +0.5f); } } else if (i == 0) { wml.SetDistances(i, -0.5f, +0.5f); } else { wml.SetDistances(i, +0.5f, +0.5f); } // Make window element position go back to normal insideWindowObject.transform.Find("Elements").localPosition = window.transform.Find("Elements").localPosition; // Make window model a child of the manipulator insideWindowObject.transform.parent = windowManipulator.transform; // Make manipulator a child of the anchor. windowManipulator.transform.parent = m.transform; // Show new Windows insideWindowObject.SetActive(true); // Hide old windows window.SetActive(false); if (m == windowObject.GetComponent <ModelConfiguratorBiCorner>().Sides[1]) { windowManipulator.transform.localEulerAngles = new Vector3(0, 0, 0);// = Quaternion.Euler(0, 0, 0); } // Connect new windows to ModelConfigurator m.GetComponent <ModelConfigurator>().Windows[i] = insideWindowObject.GetComponent <Window>(); } } } UiManager.Instance.appHud.Set_LockUnlockButton(true); ManipulationSystem.Instance.Select(manipulator); } } }
private void SetModelConfiguratorBiCorner(AugmentedImage image) { // Open Configurator GUI UiManager.Instance.appHud.Set_Configurator(m_Visualizer.GetComponent <ModelConfiguratorBiCorner>().Sides[0]); foreach (ModelConfigurator m in m_Visualizer.GetComponent <ModelConfiguratorBiCorner>().Sides) { for (int i = 0; i < m.Windows.Count; i++) { // Create example of a window GameObject window = m.Windows[i].gameObject; // Instantiate inside window model at the hit pose. var insideWindowObject = Instantiate(window, image.CenterPose.position, image.CenterPose.rotation); // Instantiate manipulator. Vector3 manipulatorPos = window.transform.position; var windowManipulator = Instantiate(manipulatorInnerWindow, manipulatorPos, image.CenterPose.rotation); // Add Window limiter to inner windows windowManipulator.AddComponent <WindowMovementLimiter>(); WindowMovementLimiter wml = windowManipulator.GetComponent <WindowMovementLimiter>(); if (m == m_Visualizer.GetComponent <ModelConfiguratorBiCorner>().Sides[0]) { if (i == 0) { wml.SetDistances(i, -0.5f, -0.5f); } else { wml.SetDistances(i, -0.5f, +0.5f); } } else if (i == 0) { wml.SetDistances(i, -0.5f, +0.5f); } else { wml.SetDistances(i, +0.5f, +0.5f); } // Make window element position go back to normal insideWindowObject.transform.Find("Elements").localPosition = window.transform.Find("Elements").localPosition; // Make window model a child of the manipulator insideWindowObject.transform.parent = windowManipulator.transform; // Make manipulator a child of the anchor. windowManipulator.transform.parent = m.transform; // Show new Windows insideWindowObject.SetActive(true); // Hide old windows window.SetActive(false); if (m == m_Visualizer.GetComponent <ModelConfiguratorBiCorner>().Sides[1]) { windowManipulator.transform.localEulerAngles = new Vector3(0, 0, 0); // = Quaternion.Euler(0, 0, 0); } // Connect new windows to ModelConfigurator m.GetComponent <ModelConfigurator>().Windows[i] = insideWindowObject.GetComponent <Window>(); } } }