public void DampenMolPosForSurfaceCollisions(Vector3 directionToCheck, float yOffset)
    {
        RaycastHit info;

        Vector3[] raycastOrigins = new Vector3[5] {
            new Vector3(transform.position.x, transform.position.y + yOffset, transform.position.z),
            new Vector3(transform.position.x + moleculeBounds.extents.x, transform.position.y + yOffset, transform.position.z),
            new Vector3(transform.position.x - moleculeBounds.extents.x, transform.position.y + yOffset, transform.position.z),
            new Vector3(transform.position.x, transform.position.y + yOffset, transform.position.z + moleculeBounds.extents.z),
            new Vector3(transform.position.x, transform.position.y + yOffset, transform.position.z - moleculeBounds.extents.z)
        };

        foreach (Vector3 raycastOrigin in raycastOrigins)
        {
            if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + yOffset, transform.position.z), directionToCheck, out info))
            {
                if (info.collider.gameObject.name == "ChemViewSurface" && info.distance < 0.01f)
                {
                    NewMolPos = new Vector3(NewMolPos.x, transform.position.y, NewMolPos.z);
                    ChemviewHelper.ShowAndroidToastMessage("freezing y pos" + info.distance);
                }

                break;
            }
        }
    }
Example #2
0
    public void MoleculeClick(string molClicked)
    {
        GameObject newSelectedMol = molsList.Where(mol => mol.name == molClicked).FirstOrDefault();

        chemViewController.loadedChemModel = newSelectedMol;
        molListInfoSheet.SetMolSelectInfoSheet(chemViewController);
        ChemviewHelper.ShowAndroidToastMessage(molClicked + " set as spawnable molecule");
    }
    public void RotateLeftRight(float rotateLeftRight, float rotateUpDown)
    {
        float sensitivity = 35f;

        MolRelDirection molRelDirection = GetMolRelativeDirection();

        Quaternion rotateBy = Quaternion.AngleAxis(rotateLeftRight / gameObject.transform.parent.transform.localScale.x * sensitivity, molRelDirection.molRelUp)
                              * Quaternion.AngleAxis(-rotateUpDown / gameObject.transform.parent.transform.localScale.x * sensitivity, molRelDirection.molrelRight);


        _rotateBy = rotateBy;

        try
        {
            //molRigidBody.MoveRotation(rotateBy * transform.rotation);
            transform.Rotate(rotateBy.eulerAngles);
        }

        catch (Exception e)
        {
            ChemviewHelper.ShowAndroidToastMessage(e.ToString());
        }
        //TODO: Use rotation in fixed update to potentially solve jittery issues
    }
    public void Update()
    {
        _UpdateApplicationLifecycle();

        // Hide snackbar when currently tracking at least one plane.
        Session.GetTrackables <DetectedPlane>(m_AllPlanes);
        bool showSearchingUI = true;

        for (int i = 0; i < m_AllPlanes.Count; i++)
        {
            if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
            {
                showSearchingUI = false;
                break;
            }
        }


        if (showSearchingUI != uIController.SearchingForPlanes)
        {
            if (firstSurface == true)
            {
                ChemviewHelper.ShowAndroidToastMessage("Double tap on a surface to spawn a molecule");
                firstSurface = false;
            }

            uIController.SearchingForPlanes = showSearchingUI;
            SearchingForPlaneUI.GetComponent <SearchingForPlaneController>().MovePosition(showSearchingUI);

            if (showSearchingUI)
            {
                SearchingForPlaneUI.GetComponent <SearchingForPlaneController>().StartMessageCoroutine();
                uIController.FadeOut();
            }

            else
            {
                uIController.FadeIn();
            }
        }

        Touch touch;

        // If the player has not touched the screen, we are done with this update.
        if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
        {
            return;
        }


        if (touch.tapCount == 1 && UserRotating == false)
        {
            if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId))
            {
                Ray        raycast = FirstPersonCamera.ScreenPointToRay(touch.position);
                RaycastHit raycastHit;
                if (Physics.Raycast(raycast, out raycastHit))
                {
                    if (raycastHit.collider.tag == "Molecule" && UserRotating == false)
                    {
                        if (selectedMol == null)
                        {
                            selectedMol            = raycastHit.collider.GetComponentInChildren <MoleculeController>();
                            _lastSelectedMol       = selectedMol;
                            selectedMol.isSelected = true;
                            selectedMol.Highlight();
                            uIController.SetToggles(selectedMol);
                        }

                        else
                        {
                            if (selectedMol != raycastHit.collider.GetComponentInChildren <MoleculeController>())
                            {
                                selectedMol.Dehighlight();
                                UserRotating = false;
                                uIController.TurnOffToggles();

                                selectedMol            = raycastHit.collider.GetComponentInChildren <MoleculeController>();
                                _lastSelectedMol       = selectedMol;
                                selectedMol.isSelected = true;
                                selectedMol.Highlight();
                                uIController.SetToggles(selectedMol);
                            }
                        }
                    }
                }
                else
                {
                    if (selectedMol != null && UserRotating == false)
                    {
                        selectedMol.Dehighlight();
                        MoleculeController selectedMolScript = selectedMol.GetComponentInChildren <MoleculeController>();
                        selectedMolScript.isSelected = false;
                        selectedMol = null;
                        uIController.TurnOffToggles();
                        UserRotating = false;
                    }
                }
                return;
            }
        }

        if (touch.tapCount == 2)
        {
            if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId) && UserRotating == false)
            {
                SpawnMolecule();
                return;
            }
        }
    }