Пример #1
0
    private void InstantiateSelectable(Vector3 pos, Quaternion rot)
    {
        //ARSelectable ars = _Selectables[_selectablesMap[GameGlobals.CurrentDrawingSelection]];
        ARSelectable newARS =
            GameObject.Instantiate(_Selectables[_selectablesMap[GameGlobals.CurrentDrawingSelection]], pos, rot) as ARSelectable;

        //Debug.Log(newARS.GetType().ToString());
        if (newARS._Projectile)
        {
            newARS.transform.position =
                Camera.main.transform.position - (Camera.main.transform.up * newARS.transform.localScale.y);
            newARS.transform.GetComponent <Rigidbody>().velocity =
                (Camera.main.transform.forward * forwardVelocity) + (Camera.main.transform.up * forwardVelocity / 2);
        }
    }
Пример #2
0
    /// <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)
    {
        //Debug.Log("Waiting for new depth------------------------------");
        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);
        //Debug.Log("------------------------------New depth available!");
        // 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);
        }

        InstantiateSelectable(planeCenter, Quaternion.LookRotation(forward, up));
        m_selectedPrefab = null;
    }
Пример #3
0
    /// <summary>
    /// Update location marker state.
    /// </summary>
    private void _UpdateLocationMarker()
    {
        if (Input.touchCount == 2)
        {
            return;
        }

        if (Input.touchCount == 1 || Input.GetMouseButtonDown(1))
        {
            // Single tap -- place new location or select existing location.

            Vector2 pos = new Vector2();
            if (Input.touchCount == 1)
            {
                Touch t = Input.GetTouch(0);
                pos = t.position;
                if (t.phase != TouchPhase.Began ||
                    UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(t.fingerId))
                {
                    return;
                }
            }
            else
            {
                if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
                {
                    return;
                }
                pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            }

            if (GameGlobals.PropertiesPanelOpen)
            {
                GameGlobals.SetPropertiesOpen(false);
                return;
            }

            Vector2    guiPosition = new Vector2(pos.x, Screen.height - pos.y);
            Camera     cam         = Camera.main;
            RaycastHit hitInfo;

            if (m_selectedRect.Contains(guiPosition) || m_hideAllRect.Contains(guiPosition))
            {
                // do nothing, the button will handle it
            }
            else if (Physics.Raycast(cam.ScreenPointToRay(pos), out hitInfo, 10, 1 << _PrefabObjLayer))
            {
                // Found a prefab, select it (so long as it isn't disappearing)!
                GameObject tapped = hitInfo.collider.transform.root.gameObject;
                //Debug.Log(tapped.name + " tapped!");
                m_selectedPrefab = tapped.GetComponent <ARSelectable>();
                m_selectedPrefab.MakeSelected();

                //if (!tapped.GetComponent<Animation>().isPlaying)
                //{
                //    m_selectedPrefab = tapped.GetComponent<PrefabObject>();
                //}
            }
            else
            {
                // Place a new point at that location, clear selection
                m_selectedPrefab = null;
                GameGlobals.ChangeSelected(Enums.SelectionType.NONE);

                StartCoroutine(_WaitForDepthAndFindPlane(pos));

                // 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 = (RectTransform)Instantiate(m_prefabTouchEffect);
                touchEffectRectTransform.transform.SetParent(m_canvas.transform, false);
                Vector2 normalizedPosition = pos;
                normalizedPosition.x /= Screen.width;
                normalizedPosition.y /= Screen.height;
                touchEffectRectTransform.anchorMin = touchEffectRectTransform.anchorMax = normalizedPosition;
            }
        }
    }