trade & sell UI added
This commit is contained in:
@@ -21,7 +21,7 @@ public class CollectBtn : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
|
||||
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * productionRate);
|
||||
txt.text = ((int)collectableAmount).ToString();
|
||||
|
||||
btn.interactable = collectableAmount > 1;
|
||||
@@ -34,9 +34,9 @@ public class CollectBtn : MonoBehaviour
|
||||
resourceType = _resourceType;
|
||||
}
|
||||
|
||||
void OnClick(){
|
||||
async void OnClick(){
|
||||
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
|
||||
lastCollected = DBmanager.GetNetworkTime();
|
||||
lastCollected = await DBmanager.GetNetworkTime();
|
||||
switch (resourceType){
|
||||
case CollectablesData.ResourceType.Metal:
|
||||
DBmanager.SetMetal(DBmanager.Metal + (int)collectableAmount);
|
||||
|
||||
@@ -40,8 +40,27 @@ public class DBmanager : MonoBehaviour
|
||||
username = null;
|
||||
}
|
||||
|
||||
public static DateTime GetNetworkTime()
|
||||
public static async Task<DateTime> GetNetworkTime()
|
||||
{
|
||||
int unixTime = 0;
|
||||
using (UnityWebRequest www = UnityWebRequest.Get(phpRoot + "get_time.php"))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
try{
|
||||
unixTime = int.Parse(www.downloadHandler.text);
|
||||
}catch{
|
||||
Debug.Log("Invalid response from server : " + www.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
|
||||
if(unixTime> 0){
|
||||
return DateTimeOffset.FromUnixTimeSeconds(unixTime).UtcDateTime;
|
||||
}
|
||||
|
||||
//default Windows time server
|
||||
const string ntpServer = "time.windows.com";
|
||||
|
||||
@@ -352,7 +371,7 @@ public class DBmanager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
Debug.Log("adding new building " + buildingData.buildingName);
|
||||
buildingStates.Add(new BuildingState(buildingData.buildingName, 0, Vector3.zero, GetNetworkTime()));
|
||||
buildingStates.Add(new BuildingState(buildingData.buildingName, 0, Vector3.zero,await GetNetworkTime()));
|
||||
Debug.Log("Added new building " + buildingData.buildingName);
|
||||
await UpdateBuildingsToServer();
|
||||
OnStateChanged.Invoke();
|
||||
@@ -383,7 +402,7 @@ public class DBmanager : MonoBehaviour
|
||||
{
|
||||
if (buildingStates[i].id == id)
|
||||
{
|
||||
buildingStates[i].lastCollectedTimestamp = GetNetworkTime();
|
||||
buildingStates[i].lastCollectedTimestamp = await GetNetworkTime();
|
||||
Debug.Log("Setting " + id + " last collected to " + buildingStates[i].lastCollectedTimestamp);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user