コード例 #1
0
 // Use this for initialization
 void Start()
 {
     anim    = this.GetComponent <Animator>();
     tc      = this.GetComponentInChildren <TargetChange>();
     mCamera = Camera.main;
     headPos = GameObject.Find("headPos").GetComponent <Transform>().position;
     Head    = GameObject.Find("C_man_Head");
     idle();
 }
コード例 #2
0
        public async Task <WatchResponseResult> HandleResponseAsync(ListenResponse response, CancellationToken cancellationToken)
        {
            switch (response.ResponseTypeCase)
            {
            case ListenResponse.ResponseTypeOneofCase.TargetChange:
                TargetChange change      = response.TargetChange;
                bool         noTargetIds = change.TargetIds.Count == 0;

                switch (change.TargetChangeType)
                {
                case NoChange:
                    if (noTargetIds && change.ReadTime != null && _current)
                    {
                        // This means everything is up-to-date, so emit the current set of docs as a snapshot,
                        // if there were changes.
                        await PushSnapshotAsync(Timestamp.FromProto(change.ReadTime), change.ResumeToken, cancellationToken).ConfigureAwait(false);
                    }
                    break;

                case Add:
                    GaxPreconditions.CheckState(WatchStream.WatchTargetId == change.TargetIds[0], "Target ID must be 0x{0:x}", WatchStream.WatchTargetId);
                    break;

                case Remove:
                    // TODO: Do we really want an RpcException here?
                    StatusCode status = (StatusCode?)change.Cause?.Code ?? StatusCode.Cancelled;
                    throw new RpcException(new Status(status, $"Backend ended listen stream: {change.Cause?.Message}"));

                case Current:
                    _current = true;
                    break;

                case Reset:
                    ResetDocs();
                    return(WatchResponseResult.Continue);

                default:
                    // TODO: Do we really want an RpcException here?
                    throw new RpcException(new Status(StatusCode.InvalidArgument, $"Encountered invalid target change type: {change.Cause.Message}"));
                }

                bool healthy = change.ResumeToken != null && (change.TargetIds.Count == 0 || change.TargetIds.Contains(WatchStream.WatchTargetId));
                // Possibly tell the watch stream that it's now healthy (so reset backoff), or just continue.
                return(healthy ? WatchResponseResult.StreamHealthy : WatchResponseResult.Continue);

            case ListenResponse.ResponseTypeOneofCase.DocumentChange:
                // No other targetIds can show up here, but we still need to see if the targetId was in the
                // added list or removed list.
                var               changed  = response.DocumentChange.TargetIds.Contains(WatchStream.WatchTargetId);
                var               removed  = response.DocumentChange.RemovedTargetIds.Contains(WatchStream.WatchTargetId);
                Document          document = response.DocumentChange.Document;
                DocumentReference docRef   = CreateDocumentReference(document.Name);
                if (changed && removed)
                {
                    throw new InvalidOperationException("Server error: document was both changed and removed");
                }
                if (!changed && !removed)
                {
                    throw new InvalidOperationException("Server error: document was neither changed nor removed");
                }
                _changeMap[docRef] = changed ? document : null;
                return(WatchResponseResult.Continue);

            case ListenResponse.ResponseTypeOneofCase.DocumentDelete:
                _changeMap[CreateDocumentReference(response.DocumentDelete.Document)] = null;
                return(WatchResponseResult.Continue);

            case ListenResponse.ResponseTypeOneofCase.DocumentRemove:
                _changeMap[CreateDocumentReference(response.DocumentRemove.Document)] = null;
                return(WatchResponseResult.Continue);

            case ListenResponse.ResponseTypeOneofCase.Filter:
                // TODO: Do we really want to create the change set itself, rather than just count? It seems a bit wasteful.
                ChangeSet changeSet   = ExtractChanges(default);
                int       currentSize = _documentSet.Count + changeSet.Adds.Count - changeSet.Deletes.Count;
                // Reset the stream if we don't have the right number of documents.
                if (response.Filter.Count != currentSize)
                {
                    ResetDocs();
                    return(WatchResponseResult.ResetStream);
                }
                return(WatchResponseResult.Continue);

            default:
                throw new RpcException(new Status(StatusCode.InvalidArgument, $"Encountered invalid listen response type: {response.ResponseTypeCase}"));
            }
        }