Ejemplo n.º 1
0
    void UpdatePlacementPose()
    {
        var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        var hits         = new List <ARRaycastHit>();

        aRRaycastManager.Raycast(screenCenter, hits, TrackableType.Planes);

        placementPoseIsValid = hits.Count > 0;
        if (placementPoseIsValid)
        {
            PlacementPose = hits[0].pose;
        }
    }
Ejemplo n.º 2
0
        // Update is called once per frame
        void Update()
        {
            if (Input.touchCount > 0)
            {
                Touch   touch = Input.GetTouch(0);
                Vector2 tPos  = touch.position;

                if (touch.phase == TouchPhase.Began)
                {
                    Ray ray = arcamera.ScreenPointToRay(tPos);
                    if (Physics.Raycast(ray, out RaycastHit hit))
                    {
                        //Destroy(hit.transform.gameObject);

                        ISelectableObject selected = hit.transform.gameObject.GetComponent <ISelectableObject>();

                        if (selected != null)
                        {
                            if (selected.IsSelected == false)
                            {
                                selected.OnSelectEnter();
                            }
                            else
                            {
                                selected.OnSelectExit();
                            }

                            selected.IsSelected = !selected.IsSelected;
                        }
                    }
                }

                List <ARRaycastHit> hits = new List <ARRaycastHit>();
                if (raycastManager.Raycast(tPos, hits, TrackableType.PlaneWithinPolygon))
                {
                    Pose pose = hits[0].pose;

                    if (placed == null)
                    {
                        placed = Instantiate(player);
                        placed = Instantiate(level, pose.position, Quaternion.identity);

                        planeManager.planePrefab = null;
                        foreach (var plane in planeManager.trackables)
                        {
                            plane.gameObject.SetActive(false);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
    public void Update()
    {
        if (Input.touchCount > 0)
        {
            bool    last          = false;
            var     index         = -1;
            Vector2 touchPosition = Input.GetTouch(0).position;

            if (m_RaycastManager.Raycast(touchPosition, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                // Raycast hits are sorted by distance, so the first one
                // will be the closest hit.
                var hitPose = s_Hits[0].pose;



                for (var i = 0; i < objects.Count; i++)
                {
                    var obj = objects[i];
                    var dif = hitPose.position - obj.transform.position;
                    if (dif.x < 0.1 && dif.y < 0.1 && dif.z < 0.1)
                    {
                        last  = true;
                        index = i;
                        break;
                    }
                }

                if (last && index != -1)
                {
                    var touchObj = objects[index];
                    index = -1;
                    touchObj.transform.position = hitPose.position;

                    text.text = touchObj.transform.position.ToString();
                    dedo.text = "same";
                }
                else
                {
                    Vector3 cubePosition = hitPose.position + new Vector3(0, 1, 0);
                    spawnedObject = Instantiate(square, cubePosition, hitPose.rotation);
                    var cubeRenderer = spawnedObject.GetComponent <Renderer>();

                    //Call SetColor using the shader property name "_Color" and setting the color to red
                    cubeRenderer.material.SetColor("_Color", Random.ColorHSV());
                    objects.Add(spawnedObject);
                    text.text = spawnedObject.transform.position.ToString();
                }
            }
        }
    }
        void Update()
        {
            if (this.is_pc)
            {
                this.AddMissileAt(new Pose(Vector3.zero, Quaternion.identity));
                this.camera.transform.position = this.camera.transform.position - new Vector3(0, 0, 2);

                this.is_pc = false;
            }

            if (Input.touchCount > 0)
            {
                Touch touch = Input.GetTouch(0);

                if (touch.phase == TouchPhase.Began)
                {
                    if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
                    {
                        Pose hitPose = s_Hits[0].pose;
                        this.AddMissileAt(hitPose);
                    }
                }
            }

            // Debug.Log("Camera: " + this.camera.transform.position.ToString());

            GameObject deletedGO = null;

            foreach (GameObject go in this.placedObjects)
            {
                // go.transform.position = Vector3.MoveTowards(go.transform.position, this.camera.transform.position, 0.005f);

                //Debug.Log(go.transform.position.ToString());

                if (Vector3.Distance(go.transform.position, this.camera.transform.position) < 0.1)
                {
                    deletedGO = go;
                }
            }

            if (deletedGO != null)
            {
                this.placedObjects.Remove(deletedGO);
                Destroy(deletedGO);
                Debug.Log("HIT");
                Handheld.Vibrate();

                this.drinkText.SetActive(true);
                Invoke("HideDrinkText", 0.5f);
            }
        }
Ejemplo n.º 5
0
    void Update()
    {
        Text.GetComponent <Text>().text = text;
        List <ARRaycastHit> hits = new List <ARRaycastHit>();

        if (!placeObject)
        {
            // Shoot a raycast from the center of the screen
            rayManager.Raycast(new Vector2(Screen.width / 2, Screen.height / 2),
                               hits,
                               TrackableType.Planes
                               );

            // Hide the gameobject in the hierarchy and show the placement indicator
            SetActiveList(HideAfterClick, true);
            SetActiveList(HideBeforeClick, false);
        }
        else
        {
            // Activate the gameobject we want to display in the hierarchy
            // and hide the placement indicator
            SetActiveList(HideAfterClick, false);
            SetActiveList(HideBeforeClick, true);
        }

        // If we hit an AR plane surface, update the position and rotation
        if (hits.Count > 0)
        {
            transform.position = hits[0].pose.position;
            transform.rotation = hits[0].pose.rotation;
        }

        if (Input.GetMouseButtonDown(0))
        {
            text = "Clicked" + '\n';

            // Create a ray from mouse/touch position
            Ray        ray = ARCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                // Display selected gameobject tag and the impact position
                text += "Tag: " + hit.transform.tag + '\n';
                text += string.Format("{0}, {1}, {2}",
                                      hit.point.x,
                                      hit.point.y,
                                      hit.point.z
                                      );
            }
        }
    }
Ejemplo n.º 6
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && followPathBool == 0)
        {
            List <ARRaycastHit> hits = new List <ARRaycastHit>();
            if (arRaycaster.Raycast(Input.mousePosition, hits, TrackableType.Planes))
            {
                Pose hitPose = hits[0].pose;
                hitArr[i] = hitPose.position;
                var go = GameObject.Instantiate(arrowGameObject, hitPose.position, Quaternion.identity);
                gameArray[i] = go;
                i++;
            }
        }

        if (followPathBool == 1)
        {
            float step = speed * Time.deltaTime;

            if (k < len)
            {
                if (0.02 >= Vector3.Distance(travellingSalesman.transform.position, hitArr[k]))
                {
                    travellingSalesman.transform.position = hitArr[k];
                }
                else
                {
                    travellingSalesman.transform.position = Vector3.MoveTowards(travellingSalesman.transform.position, hitArr[k], step);
                }

                if (travellingSalesman.transform.position == hitArr[k])
                {
                    Vector3    relativePos = hitArr[k + 1] - travellingSalesman.transform.position;
                    Quaternion rotation    = Quaternion.LookRotation(relativePos, Vector3.up);
                    travellingSalesman.transform.rotation = rotation;
                    Destroy(gameArray[k]);
                    k++;
                }
            }

            if (k == len)
            {
                followPathBool = 0;
                Destroy(travellingSalesman);                 // delete the instance

                reset();

                rabitVisible = false;                 // reset visibility to initial state
            }
        }
    }
Ejemplo n.º 7
0
    void Update()
    {
        // do not capture events unless the welcome panel is hidden
        if (welcomePanel.activeSelf)
        {
            return;
        }

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            touchPosition = touch.position;

            if (touch.phase == TouchPhase.Began)
            {
                Ray        ray = arCamera.ScreenPointToRay(touch.position);
                RaycastHit hitObject;
                if (Physics.Raycast(ray, out hitObject))
                {
                    if (hitObject.transform.name.Contains("PlacedObject"))
                    {
                        onTouchHold = true;
                    }
                }
            }

            if (touch.phase == TouchPhase.Ended)
            {
                onTouchHold = false;
            }
        }

        if (arRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon))
        {
            Pose hitPose = hits[0].pose;

            if (placedObject == null)
            {
                placedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
            }
            else
            {
                if (onTouchHold)
                {
                    placedObject.transform.position = hitPose.position;
                    placedObject.transform.rotation = hitPose.rotation;
                }
            }
        }
    }
Ejemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (planeSelected)
        {
            return;
        }

        if (Input.touchCount <= 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        //Debug.Log("Detected Touch");
        if (arRaycastManager.Raycast(touch.position, m_Hits))
        {
            //Debug.Log("Hit Something");
            ARRaycastHit hit = m_Hits[0];
            if ((hit.hitType & TrackableType.PlaneWithinPolygon) != 0)
            {
                Debug.Log("First hit was plane");
                plane = arPlaneManager.GetPlane(hit.trackableId);

                foreach (ARPlane onPlane in arPlaneManager.trackables)
                {
                    if (onPlane != plane)
                    {
                        Debug.Log("Removing secondary plane");
                        onPlane.gameObject.SetActive(false);
                    }
                }

                planeSelected = true;

                LineRenderer lineRenderer = plane.gameObject.GetComponent <LineRenderer>();

                Debug.Log(lineRenderer);

                lineRenderer.material   = new Material(Shader.Find("Sprites/Default"));
                lineRenderer.startColor = Color.green;
                lineRenderer.endColor   = Color.green;

                Debug.Log("Updated Line render");

                arPlaneManager.enabled = false;
                uiManager.PlaneSelected(plane);
            }
        }
    }
Ejemplo n.º 9
0
    void Update()
    {
        if (m_RaycastManager.Raycast(Input.GetTouch(0).position, s_Hits, TrackableType.PlaneWithinPolygon))
        {
            // Raycast hits are sorted by distance, so the first one
            // will be the closest hit.
            var hitPose = s_Hits[0].pose;

            if (spawnedObject == null)
            {
                spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
            }
            else
            {
                //spawnedObject.transform.position = hitPose.position;
                //Vector3.MoveTowards(spawnedObject.transform.position, hitPose.position, 2f*Time.deltaTime);
            }
        }

        if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began))
        {
            Ray        raycast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit raycastHit;
            if (Physics.Raycast(raycast, out raycastHit))
            {
                Debug.Log("Something Hit");
                if (raycastHit.collider.CompareTag("Bot"))
                {
                    raycastHit.collider.GetComponent <Renderer>().material.color = Color.green;
                }
                else
                {
                    spawnedObject.GetComponent <Renderer>().material.color = Color.green;
                }
            }
            if (GameObject.FindGameObjectWithTag("Ball") == null)
            {
                ballObject = Instantiate(myBall, Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Quaternion.identity) as GameObject;

                ballObject.GetComponent <Rigidbody>().AddForce(Camera.main.transform.forward * 10f, ForceMode.Impulse);
            }
        }

        //if(ballObject != null)
        //{
        //    spawnedObject.transform.position = Vector3.MoveTowards(spawnedObject.transform.position, new Vector3(ballObject.transform.position.x, spawnedObject.transform.position.y, spawnedObject.transform.position.z), 10f * Time.deltaTime);
        //    Destroy(ballObject, 1.0f);

        //}
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (!TryGetTouchPosition(out Vector2 touchPosition))
        {
            return;
        }

        if (arRaycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))
        {
            var hitPose = hits[0].pose;

            Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
        }
    }
