The Time Manager Component allows you to synchronise your game with real world time. You can retrive the time from a Network Time Protocol (NTP) server, store it in your variables, and encrypt it to prevent hacking.
The system currently consists of a Time Manager Component, a series of Actions to control encryption and Variable store/receive, and Conditions to verify synchronised times.
To use the Time Manager, create an empty gameobject in your hierarchy and add the time mamanger component to it.
Next, create four Global Variabes to enabled all the features of the Time Manager.
Initial Time (the time the game was started or first started)
Current Time (the current time from the Network)
Local Time (to store the current time of the Players platform)
Last Update time (stores the array of times that each recurring Action was last executed)
These should all be String Variables and the save check box should be checked.
Add these Variables to the approriate slots in the Time Manager Component. The Local Time Variable is used by the Condition and Action to verify local time and is not referenced by the Time Manager.
Select an NTP server, for most cases the pool.ntp.org is the best choice.
Also decide if you wish to encrypt your variables to protect them from Hacking. You can leave this unchecked while developing and check it later when building. The Key you choose must be a combination of 32 characters and numbers, abnd must be the same for all of your variables.
If you require te NTP server to be queried repeatedly, set the repeating ping check box and interval. Do not set this tio continually ping, or your game will be blocked. Every 10 seconds or even once per hour is a good option. You can also use the Action to check NTP now, if you want to prevent hacking or cheating (see example for how this is set up).
Lastly, add your Actions to the Recurring Action listand selecyt the interval that you required. This seting is to execute this Action every x (number) y (time), where x is a count like 13, and y is either minutes, hours, days, weeks or months. Therefore if you set this to every 30 minutes, the Action will execute every half hour or 48 times per day. Likewise, every 12 months will be once per year, as would e very 52 weeks.
The wait after start parameter is to allow for areas with slow network times. You should allow the NTP server to obtain and store the time prior to checking if the Actions are due to execute.
NOTE: If the start variable is empty, the Time Manager will presume that this is a new game and store the initial time in this variable. If there is a time already there, as would be from a loaded saved game, the variable will not be updated. This allows you to know when a new game was started, and when this game is reloaded (load saved game), all Recurring Actions will be checked to calculate if they should have been executed during the time the game was not active.
New Game: If the Initial Variable is empty, store current time in milliseconds.
Set Actions: Calculate the interval in Milliseconds (example, every 3 minutes is 60000 x 3) and store as ActionTime.
Read Last Update: Calculate how many times the Action should be executed to bring it current.
(If ((last time updated + action interval) <= current time), then execute)
Execute Actions: Loop through the Action Array until ALL actions are brought up to date.
Store Last Update: Each Action that was just executed has current time stored in the array.
The Time Manager is executed every 60 seconds. More than this is not needed as the smallest Action time is 1 minute.