public override void ChangeAwayFrom(NVRHand hand) { if (current_hover != null) { current_hover.line_renderer.material.color = nonhover_color; } current_hover = null; }
/// <summary> /// Shifts the given playback by the positional shift. /// </summary> private static void shiftRecording(PlaybackActions playback, Vector3 shift) { var shifted_recording = playback.Recording.Select(snapshot => { snapshot.position = snapshot.position + shift; return(snapshot); }).ToList(); playback.Recording = shifted_recording; }
// Update is called once per frame private void Update() { // 0..1 double progress = (PlaybackActions.sequence_time() / PlaybackActions.sequence_period) % 1; // Set the size Vector3 scale = transform.localScale; scale.x = (float)(1 - progress) * .05f; transform.localScale = scale; // Set the color GetComponent <Renderer>().material.color = progress > .8 ? Color.red : Color.white; }
public override void Update(NVRHand hand) { var all_playing_clones = FindObjectsOfType <PlaybackActions>(); if (all_playing_clones.Length != 0) { // Find the clone of the closest recording to the current hand position. var closest_clone = all_playing_clones.MinBy( clone => { return(clone.Recording.Min(snapshot => Vector3.Distance(snapshot.position, hand.transform.position))); }); // Highlight the recording we're closest to the start point of. if (closest_clone != current_hover) { if (current_hover != null) { current_hover.line_renderer.material.color = nonhover_color; } closest_clone.line_renderer.material.color = hover_color; current_hover = closest_clone; } } // Move the recording when we grip the trigger if (hand.UseButtonPressed) { if (last_position.HasValue) { if (current_hover != null) { var shift = hand.CurrentPosition - last_position.Value; // shift all recorded positions, by the delta shiftRecording(current_hover, shift); } } last_position = hand.CurrentPosition; } if (hand.UseButtonUp) { last_position = null; } // Clone the nearest recording if (GetDPadPress(hand) == NVRButtons.DPad_Right || Input.GetKeyDown(KeyCode.D)) { current_hover.gameObject.SetActive(false); var duplicate_obj = Instantiate(current_hover.gameObject); duplicate_obj.GetComponent <PlaybackActions>().Recording = new List <RecordActions.Snapshot>(current_hover.Recording); // The hand component doesn't duplicate cleanly, so add it again DestroyImmediate(duplicate_obj.GetComponent <NVRHand>()); NVRHand duplicate_hand = duplicate_obj.AddComponent <NVRHand>(); // The physical component doesn't duplicate cleanly, so add it again DestroyImmediate(duplicate_obj.GetComponent <NVRPhysicalController>()); duplicate_obj.AddComponent <NVRPhysicalController>(); current_hover.gameObject.SetActive(true); duplicate_obj.SetActive(true); duplicate_hand.PreInitialize(hand.Player); duplicate_hand.SetupInputDevice(duplicate_obj.GetComponent <FakeInputDevice>()); hand.Player.Hands.Add(duplicate_hand); shiftRecording(duplicate_obj.GetComponent <PlaybackActions>(), new Vector3(0, .1f, 0)); } }