private static Research GetRandomResearch(Research[] researchArray) { var randomWeight = Random.Range(0, SumRandomWeights(researchArray)); Research selectedResearch = null; foreach (var research in researchArray) { if (randomWeight < research.randomWeight) { selectedResearch = research; break; } else { randomWeight -= research.randomWeight; } } return(selectedResearch); }
/// <summary> /// Load UI with data from SO. /// </summary> /// <param name="newResearch"></param> public void LoadInfo(Research researchSO) { infoText.text = researchSO.description; costText.text = researchSO.goldCost.ToString(); }
protected override void Start() { currentResearch = GetRandomResearch(researchArray); }
/// <summary> /// Called by Button. /// </summary> public override void OnReadyIconPressed() { base.OnReadyIconPressed(); currentResearch = GetRandomResearch(researchArray); infoPromptControllerInstance.LoadInfo(currentResearch); }
/// <summary> /// Load UI with data from SO. /// </summary> /// <param name="newResearch"></param> public void ReadResearchSO(Research researchSO) { researchInfoText.text = researchSO.description; researchCostText.text = researchSO.goldCost.ToString(); windowTitleText.text = researchSO.researchName.ToString(); }