/// <summary> /// Adds a new ticker text to a ticker line. /// </summary> public void AddTickerText(TickerText tickerText) { if (tickerText == null) { Debug.LogWarning("Tried to add an empty ticker. Ignoring."); return; } if (tickerBands == null) { Debug.LogWarning("Tickers has not been initialized properly."); return; } if (tickerText.tickerLine < 0 || tickerText.tickerLine >= tickerBands.Length) { Debug.LogWarning("Ticker line " + tickerText.tickerLine + " doesn't exist."); return; } TickerBand tickerBand = tickerBands [tickerText.tickerLine]; GameObject tickerBandObj = tickerBand.gameObject; if (tickerBandObj == null) { Debug.LogWarning("Ticker band " + tickerText.tickerLine + " has been destroyed. Can't add text."); return; } if (tickerText.font == null) { tickerText.font = defaultFont; } if (tickerText.shadowMaterial == null) { tickerText.shadowMaterial = defaultShadowMaterial; } // Creates TextMesh Object Vector2 pos = new Vector2(tickerText.horizontalOffset, 0); TickerTextAnimator[] previous = tickerBandObj.GetComponentsInChildren <TickerTextAnimator> (); GameObject tickerTextObj = Drawing.CreateText(tickerText.text, null, tickerBandObj.layer, pos, tickerText.font, tickerText.textColor, tickerText.drawTextShadow, tickerText.shadowMaterial, tickerText.shadowColor).gameObject; tickerTextObj.layer = tickerBandObj.layer; if (tickerText.drawTextShadow) { tickerTextObj.transform.FindChild("shadow").gameObject.layer = tickerTextObj.layer; } tickerText.gameObject = tickerTextObj; tickerText.textMeshSize = tickerTextObj.GetComponent <Renderer> ().bounds.size; tickerTextObj.transform.SetParent(tickerBandObj.transform, false); // Apply scale (text size) Vector3 parentSize = new Vector3(WorldMapGlobe.overlayWidth, tickerBand.verticalSize * WorldMapGlobe.overlayHeight, 1.0f); float textScale = 0.003f * tickerText.textMeshSize.y; tickerTextObj.transform.localScale = new Vector3(textScale * parentSize.y / parentSize.x, textScale, 1.0f); tickerText.textMeshSize *= textScale; tickerTextObj.AddComponent <TickerTextAnimator> ().tickerText = tickerText; // Position the text float x = pos.x; if (tickerBand.scrollSpeed != 0) { x = 0.5f + 0.5f * tickerText.textMeshSize.x / parentSize.x; // Adds other previous tickertexts on the band float widthSum = 0; for (int p = 0; p < previous.Length; p++) { widthSum += previous [p].tickerText.textMeshSize.x / parentSize.x; } if (widthSum > 0) { x = x + 0.01f + widthSum; } if (tickerBand.scrollSpeed > 0) { x = -x; } } pos = new Vector3(x, tickerTextObj.transform.localPosition.y); tickerTextObj.transform.localPosition = new Vector3(pos.x, 0.06f, -0.001f); }