Ejemplo n.º 11
0
    void UpdatePlacementIndicator()
    {
        Vector3 centerScreen = mainCam.ViewportToScreenPoint(Vector2.one * 0.5f);

        hits.Clear();
        arRayManager.Raycast(centerScreen, hits, UnityEngine.XR.ARSubsystems.TrackableType.Planes);

        isValidGround = hits.Count > 0;

        if (isValidGround)
        {
            placementPose = hits[0].pose;
        }
    }
Ejemplo n.º 12
0
    void Update()
    {
        if (!TryGetTTouchPosition(out Vector2 touchPosition))
        {
            return;
        }

        if (arRaycastMenager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon))
        {
            var hitPose = hits[0].pose;

            Instantiate(Clabs, hitPose.position, hitPose.rotation);
        }
    }
Ejemplo n.º 13
0
    void Update()
    {
        if (!TryGetTouchPosition(out touchPosition))
        {
            return;
        }

        if (arRaycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))
        {
            var hitPose = hits[0].pose;

            portalScenario.CreatePortal(hitPose.position, hitPose.up, Vector3.up);
        }
    }
Ejemplo n.º 14
0
    private void UpdatePlacementPose()
    {
        var screenCenter = mainCam.ViewportToScreenPoint(new Vector3(.5f, .5f));
        var hits         = new List <ARRaycastHit>();

        rcManager.Raycast(screenCenter, hits, TrackableType.Planes);

        placementPoseIsValid = hits.Count > 0;

        if (placementPoseIsValid)
        {
            placementPose = hits[0].pose;
        }
    }
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        Vector3 centerOfScreen = new Vector3(Screen.width / 2, Screen.height / 2);
        Ray     ray            = aRCamera.ScreenPointToRay(centerOfScreen);

        if (m_ARRaycastManager.Raycast(ray, raycast_Hits, TrackableType.PlaneWithinPolygon))
        {
            //Intersection
            Pose    hitPose            = raycast_Hits[0].pose;
            Vector3 positionToBePlaced = hitPose.position;

            battleArenaGameObject.transform.position = positionToBePlaced;
        }
    }
        private void UpdatePlacementPose()
        {
            Ray screenCenter = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));

            aRRaycastManager.Raycast(screenCenter, hits, TrackableType.PlaneWithinPolygon);
            placementPoseIsValid = hits.Count > 0;
            if (placementPoseIsValid)
            {
                placementPose = hits[0].pose;
                Vector3 cameraForward = Camera.main.transform.forward;
                Vector3 cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
                placementPose.rotation = Quaternion.LookRotation(cameraBearing);
            }
        }
