trade & sell UI added

This commit is contained in:
2022-05-17 11:36:24 +05:30
parent 58f7212434
commit a3aba776a5
25 changed files with 22513 additions and 635 deletions

View File

@@ -46619,7 +46619,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 50, y: 190}
m_AnchoredPosition: {x: 49.99994, y: 190}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &386684401
@@ -64207,11 +64207,11 @@ RectTransform:
m_Father: {fileID: 1840047501}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -610.64, y: 20.799866}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: -85, y: 20.799843}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 1, y: 1}
m_Pivot: {x: 0, y: 1}
--- !u!114 &546537820
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -64243,7 +64243,7 @@ MonoBehaviour:
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 4
m_ChildAlignment: 3
m_Spacing: 27.89
m_ChildForceExpandWidth: 0
m_ChildForceExpandHeight: 0
@@ -212563,7 +212563,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -85}
m_AnchoredPosition: {x: 0.00018310547, y: -85}
m_SizeDelta: {x: 1920, y: 65.05449}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &1840047502

View File

@@ -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);

View File

@@ -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;
}