private void OnEnable() { _cam = Camera.main.transform; _plot = GetComponent <Plot>(); _origin = OriginCoordinateSystem.Instance; _webClients = Manager <WebClient> .Instance; _connection = WebServerConnection.Instance; _user = StreamClient.Instance; WebClient.AllModelChange() .TakeUntilDisable(this) .Where(ev => ev.ChangedProperties.Contains("Owner")) .Subscribe(ev => SearchCurrentWebclient()); Observable.Merge(WebClient.ModelCreated(), WebClient.ModelDestroyed()) .TakeUntilDisable(this) .Subscribe(m => SearchCurrentWebclient()); SearchCurrentWebclient(); _plot.LockedToAxisRx .TakeUntilDisable(this) .Subscribe(isLocked => { if (isLocked) { LockAlignment(); } else { UnlockAlignment(); } }); _plot.BoundToRx .TakeUntilDisable(this) .Where(boundTo => boundTo >= 0) .Select(_ => _webClients.Get(_plot.BoundTo)) .Where(client => client != null && client.Owner == _user.Id) .Subscribe(client => { // TODO: Workaround for newly created scatterplots if (_plot.Position != Vector3.zero || _plot.Rotation != Quaternion.identity) { _plot.PositioningOffset = Vector3.Distance(_plot.transform.position, _cam.position); } else { _plot.Position = _origin.transform.InverseTransformPoint(_cam.position + _cam.forward * _plot.PositioningOffset); } _plot.IsPositioning = true; _wasPositioning = true; _plot.ActualPosition = _plot.Position; _plot.ActualRotation = _plot.Rotation; UpdatePosition(client); Observable.EveryFixedUpdate() .TakeUntilDisable(this) .TakeWhile(_ => client != null && client.Id == _plot.BoundTo && client.Owner == _user.Id) .Subscribe( _ => UpdatePosition(client), () => _plot.IsPositioning = false); }); }
private void OnEnable() { _plot = GetComponent <Plot>(); _cam = Camera.main.transform; }