Ejemplo n.º 17
0
 void Update()
 {
     // detect a touch on the screen
     if (Input.touchCount > 0)
     {
         // save the position of the touch on the screen
         Vector2 touchPosition = Input.GetTouch(0).position;
         if (raycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))
         {
             var        hitPose       = hits[0].pose;
             GameObject spawnedPrefab = Instantiate(prefab, hitPose.position, prefab.transform.rotation);
         }
     }
 }
Ejemplo n.º 18
0
    // Update is called once per frame
    void Update()
    {
#if !Unity_Engine
        Vector3 center = Camera.main.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, 0));

        List <ARRaycastHit> validHits = new List <ARRaycastHit>();
        arOrigin.Raycast(center, validHits, surfaceToDetect);
        if (validHits.Count > 0)
        {
            gameObject.transform.position = validHits[0].pose.position;
            gameObject.transform.rotation = validHits[0].pose.rotation;
        }
#endif
    }
Ejemplo n.º 19
0
    private void UpdatePlacementPose()
    {
        var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, 0f));
        var hits         = new List <ARRaycastHit>();

        arOrigin.Raycast(screenCenter, hits, TrackableType.Planes);

        placementIsGood = hits.Count > 0;
        if (placementIsGood)
        {
            placementPose          = hits[0].pose;
            placementPose.rotation = Quaternion.LookRotation(new Vector3(Camera.current.transform.forward.x, 0, Camera.current.transform.forward.z).normalized);
        }
    }
Ejemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (m_ARRaycastManager.Raycast(touch.position, raycast_hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon))
            {
                //getting the pose
                Pose pose = raycast_hits[0].pose;
                LocationBasedARPrefeb.transform.position = pose.position;
            }
        }
    }
Ejemplo n.º 21
0
    public void zz()
    {
        var center = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));



        if (aRRaycast.Raycast(center, hits, TrackableType.Planes))
        {
            heightPose = hits[0].pose.position;
            if (ex == null)
            {
            }
        }
    }
Ejemplo n.º 22
0
 /// <summary>
 /// 點擊
 /// </summary>
 private void Tap()
 {
     // 判斷玩家是否點擊
     if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         pointMouse = Input.mousePosition;           // 滑鼠座標 = 玩家的滑鼠座標
         if (arManager.Raycast(pointMouse, hits, TrackableType.PlaneWithinPolygon))
         {
             Instantiate(OBJ, hits[0].pose.position, Quaternion.identity);
         }
     }
     // 判斷射線是否打到物件
     // 生成物件
 }
Ejemplo n.º 23
0
 private Vector3 RaycastHitPosition()
 {
     if (aRRaycastManager.Raycast(new Vector2(Screen.width / 2, Screen.height / 2), hits, TrackableType.PlaneWithinPolygon))
     {
         hitPose = hits[0].pose;
         raycastPositionText.text = hitPose.ToString();
         return(hitPose.position);
     }
     else
     {
         raycastPositionText.text = hitPose.ToString();
         return(hitPose.position);
     }
 }
Ejemplo n.º 24
0
    private void OnTouchInteractionEnded(Touch touch)
    {
#if UNITY_ANDROID || UNITY_IOS
        var arRaycastHits = new List <ARRaycastHit>();

        if (arRaycastManager.Raycast(touch.position, arRaycastHits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneEstimated) && arRaycastHits.Count > 0)
        {
            var hit = arRaycastHits[0];

            OnSelectObjectInteraction?.Invoke(hit.pose.position);
        }
#elif WINDOWS_UWP || UNITY_WSA
#endif
    }
