Beispiel #1
0
 public bool Exists(NetworkEntityGuid entity)
 {
     using (SyncObj.ReaderLock())
     {
         return(LocalNameMap.ContainsKey(entity));
     }
 }
Beispiel #2
0
        /// <inheritdoc />
        public async Task <string> RetrieveAsync(NetworkEntityGuid entity)
        {
            using (await SyncObj.ReaderLockAsync())
            {
                if (LocalNameMap.ContainsKey(entity))
                {
                    return(LocalNameMap[entity]);                    //do not call Retrieve, old versions of Unity3D don't support recursive readwrite locking.
                }
            }

            //If we're here, it wasn't contained
            var result = await QueryRemoteNameService(entity);

            if (!result.isSuccessful)
            {
                throw new InvalidOperationException($"Failed to query name for Entity: {entity}. Result: {result.ResultCode}.");
            }

            //Add it
            using (await SyncObj.WriterLockAsync())
            {
                //Check if some other thing already initialized it

                if (LocalNameMap.ContainsKey(entity))
                {
                    return(LocalNameMap[entity]);                    //do not call Retrieve, old versions of Unity3D don't support recursive readwrite locking.
                }
                return(LocalNameMap[entity] = result.isSuccessful ? result.Result.EntityName : "Unknown");
            }
        }
Beispiel #3
0
        /// <inheritdoc />
        public void EnsureExists([NotNull] NetworkEntityGuid entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            using (SyncObj.ReaderLock())
                if (!LocalNameMap.ContainsKey(entity))
                {
                    throw new KeyNotFoundException($"Entity: {entity} not found in {nameof(INameQueryService)}.");
                }
        }