protected override async void OnEnable() { _plots = PlotManager.Instance as PlotManager; await _plots.Initialized; Filter.AllRemoteChanges() .TakeUntilDisable(this) .Where(ev => ev.ChangedProperties.Contains("Origin")) .Subscribe(async ev => { await _plots.Initialized; var plot = _plots.Get(ev.Model.Origin); if (plot) { ev.Model.transform.SetParent(plot.Visualization, false); // scatter plot's position is in the middle, set position to 'origin' of scatter plot ev.Model.transform.localPosition = new Vector3(-0.5f, -0.5f, 0); } else { Debug.LogError($"Unable to find plot {ev.Model.Origin} for filter {ev.Model.Id}"); } }); base.OnEnable(); }
private void LateUpdate() { if (_link.CreatedBy == _client.Id) { if (isFirst) { isFirst = false; _link.PlacingPosition = transform.parent.InverseTransformPoint(_cam.position + _cam.forward * _placementDistance); var plotUpstream = _plots.Get(_link.Upstream); var plotDownstream = _plots.Get(_link.Downstream); if (plotUpstream != null) { _link.PlacingRotation = Quaternion.identity; _placementDistance = Mathf.Max(1f, Mathf.Abs((_cam.position - plotUpstream.transform.position).magnitude)); } else if (plotDownstream != null) { _link.PlacingRotation = Quaternion.identity; _placementDistance = Mathf.Max(1f, Mathf.Abs((_cam.position - plotDownstream.transform.position).magnitude)); } transform.localPosition = _link.PlacingPosition; transform.localRotation = _link.PlacingRotation; } var worldPos = _cam.position + _cam.forward * _placementDistance; var worldRot = Quaternion.identity; if (_client.LookingAtType == "plot" && _client.LookingAtId != Mathf.Max(_link.Upstream, _link.Downstream)) // up- or downstream should be -1 { var plot = _plots.Get(_client.LookingAtId); worldPos = plot.transform.position; worldRot = plot.transform.rotation; } var localPos = transform.parent.InverseTransformPoint(worldPos); _link.PlacingPosition = Vector3.Lerp(localPos, _link.PlacingPosition, StabilizationWeight); var localRot = transform.parent.rotation * worldRot; _link.PlacingRotation = Quaternion.Lerp(localRot, _link.PlacingRotation, StabilizationWeight); } transform.localPosition = _link.PlacingPosition; transform.localRotation = _link.PlacingRotation; }
private void UpdateSelection() { if (_client.SelectedType == "plot") { var plot = _plots.Get(_client.SelectedId); _selection = plot?.Visualization; _lineRenderer.material.color = plot?.Color ?? Color.white; } else if (_client.SelectedType == "link") { _selection = _links.Get(_client.SelectedId)?.Visualization; _lineRenderer.material.color = Color.white; } else { _selection = null; } _lineRenderer.enabled = _selection != null; }
private void RefreshAnchors() { _start = _plots.Get(_link.Upstream); _end = _plots.Get(_link.Downstream); }
private void UpdateSelection() { var isTabletHorizontal = _tablet == null || _tablet.Orientation == "horizontal"; var isVoiceActive = _tablet && _tablet.IsVoiceActive; // no interaction during zen mode (with exceptions) if (_user.ZenMode && isTabletHorizontal && !isVoiceActive) { return; } // don't switch selection while placing links if (_isCreatingLink) { return; } var lookingAtId = _user.LookingAtId; var lookingAtType = _user.LookingAtType; if (_tablet && _tablet.Orientation == "vertical") { lookingAtId = _tablet.LookingAtId; lookingAtType = _tablet.LookingAtType; } // avoid unnecessary updates if (lookingAtId == _user.SelectedId && lookingAtType == _user.SelectedType) { return; } if (string.IsNullOrEmpty(lookingAtType)) { return; } // disable gaze selection while placing a plot if (_tablet && _plots.Get().Any(p => p.BoundTo == _tablet.Id)) { return; } if (_user.SelectionProgress == -1) { _user.SelectionProgress = 0; _gazeStartTime = Time.time; } if (_user.SelectionProgress < 100) { var dwellTime = DEFAULT_DWELL_TIME; if (_tablet && _tablet.Orientation == WebClient.ORIENTATION_VERTICAL) { dwellTime = VERTICAL_DWELL_TIME; } if (_tablet && _tablet.IsVoiceActive) { dwellTime = VOICE_DWELL_TIME; } _user.SelectionProgress = Mathf.Min(100f, (Time.time - _gazeStartTime) / dwellTime * 100f); if (_user.SelectionProgress >= 100f) { _user.SelectedId = lookingAtId; _user.SelectedType = lookingAtType; } } }
private void UpdatePlots() { _sourcePlot = _plotManager.Get(_link.Upstream); _targetPlot = _plotManager.Get(_link.Downstream); if (_sourcePlot == null && _targetPlot == null) { Debug.LogError($"Unable to find both source ({_link.Upstream}) and target ({_link.Downstream}) plot!"); name = $"GraphLink (Error)"; } else if (_sourcePlot == null) { if (!PositionHelper) { PositionHelper = Instantiate(PositionHelperTemplate, transform); } _renderer.StartAnchor = PositionHelper.transform; _renderer.EndAnchor = _targetPlot.Visualization; name = $"GraphLink to {_targetPlot.Id}"; } else if (_targetPlot == null) { if (!PositionHelper) { PositionHelper = Instantiate(PositionHelperTemplate, transform); } _renderer.EndAnchor = PositionHelper.transform; _renderer.StartAnchor = _sourcePlot.Visualization; name = $"GraphLink from {_sourcePlot.Id}"; } else { if (PositionHelper) { Destroy(PositionHelper.gameObject); PositionHelper = null; } _renderer.StartAnchor = _sourcePlot.Visualization; _renderer.EndAnchor = _targetPlot.Visualization; Observable.Merge(_sourcePlot.DataRx, _targetPlot.DataRx) .ObserveOnMainThread() .TakeUntilDisable(this) .BatchFrame(0, FrameCountType.EndOfFrame) .Subscribe(_ => UpdateRenderer()); name = $"GraphLink {_sourcePlot.Id} -> {_targetPlot.Id}"; } _spSource = _sourcePlot?.GetComponentInChildren <ScatterPlot>(); _spTarget = _targetPlot?.GetComponentInChildren <ScatterPlot>(); if (_client.LookingAtType == "plot") { var tmpPlot = _plotManager.Get(_client.LookingAtId); if (_spSource == null) { _spSource = tmpPlot?.GetComponentInChildren <ScatterPlot>(); _sourcePlot = tmpPlot; } else if (_spTarget == null) { _spTarget = tmpPlot?.GetComponentInChildren <ScatterPlot>(); _targetPlot = tmpPlot; } } }