UnityThread | 在u3d中使用多线程,使用C # 的多线程,http
kandi X-RAY | UnityThread Summary
kandi X-RAY | UnityThread Summary
UnityThread
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of UnityThread
UnityThread Key Features
UnityThread Examples and Code Snippets
Community Discussions
Trending Discussions on UnityThread
QUESTION
I'm using Firebase Realtime Database (for Unity) to manage the server side for a turn based game but I have a problem with my matchmaking... a high download usage.
Every online game have 2 base states to avoid more than 2 players join a game: Created and Joined
- Created: A player try to join a game, if can't find one a new game will be Created
- Joined: A player try to join a game, if find one change the state to from Created to Joined
I'm using RunTransaction
to prevent more than 2 players from joining a game, but I checked that the latest data was not fetched from the database because of the local cache, adding keepSynced
over my matches-{lang}
child node will always have the latest data but naturally this produces a high download usage.
ANSWER
Answered 2020-Apr-22 at 14:38Removing "keepSynced" players will have locally cached information for "matches", can I trust that by doing this there will be no more than 2 players per game? *Transactions are supposed to avoid this kind of problem.
With KeepSynced off, Transactions will still hit the local cache then hit the internet. It'll probably save you some bandwidth since it's a lazy access (that's assuming you don't do something like "get all matches"), and you'll be able to make the guarantees you need. Whether or not you use KeepSynced, you should be prepared for your transaction to run multiple times (and against null data if the local cache is empty).
Is there a way to avoid the local cache for a request and thus always get the updated data?
Correction
It looks like I got this a little backwards, see this answer for more details. It will return the cached value and request an updated one. Subsequent calls will get a new value when it's available. You should always try to use ValueChanged
when possible.
old answer:
You _can_ just say `GetValueAsync`, which has to bypass the cache since it will only fire once. You really should use ValueChanged listeners to listen for changes and Transactions to change data if you can to keep everything up to date and to avoid data races.
Could the best solution be to move the games to another node to reduce the size of the "matches" node?
Generally the fewer people hitting a shared resource, the better your performance. If you haven't already, check out the Loteria post to see how a team created a realtime game on Realtime Database that was resilient enough to be a Google Doodle.
The TLDR is that rather than a player being responsible for creating or finding a game, players looking for games are written to a queue. When a player is added to the matchmaking queue, a Cloud Function trigger fires which does the work of hooking the users up. A client knows that they're in a game by putting a ValueChanged listener onto a player entry in the database and waiting for a game to be written into it.
The game is further kept low latency with some manual sharding logic. They performed some profiling to see how much traffic a single database could handle, then write some quick (manual - since it was a one day thing) scaling logic to distribute players to one of a number of databases.
I hope that all helps!
--Patrick
QUESTION
I'm working on a game in Unity and Unity is not threadsafe so whenever I do some calculations on different thread and want to go back to Unity I need to queue calls in some kind of queue so Unity can take those tasks and execute them on Unity thread. This is my code with tool that kind of gets job done:
...ANSWER
Answered 2018-May-20 at 18:44Just wrap your method call in a lambda expression:
Action act = () => MethodCalledNotInUnityThread1(argVal1, argVal2);
ExecuteInUpdate(act);
QUESTION
Here is my code:
...ANSWER
Answered 2018-Apr-19 at 09:27- you need a certificate;
makecert
would work, but it won't be trusted by default, so you'd either need to supply a customRemoteCertificateValidationCallback
to the consumer, or use a trusted cert; Let's Encrypt might be useful there makecert
orNew-SelfSignedCertificate
- the
SslStream
would need to go between theNetworkStream
and theStreamReader
; frankly, it isn't clear to make thatStreamReader
give you much here - you could do everything here with just theStreaam
API; so instead ofWriteLine
, you'd encode manually and thenWrite
the encoded buffer; but - there's no reason that you can't just whackSslStream
in the middle of the two - yes
- only the server needs the certificate (and in particular, only the server needs the private key of the certificate); there is something related called "client certificates" used for authenticating the client, but that is a related but different topic
As an example ripped from SE.Redis and mangled beyond legibility; SE.Redis optionally encrypts, and is basically:
QUESTION
I wrote a Thread helper class that can be used to execute a piece of code in Unity's main Thread.
This is the functions blue print:
...ANSWER
Answered 2017-Apr-23 at 11:00After hours of experiment I discovered that if you put the code with the closure in a function, then cache it to an Action
variable once in the Start
or Awake
function, the closure memory allocation will be gone when you invoke it in inside the while loop.
Also, I made the doneUploading
boolean variable a volatile
so that both Threads
can see the changes. I don't think that the lock
keyword is needed for this boolean
variable here.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install UnityThread
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page