//-------------------------------------------------------------------------------------------------------------------------- // Collision Detection / Force Feedback // Called when this object enters the collider of another object protected virtual void OnTriggerEnter(Collider col) { SenseGlove_Interactable interact = col.attachedRigidbody != null?col.attachedRigidbody.GetComponent <SenseGlove_Interactable>() : col.GetComponent <SenseGlove_Interactable>(); if (interact != null) { interact.TouchedBy(this); if (this.touchedObject == null) { //if (!this.IsTouching(col.gameObject)) //{ // //touching a new object! //} this.touchedObject = interact.gameObject; this.touchedScript = interact; if (this.touchedObject.transform.parent != null) { if (this.touchedObject.transform.parent.name == "Tastatur" && this.name == "indexPickupCollider") { this.transform.root.GetComponent <SenseGlove_Object>().SendBuzzCmd(new bool[5] { false, true, false, false, false }, 100, 50); GlobalCtrl text = this.transform.root.GetComponent <GlobalCtrl>(); text.textChange(this.touchedObject); } else if (this.touchedObject.transform.parent.name == "GUILoad" && this.name == "indexPickupCollider") { this.transform.root.GetComponent <SenseGlove_Object>().SendBuzzCmd(new bool[5] { false, true, false, false, false }, 100, 50); if (this.touchedObject.name == "Down") { GlobalCtrl.updown += 1; } else if (this.touchedObject.name == "Up" && GlobalCtrl.updown >= 1) { GlobalCtrl.updown -= 1; } else if (this.touchedObject.name.StartsWith("Platz")) { List <atomData> loadFile = new List <atomData>(); loadFile = (List <atomData>)CFileHelper.LoadData(Application.dataPath + "/MoleculeFiles/" + touchedObject.transform.GetChild(0).GetComponent <Text>().text, typeof(List <atomData>)); this.transform.root.GetComponent <GlobalCtrl>().loadMolecule(loadFile); } else if (this.touchedObject.name == "ExitLoadGui") { GlobalCtrl.loadGUI = false; GameObject.Find("GUILoad").SetActive(false); molecule.SetActive(true); } } } } } }
private void Update() { if (!isActive) { isActive = true; this.transform.GetChild(0).gameObject.SetActive(true); } //IF Trackpad is touched in the front mittle of the trackpad, the laserpointer appears Vector2 touchPos = trackpadtouch.GetAxis(SteamVR_Input_Sources.Any); if (touchPos.y >= 0.5) { var device = trackpadtouch.GetActiveDevice(SteamVR_Input_Sources.Any); if (device == transform.GetComponent <SteamVR_Behaviour_Pose>().inputSource) { transform.GetChild(1).GetChild(0).gameObject.SetActive(true); } } else { this.transform.GetChild(1).GetChild(0).gameObject.SetActive(false); } Transform rayTrans = transform.GetChild(1).transform; rayTrans.localRotation = Quaternion.Euler(30, 0, 0); Ray raycast = new Ray(transform.position, rayTrans.forward); RaycastHit hit; bool bHit = Physics.Raycast(raycast, out hit); //Klick on the trackpad confirms the selection, target gets executed if (trackpadklicked.stateDown && bHit && touchPos.y >= 0.5) { //Open an already saved molecule if (false && hit.collider.name == "Öffnen" && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { vibration.Execute(0, 0.2f, 1, 1, this.pose.inputSource); GameObject.Find("Molekül").GetComponent <EditMode>().editMode = false; GameObject.Find("UI0").transform.position = new Vector3(0, 0, 0); GameObject.Find("UI1").transform.position = new Vector3(0, 0, 0); GameObject.Find("UI2").transform.position = new Vector3(0, 0, 0); GameObject.Find("UI3").transform.position = new Vector3(0, 0, 0); GameObject.Find("Molekül").SetActive(false); this.GetComponentInParent <GlobalCtrl>().loadGUILoad(); guiLoad.SetActive(true); } //Save created molecule else if (false && hit.collider.name == "Speichern" && guiSave.activeInHierarchy == false && (guiLoad.activeInHierarchy == false)) { vibration.Execute(0, 0.2f, 1, 1, this.pose.inputSource); guiSave.SetActive(true); GameObject.Find("Molekül").GetComponent <EditMode>().editMode = false; GameObject.Find("UI0").transform.position = new Vector3(0, 0, 0); GameObject.Find("UI1").transform.position = new Vector3(0, 0, 0); GameObject.Find("UI2").transform.position = new Vector3(0, 0, 0); GameObject.Find("UI3").transform.position = new Vector3(0, 0, 0); GameObject.Find("Molekül").SetActive(false); } //Create new carbon atom else if (hit.collider.name == "PeriodensystemC" && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { vibration.Execute(0, 0.2f, 1, 1, this.pose.inputSource); this.GetComponentInParent <GlobalCtrl>().createCarbon(this.transform.position); } //Create new hydrogen atom else if (hit.collider.name == "PeriodensystemH" && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { vibration.Execute(0, 0.2f, 1, 1, this.pose.inputSource); this.GetComponentInParent <GlobalCtrl>().createHydrogen(this.transform.position); } //Delete atoms or whole molecule else if (hit.collider.name == "recycle bin" && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { vibration.Execute(0, 0.2f, 1, 1, this.pose.inputSource); this.GetComponentInParent <GlobalCtrl>().recycle(); } //Mark an existing atom to edit / delete it else if (false && hit.collider.name.StartsWith("atom") && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { vibration.Execute(0, 0.2f, 1, 1, this.pose.inputSource); //if it isn't selected before,start edit mode if (GameObject.Find("Molekül").GetComponent <EditMode>().editMode == false) { GameObject.Find("Molekül").GetComponent <EditMode>().editMode = true; GameObject.Find("Molekül").GetComponent <EditMode>().fixedAtom = hit.collider.gameObject.GetComponent <Atom>(); hit.collider.gameObject.GetComponent <Renderer>().material.color = new Color32(255, 0, 0, 255); hit.collider.gameObject.GetComponent <SenseGlove_Grabable>().editMarker = true; } //if it already was selected before, close edit mode else if (GameObject.Find("Molekül").GetComponent <EditMode>().editMode == true && hit.collider.gameObject.GetComponent <Atom>()._id == GameObject.Find("Molekül").GetComponent <EditMode>().fixedAtom._id) { hit.collider.gameObject.GetComponent <SenseGlove_Grabable>().editMarker = false; GameObject.Find("Molekül").GetComponent <EditMode>().editMode = false; GameObject.Find("Molekül").GetComponent <EditMode>().fixedAtom = null; hit.collider.transform.GetComponent <Atom>().setOriginalColor(); } } //Select the whole molecule -- moves as a solid structure else if ((hit.collider.name == "AllAtoms") && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { GameObject.Find("AllAtoms").transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); GameObject.Find("SingleAtom").transform.localScale = new Vector3(0.07f, 0.1f, 0.07f); this.GetComponentInParent <GlobalCtrl>().allAtom = true; } //Select single atom -- moves independent from the molecule else if ((hit.collider.name == "SingleAtom") && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { GameObject.Find("AllAtoms").transform.localScale = new Vector3(0.07f, 0.1f, 0.07f); GameObject.Find("SingleAtom").transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); this.GetComponentInParent <GlobalCtrl>().allAtom = false; } //Turn off the forcefield, no forces are calculated else if ((hit.collider.name == "ButtonOFF") && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { GameObject.Find("ButtonON").transform.localPosition = new Vector3(4.75f, 1.6f, 6.5f); GameObject.Find("ButtonOFF").transform.localPosition = new Vector3(4.775f, 1.6f, 6.53f); this.GetComponentInParent <GlobalCtrl>().forceField = true; } //Turn on the forcefiled, forces are calculated, atoms are going to move if forces are big enough else if ((hit.collider.name == "ButtonON") && (guiSave.activeInHierarchy == false) && (guiLoad.activeInHierarchy == false)) { GameObject.Find("ButtonOFF").transform.localPosition = new Vector3(4.75f, 1.6f, 6.5f); GameObject.Find("ButtonON").transform.localPosition = new Vector3(4.775f, 1.6f, 6.53f); this.GetComponentInParent <GlobalCtrl>().forceField = false; } //Typing on virtual keyboard else if (hit.collider.transform.parent != null && hit.collider.transform.parent.name == "Tastatur") { GlobalCtrl text = this.transform.root.GetComponent <GlobalCtrl>(); text.textChange(hit.collider.gameObject); } //Scrollbar and update in GUI, if "open created molecule" is active else if (hit.collider.transform.parent != null && hit.collider.transform.parent.name == "GUILoad") { if (hit.collider.name == "Down") { GlobalCtrl.updown += 1; } else if (hit.collider.name == "Up" && GlobalCtrl.updown >= 1) { GlobalCtrl.updown -= 1; } else if (hit.collider.name.StartsWith("Platz")) { List <atomData> loadFile = new List <atomData>(); loadFile = (List <atomData>)CFileHelper.LoadData(Application.dataPath + "/MoleculeFiles/" + hit.collider.transform.GetChild(0).GetComponent <Text>().text, typeof(List <atomData>)); this.transform.root.GetComponent <GlobalCtrl>().loadMolecule(loadFile); } else if (hit.collider.name == "ExitLoadGui") { GlobalCtrl.loadGUI = false; GameObject.Find("GUILoad").SetActive(false); molecule.SetActive(true); } } } }