52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CollectBtn : MonoBehaviour
|
|
{
|
|
public DateTime lastCollected;
|
|
public string buildingId;
|
|
public float productionRate;
|
|
public double collectableAmount;
|
|
public Button btn;
|
|
public TMP_Text txt;
|
|
|
|
public CollectablesData.ResourceType resourceType;
|
|
|
|
|
|
void Start(){
|
|
btn.onClick.AddListener(OnClick);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
|
|
txt.text = ((int)collectableAmount).ToString();
|
|
|
|
btn.interactable = collectableAmount > 1;
|
|
}
|
|
|
|
public void Set(string id,DateTime _lastCollected, float _productionRate, CollectablesData.ResourceType _resourceType){
|
|
buildingId = id;
|
|
lastCollected = _lastCollected;
|
|
productionRate=_productionRate;
|
|
resourceType = _resourceType;
|
|
}
|
|
|
|
void OnClick(){
|
|
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
|
|
lastCollected = DBmanager.GetNetworkTime();
|
|
switch (resourceType){
|
|
case CollectablesData.ResourceType.Metal:
|
|
DBmanager.SetMetal(DBmanager.Metal + (int)collectableAmount);
|
|
break;
|
|
|
|
case CollectablesData.ResourceType.Oxygen:
|
|
DBmanager.SetOxygen(DBmanager.Oxygen + (int)collectableAmount);
|
|
break;
|
|
}
|
|
DBmanager.CollectBuilding(buildingId);
|
|
}
|
|
}
|