Ejemplo n.º 25
0
    private void placeObjectByTouch()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            List <ARRaycastHit> hits = new List <ARRaycastHit>();

            if (arRaycaster.Raycast(touch.position, hits, TrackableType.Planes))
            {
                Pose hitPose = hits[0].pose;

                if (!spawnObject)
                {
                    spawnObject = Instantiate(placeObject, hitPose.position, hitPose.rotation);
                }
                else
                {
                    spawnObject.transform.position = hitPose.position;
                    spawnObject.transform.rotation = hitPose.rotation;
                }
            }
        }
    }
Ejemplo n.º 26
0
    void Update()
    {
        Ray ray = arCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));

        if (raycastManager.Raycast(ray, hitResults))
        {
            hitPose = hitResults[0].pose;
            isRaycastingToTrackable = true;
        }
        else
        {
            isRaycastingToTrackable = false;
        }
    }
Ejemplo n.º 27
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0) && !IsClickOverUI())
     {
         List <ARRaycastHit> hitPoints = new List <ARRaycastHit>();
         raycastManager.Raycast(Input.mousePosition, hitPoints, UnityEngine.XR.ARSubsystems.TrackableType.Planes);
         if (hitPoints.Count > 0)
         {
             Pose pose = hitPoints[0].pose;
             transform.rotation = pose.rotation;
             transform.position = pose.position;
         }
     }
 }
Ejemplo n.º 28
0
    // Update is called once per frame
    void Update()
    {
        Vector3 centerOfScreen = new Vector3(Screen.width / 2, Screen.height / 2);
        Ray     ray            = ARcamera.ScreenPointToRay(centerOfScreen); // this way we gert rays coming from center of screen

        if (m_ARrayRaycastManager.Raycast(ray, raycast_Hits, TrackableType.PlaneWithinPolygon))
        {
            // inside this means, a ray is sent and it intersects with the detected plane
            Pose hitPose = raycast_Hits[0].pose;

            Vector3 positionToBePlaced = hitPose.position;
            battleArenaGameobject.transform.position = positionToBePlaced;
        }
    }
Ejemplo n.º 29
0
    void Update()
    {
        planeManager.enabled = !planeManager.enabled;
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began && raycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon) && isInstantiated == false)
            {
                Pose pose = hits[0].pose;

                GameObject btnPrefab = null;

                if (currValue == ButtonValue.Rain)
                {
                    btnPrefab = RainPrefab;
                }
                else if (currValue == ButtonValue.Blizzard)
                {
                    btnPrefab = BlizzardPrefab;
                }
                else if (currValue == ButtonValue.Fire)
                {
                    btnPrefab = FirePrefab;
                }
                else if (currValue == ButtonValue.Tornado)
                {
                    btnPrefab = TornadoPrefab;
                }
                else if (currValue == ButtonValue.Meteor)
                {
                    btnPrefab = MeteorPrefab;
                }
                else if (currValue == ButtonValue.Tsunami)
                {
                    btnPrefab = TsunamiPrefab;
                }
                else if (currValue == ButtonValue.Plague)
                {
                    btnPrefab = PlaguePrefab;
                }

                var go = Instantiate(btnPrefab, pose.position, pose.rotation);
                sessionOrigin.MakeContentAppearAt(go.transform, go.transform.position, go.transform.rotation);
                isInstantiated     = true;
                audioSource.volume = 0.1f;
                SetAllPlanesActive(false);
                StartCoroutine(OnDestroyPrefab(go));
            }
        }
    }
Ejemplo n.º 30
0
    void Update()
    {
        // shooting AR raycast from the center of the screen
        List <ARRaycastHit> hits = new List <ARRaycastHit>(); // 레이캐스트 히트를 리스트로 생성

        rayManager.Raycast(new Vector2(Screen.width / 2, Screen.height / 2), hits, TrackableType.Planes);

        // if we hit an AR plane , update the position and rotation
        if (hits.Count > 0) // 레이캐스트가 평면에 부딛히면 부딛힌 갯수만큼 카운트해서 값을 넘겨줌 ( 안부딛히면 null값 반환 )
        {
            transform.position = hits[0].pose.position;
            transform.rotation = hits[0].pose.rotation;
        }
    }