private void OnChartDataChanged(object sender, ChartEventArgs e) { if (e.ChartType != ChartDataType) { // not our type return; } ChartData = GameManager.Instance.GetEpmResponse_Chart(); if (_isFirstRefresh) { PushChartDataToModels(true); _isFirstRefresh = false; } else { PushChartDataToModels(false); } }
public EpmChartData GetEpmResponse_Chart() { if (string.IsNullOrEmpty(_epmDataChart) || _epmDataChart == "empty") { return null; } else { EpmChartData epmChart = new EpmChartData(false); epmChart.ChartTitle = _epmDataChartTypeRequested.ToString(); var N = JSON.Parse(_epmDataChart); // if server not up, then _epmDataChart will contain error string, not parsable JSON if (N == null) { print("GameManager.GetEpmResponse_Chart failed to parse: " + _epmDataChart); // only log above once: _epmDataChart = null; return null; } int entries = N["entries"].Count; for (int i = 0; i < entries; i++) { string name = N["entries"][i]["name"]; string value = N["entries"][i]["value"]; //print("entry: " + i + " " + name + " " + value); epmChart.Records.Add(new EpmChartRecord() { BarName = name, BarValue = float.Parse(value), BarValueLabel = "" }); } return epmChart; } }
// Use this for initialization void Start() { GameManager.Instance.OnChartDataChanged += OnChartDataChanged; _chartGui = GetComponent<ChartGui>(); _chartGui.enabled = false; //_isFirstRefresh = true; // this cauees first refresh to happen without any animation or sound _isFirstRefresh = false; // listen to all the child bar events for being highlighted foreach (Transform child in transform) { // get ref to title if (child.gameObject.name == "Chart Title") { _gameObjectTitle = child.gameObject; } if (child.gameObject.name.StartsWith("ChartBar_")) { Highlight_IsHighlightable hih = child.GetComponent<Highlight_IsHighlightable>(); if (hih != null) { hih.OnHighlighted += OnBarHighlighted; hih.OnUnhighlighted += OnBarUnhighlighted; } } } // create inits but dont push them to models ChartData = new EpmChartData(true); // Init the chart data with a title SetTitle(ChartDataType.ToString()); }