private void HitListener_BodyPartHit(object sender, BodyHitListener.HapticInformation e) { float hitTime; if (HapticPattern.curveList[CurveIndex].heightCurve.length == 0) { hitTime = 0.0f; } else { hitTime = HapticPattern.GetCurveEndTime(CurveIndex) + hapticSettings.defaultTimeGranularity; } // Add the point to the pattern HapticPattern.AddKey(CurveIndex, hitTime, e.bodyHitInfo, hapticSettings.defaultIntensity); // Add BodyHit GO to the hit location so the user can interact with the point in the UI BodyHitUI currentHit = SpawnBodyHitGameObject(e.worldHitLocation, e.bodyHitInfo.hitAngle, e.bodyHitInfo.hitHeight, hitTime, CurveIndex, hapticSettings.defaultIntensity, true); bodyHitsPerCurve[CurveIndex].Add(currentHit); // Update the line renderer DrawCurrentCurvePath(); }
private BodyHitUI SpawnBodyHitGameObject(Vector3 spawnPosition, float hitAngle, float hitHeight, float hitTime, int curveIndex, float intensity, bool isTemporary = false) { GameObject inflectionPoint = Instantiate(hitLocationPrefab, spawnPosition, Quaternion.identity, capsuleGO.transform); inflectionPoint.hideFlags = HideFlags.HideInHierarchy; BodyHitUI currentHit = inflectionPoint.GetComponent <BodyHitUI>(); currentHit.SetValues(hitAngle, hitHeight, intensity, hitTime, HapticPattern.GetKeyCountForCurve(curveIndex) - 1, curveIndex, HapticPattern.curveList[curveIndex]); currentHit.isTemporary = isTemporary; return(currentHit); }
private void AddCurveToDictionary(int curveIndex, ScriptableHapticCurve curveToAdd) { if (curveToAdd != null) { // Go through each keyframe, save the value, and place the GO representation for (int h = 0; h < curveToAdd.heightCurve.length; h++) { float hitHeight = curveToAdd.heightCurve[h].value; float hitAngle = curveToAdd.angleCurve[h].value; BodyHitUI currentHit = SpawnBodyHitGameObject(capsuleBodyCoordinate.CalculatePositionFromBodyCoordinateHit(new BodyCoordinateHit(hitHeight, hitAngle), true), hitAngle, hitHeight, curveToAdd.heightCurve[h].time, curveIndex, curveToAdd.intensityCurve[h].value); bodyHitsPerCurve[curveIndex].Add(currentHit); } } }
public void GetMouseClicks(SceneView sceneView) { // Only care about mouse down events if (Event.current.type != EventType.MouseDown) { return; } // convert GUI coordinates to screen coordinates Vector3 screenPosition = Event.current.mousePosition; Vector3 cameraScreenPosition = screenPosition; cameraScreenPosition.y = Camera.current.pixelHeight - cameraScreenPosition.y; Ray ray = Camera.current.ScreenPointToRay(cameraScreenPosition); RaycastHit hit; // Wait for double clicks on left mouse if (Event.current.clickCount == 2 && Event.current.button == 0) { // Cast ray into the scene if (Physics.Raycast(ray, out hit)) { Event.current.Use(); BodyCoordinate bodyPart = hit.collider.GetComponent <BodyCoordinate>(); if (bodyPart != null) { BodyCoordinateHit hitLocation = bodyPart.CalculateBodyCoordinateHitFromPosition(hit.point); OnBodyPartHit(bodyPart, hitLocation, hit.point); return; } BodyHitUI uiHit = hit.collider.GetComponent <BodyHitUI>(); if (uiHit != null) { // Make sure that another UI is not already displaying lastUIHit?.HideUI(screenPosition, true); lastUIHit = uiHit; lastUIHit.DisplayUI(screenPosition); return; } } } else if (Event.current.clickCount == 1) { // Close the hitUI if they click outside of it if (lastUIHit != null) { // Right/middle clicks will force close the UI bool wasHidden = (Event.current.button != 0) ? lastUIHit.HideUI(screenPosition, true) : lastUIHit.HideUI(screenPosition); if (wasHidden) { lastUIHit = null; } } } }