void AddWall(GameObject gObj, Vector3Int pos, Transform parent, FaceToward face = FaceToward.S) { var go = Instantiate(gObj, parent); go.transform.localPosition = new Vector3(pos.x * tileSize, pos.y * tileSize, pos.z * tileSize); AdjFace(go.transform, face); }
static public void AdjFace2(Transform tran, FaceToward face = FaceToward.N) { switch (face) { case FaceToward.N: tran.Translate(Vector3.right * tileSize / 2); tran.Translate(Vector3.back * tileSize / 2); break; case FaceToward.S: tran.Translate(Vector3.left * tileSize / 2); tran.Translate(Vector3.forward * tileSize / 2); tran.Rotate(new Vector3(0, 180, 0)); break; case FaceToward.E: tran.Translate(Vector3.left * tileSize / 2); tran.Translate(Vector3.back * tileSize / 2); tran.Rotate(new Vector3(0, 90, 0)); break; case FaceToward.W: tran.Translate(Vector3.right * tileSize / 2); tran.Translate(Vector3.forward * tileSize / 2); tran.Rotate(new Vector3(0, -90, 0)); break; } }
public Vector3Int AddCorridor(Vector3Int pos, int width = 0, int length = 3, FaceToward face = FaceToward.S) { var corridorRoot = ObjBuilder.AddNode("Corridor", dungeonRoot, new Vector3Int((int)(pos.x), (int)(pos.z), (int)(pos.y))); var floorRoot = ObjBuilder.AddNode("Floor", corridorRoot); for (int row = 0; row < length; row++) { for (int col = -width; col <= width; col++) { AddFloor(new Vector3(col, 0, row), floorRoot); } } var wallRoot = ObjBuilder.AddNode("Wall", corridorRoot); for (int i = 0; i < length; i++) { AddWall(wallPrefab, new Vector3Int(-width, 0, i), wallRoot, FaceToward.E); AddWall(wallPrefab, new Vector3Int(width + 1, 0, i), wallRoot, FaceToward.W); } ObjBuilder.AdjFace(corridorRoot, face); switch (face) { case ObjBuilder.FaceToward.S: return(pos + Vector3Int.down * length); case ObjBuilder.FaceToward.N: return(pos + Vector3Int.up * length); case ObjBuilder.FaceToward.E: return(pos + Vector3Int.right * length); case ObjBuilder.FaceToward.W: return(pos + Vector3Int.left * length); } return(pos); }
void AddMisc(GameObject gObj, Vector3Int pos, Transform parent, FaceToward face = FaceToward.S) { var go = Instantiate(gObj, parent); go.transform.localPosition = new Vector3(pos.x * tileSize, pos.z * tileSize, pos.y * tileSize) + new Vector3(tileSize / 2, 0, tileSize / 2); go.transform.rotation = Quaternion.Euler(new Vector3(0, Random.Range(0, 180f), 0)); AdjFace(go.transform, face); }
private void PlaneHit(Transform hitTransform) { Debug.Log("Set facing"); WorldRoot.transform.position = hitTransform.position; FaceToward.SetFacing(WorldRoot.transform, cameraTransform.position); WorldRoot.transform.SetParent(hitTransform); // Should look at the camera but still be flush with the plane. WorldRoot.transform.LookAt(cameraTransform); WorldRoot.transform.rotation = Quaternion.Euler(0.0f, WorldRoot.transform.rotation.eulerAngles.y, WorldRoot.transform.rotation.z); }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { if (!string.IsNullOrEmpty(this.m_AnchorId)) { UnityARSessionNativeInterface.GetARSessionNativeInterface().RemoveUserAnchor(this.m_AnchorId); } m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = Quaternion.identity; // UnityARMatrixOps.GetRotation (hitResult.worldTransform); FaceToward.SetFacing(m_HitTransform, Camera.main.transform.position); m_PlaneTapped.Invoke(); m_AnchorId = UnityARSessionNativeInterface.GetARSessionNativeInterface().AddUserAnchorFromGameObject(m_HitTransform.gameObject).identifierStr; Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return(true); } } return(false); }
bool EditorHitTest() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //we'll try to hit one of the plane collider gameobjects that were generated by the plugin //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent if (Physics.Raycast(ray, out hit)) { //we're going to get the position from the contact point m_HitTransform.position = hit.point; Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); //and the rotation from the transform of the plane collider m_HitTransform.rotation = hit.transform.rotation; FaceToward.SetFacing(m_HitTransform, Camera.main.transform.position); m_PlaneTapped.Invoke(); return(true); } } return(false); }
void Start() { FaceToward.SetFacing(m_HitTransform, Camera.main.transform.position); }
public void Update() { if (Session.ConnectionState != SessionConnectionState.Connected) { return; } // The tracking state must be FrameTrackingState.Tracking in order to access the Frame. if (Frame.TrackingState != FrameTrackingState.Tracking) { const int LOST_TRACKING_SLEEP_TIMEOUT = 15; Screen.sleepTimeout = LOST_TRACKING_SLEEP_TIMEOUT; return; } Screen.sleepTimeout = SleepTimeout.NeverSleep; Frame.GetNewPlanes(ref m_newPlanes); // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them. for (int i = 0; i < m_newPlanes.Count; i++) { // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to // the origin with an identity rotation since the mesh for our prefab is updated in Unity World // coordinates. GameObject planeObject = Instantiate(m_trackedPlanePrefab, Vector3.zero, Quaternion.identity, transform); planeObject.GetComponent <GoogleARCore.HelloAR.TrackedPlaneVisualizer>().SetTrackedPlane(m_newPlanes[i]); // Apply a random color and grid rotation. planeObject.GetComponent <Renderer>().material.SetColor("_GridColor", m_planeColors[Random.Range(0, m_planeColors.Length - 1)]); planeObject.GetComponent <Renderer>().material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f)); } Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } TrackableHit hit; TrackableHitFlag raycastFilter = TrackableHitFlag.PlaneWithinBounds | TrackableHitFlag.PlaneWithinPolygon; if (Session.Raycast(m_firstPersonCamera.ScreenPointToRay(touch.position), raycastFilter, out hit)) { Debug.Log("Hit: " + hit.Point); // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical // world evolves. var anchor = Session.CreateAnchor(hit.Point, Quaternion.identity); m_worldRoot.transform.position = hit.Point; FaceToward.SetFacing(m_worldRoot.transform, m_firstPersonCamera.transform.position); m_worldRoot.transform.parent = anchor.transform; // Andy should look at the camera but still be flush with the plane. m_worldRoot.transform.LookAt(m_firstPersonCamera.transform); m_worldRoot.transform.rotation = Quaternion.Euler(0.0f, m_worldRoot.transform.rotation.eulerAngles.y, m_worldRoot.transform.rotation.z); m_planeAttachment.Attach(hit.Plane); planeTapped.Invoke(); } }
public void Start() { m_planeAttachment = m_worldRoot.GetComponent <GoogleARCore.HelloAR.PlaneAttachment>(); FaceToward.SetFacing(m_worldRoot.transform, m_firstPersonCamera.transform.position); }