private IEnumerator GetTransportStrengthImpl(Action <List <UnitStrengthData> > onSuccess, Action <string> onError) { UnityWebRequest request = UnityWebRequest.Get(FullUrl(kTransportStrengthUrl)); request.SetRequestHeader(authKey, AuthHeader); UnityWebRequestAsyncOperation operation = request.SendWebRequest(); yield return(operation); if (operation.isDone) { if (!operation.webRequest.isHttpError) { try { string result = operation.webRequest.downloadHandler.text; string json = JsonWebToken.Decode(result, secretKey); print(json.Colored(ConsoleTextColor.teal).Bold()); JObject parent = JObject.Parse(json); JToken arr = parent["response"]["data"]; List <UnitStrengthData> list = new List <UnitStrengthData>(); int generatorId = 0; foreach (JToken token in arr) { float strength = token.Value <float>(); UnitStrengthData data = new UnitStrengthData(generatorId, strength); generatorId++; list.Add(data); } onSuccess?.Invoke(list); } catch (System.Exception exception) { UDebug.LogError(exception.Message.Bold()); UDebug.LogError(exception.StackTrace.Bold()); onError?.Invoke($"{exception.Message}{Environment.NewLine}{exception.StackTrace}"); } } else { UDebug.LogError(operation.webRequest.error); onError?.Invoke(operation.webRequest.error); } } else { UDebug.LogError($"operation {nameof(GetTransportStrengthImpl)} is not done".Bold()); onError?.Invoke($"operation {nameof(GetTransportStrengthImpl)} is not done"); } }
public double GetRestoredEfficiency(int managerId, int reportCompletedCount) { UnitStrengthData strengthData = Services.ResourceService.UnitStrengthDataRepository.GetStrengthData(managerId); int unitCount = Services.TransportService.GetUnitTotalCount(managerId); if (unitCount == 0) { unitCount = 1; } if (strengthData != null) { return(reportCompletedCount / (3.0 * strengthData.Strength * unitCount)); } else { UDebug.Log($"strength data for manager => {managerId} is NULL".BoldItalic().Colored(ConsoleTextColor.brown)); } return(0.0); }