Exemple #1
0
        void Start()
        {
            tm = GetComponent <TextMesh>();
            if (tickerText == null || tm == null)
            {
                DestroyImmediate(this);
            }

            tickerBand  = transform.parent.parent.parent.parent.GetComponent <WorldMapTicker>().tickerBands[tickerText.tickerLine];;
            scrollSpeed = tickerBand.scrollSpeed;

            Transform t = transform.FindChild("shadow");

            if (t != null)
            {
                tmShadow = t.GetComponent <TextMesh>();
            }
            startTime = Time.time;
            fadeIn    = tickerText.fadeDuration > 0;
            fadeOut   = tickerText.fadeDuration > 0 && tickerText.duration > 0 && tickerBand.scrollSpeed == 0;
            if (fadeOut)
            {
                fadeOutTime = tickerText.duration - tickerText.fadeDuration;
            }
            alpha = tm.color.a;
            if (tmShadow != null)
            {
                alphaShadow = tmShadow.color.a;
            }
            blinkingCount   = 0;
            blinkingLapTime = startTime;
            blinking        = tickerText.blinkInterval > 0;
            scale           = transform.parent.transform.localScale;
            Update();
        }
Exemple #2
0
        public void Init()
        {
            if (tickerBands == null || tickerBands.Length != NUM_TICKERS)
            {
                tickerBands = new TickerBand[NUM_TICKERS];
                for (int k = 0; k < NUM_TICKERS; k++)
                {
                    tickerBands [k] = new TickerBand();
                    ResetTickerBand(k);
                }
            }

            if (defaultFont == null)
            {
                defaultFont           = GameObject.Instantiate(Resources.Load <Font> ("Font/Lato"));
                defaultFont.hideFlags = HideFlags.DontSave;
                Material fontMaterial = Instantiate(defaultFont.material);
                fontMaterial.hideFlags    = HideFlags.DontSave;
                defaultFont.material      = fontMaterial;
                fontMaterial.renderQueue += 5;
            }
            if (defaultShadowMaterial == null)
            {
                defaultShadowMaterial           = GameObject.Instantiate(defaultFont.material);
                defaultShadowMaterial.hideFlags = HideFlags.DontSave;
                defaultShadowMaterial.renderQueue--;
            }

            UpdateTickerBands();
        }
Exemple #3
0
        /// <summary>
        /// Resets ticker band properties to its defaults and removes any ticker text on it.
        /// </summary>
        /// <param name="tickerIndex">Ticker index.</param>
        public void ResetTickerBand(int tickerBandIndex)
        {
            if (tickerBands == null)
            {
                Init();
            }
            if (tickerBandIndex < 0 || tickerBandIndex >= tickerBands.Length)
            {
                Debug.LogWarning("Ticker band index out of range.");
                return;
            }
            TickerBand tickerBand = tickerBands [tickerBandIndex];

            tickerBand.verticalSize = 1.0f / NUM_TICKERS;
            float vpos = (1.0f / NUM_TICKERS) * tickerBandIndex;

            if (vpos > 0.5f)
            {
                vpos -= 1.0f;
            }
            tickerBand.verticalOffset  = vpos;
            tickerBand.autoHide        = false;
            tickerBand.backgroundColor = new Color(0, 0, 0, 0.9f);               // default color, can be changed
            GameObject layer = tickerBand.gameObject;

            if (layer != null)
            {
                TickerTextAnimator[] tta = tickerBand.gameObject.GetComponentsInChildren <TickerTextAnimator> (true);
                for (int k = 0; k < tta.Length; k++)
                {
                    DestroyImmediate(tta [k].gameObject);
                }
            }
            map.requestMapperCamShot = true;
        }
        void Start()
        {
            tm = GetComponent <TextMesh> ();
            if (tickerText == null || tm == null)
            {
                DestroyImmediate(this);
            }

            tickerBand  = transform.parent.parent.parent.parent.GetComponent <WorldMapTicker> ().tickerBands [tickerText.tickerLine];
            scrollSpeed = tickerBand.scrollSpeed;

            Transform t = transform.Find("shadow");

            if (t != null)
            {
                tmShadow = t.GetComponent <TextMesh> ();
            }

            startTime = Time.time;
            fadeIn    = tickerText.fadeDuration > 0;
            fadeOut   = tickerText.fadeDuration > 0 && tickerText.duration > 0 && tickerBand.scrollSpeed == 0;
            if (fadeOut)
            {
                fadeOutTime = tickerText.duration - tickerText.fadeDuration;
            }
            alpha = tm.color.a;
            if (tmShadow != null)
            {
                alphaShadow = tmShadow.color.a;
            }
            blinkingCount   = 0;
            blinkingLapTime = startTime;
            blinking        = tickerText.blinkInterval > 0;
            scale           = transform.parent.transform.localScale;

            if (tickerText.horizontalOffsetAutomatic)
            {
                float x = ComputeCenteredHorizontalOffset();
                transform.localPosition = new Vector3(x - 0.5f, transform.localPosition.y, transform.localPosition.z);
            }

            Update();
        }
        // Sample code to show how tickers work
        void TickerSample()
        {
            map.ticker.ResetTickerBands();

            // Configure 1st ticker band: a red band in the northern hemisphere
            TickerBand tickerBand = map.ticker.tickerBands [0];

            tickerBand.verticalOffset  = 0.2f;
            tickerBand.backgroundColor = new Color(1, 0, 0, 0.9f);
            tickerBand.scrollSpeed     = 0;             // static band
            tickerBand.visible         = true;
            tickerBand.autoHide        = true;

            // Prepare a static, blinking, text for the red band
            TickerText tickerText = new TickerText(0, "WARNING!!");

            tickerText.textColor        = Color.yellow;
            tickerText.blinkInterval    = 0.2f;
            tickerText.horizontalOffset = 0.1f;
            tickerText.duration         = 10.0f;

            // Draw it!
            map.ticker.AddTickerText(tickerText);

            // Configure second ticker band (below the red band)
            tickerBand = map.ticker.tickerBands [1];
            tickerBand.verticalOffset  = 0.1f;
            tickerBand.verticalSize    = 0.05f;
            tickerBand.backgroundColor = new Color(0, 0, 1, 0.9f);
            tickerBand.visible         = true;
            tickerBand.autoHide        = true;

            // Prepare a ticker text
            tickerText           = new TickerText(1, "INCOMING MISSILE!!");
            tickerText.textColor = Color.white;

            // Draw it!
            map.ticker.AddTickerText(tickerText);
        }
Exemple #6
0
        /// <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.Find("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;
            TickerTextAnimator tta = tickerTextObj.AddComponent <TickerTextAnimator> ();

            tta.tickerText = tickerText;
            tta.map        = map;

            // 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);
            map.requestMapperCamShot = true;
        }
Exemple #7
0
        public bool UpdateTickerBands()
        {
            bool changes = false;

            if (tickerBands == null)
            {
                return(changes);
            }

            // Check base ticker layer
            if (tickerBaseLayer == null)
            {
                changes = true;
                GameObject overlayLayer = map.GetOverlayLayer(true);
                if (overlayLayer == null)
                {
                    return(changes);
                }
                Transform t = overlayLayer.transform.Find(TICKERS_LAYER);
                if (t == null)
                {
                    tickerBaseLayer = new GameObject(TICKERS_LAYER);
                    tickerBaseLayer.transform.SetParent(overlayLayer.transform, false);
                    tickerBaseLayer.transform.localPosition = new Vector3(0, 0, -0.005f);                      // Note that labels layer has -0.001f depth
                    tickerBaseLayer.layer = overlayLayer.layer;
                }
                else
                {
                    tickerBaseLayer = t.gameObject;
                }
            }

            // Redraw tickers
            for (int k = 0; k < tickerBands.Length; k++)
            {
                TickerBand tickerBand = tickerBands [k];
                // Check ticker layer
                GameObject tickerBandLayer = tickerBands [k].gameObject;
                if (tickerBandLayer == null)
                {
                    changes = true;
                    // Check if it's in the scene
                    string    name = "Ticker" + k.ToString();
                    Transform t    = tickerBaseLayer.transform.Find(name);
                    if (t != null)
                    {
                        tickerBandLayer = t.gameObject;
                    }
                    else
                    {
                        tickerBandLayer           = Instantiate(Resources.Load <GameObject> ("Prefabs/TickerBand"));
                        tickerBandLayer.name      = name;
                        tickerBandLayer.hideFlags = HideFlags.DontSave;
                        tickerBandLayer.transform.SetParent(tickerBaseLayer.transform, false);
                        tickerBandLayer.layer = tickerBaseLayer.layer;
                        Material mat = Instantiate(tickerBandLayer.GetComponent <Renderer> ().sharedMaterial);
                        mat.hideFlags = HideFlags.DontSave;
                        tickerBandLayer.GetComponent <Renderer> ().sharedMaterial = mat;
                        mat.color = new Color(0, 0, 0, 0);
                    }
                    tickerBand.gameObject = tickerBandLayer;
                }

                // Controls visibility
                float goodAlpha;
                if (tickerBand.visible && !(tickerBand.autoHide && GetTickerTextCount(k) == 0))
                {
                    goodAlpha = tickerBand.backgroundColor.a;
                }
                else
                {
                    goodAlpha = 0;
                }
                float currentAlpha = tickerBandLayer.GetComponent <Renderer> ().sharedMaterial.color.a;
                if (!tickerBand.alphaChanging && currentAlpha != goodAlpha)
                {
                    tickerBand.alphaChanging = true;
                    tickerBand.alphaStart    = currentAlpha;
                    tickerBand.alphaTimer    = DateTime.Now;
                }
                if (!tickerBandLayer.activeSelf && tickerBand.alphaChanging)
                {
                    tickerBandLayer.SetActive(true);
                }
                // Assign customizable properties
                if (tickerBandLayer.activeSelf)
                {
                    // position
                    float posY = tickerBand.verticalOffset * WorldMapGlobe.overlayHeight;
                    if (tickerBandLayer.transform.localPosition.y != posY)
                    {
                        tickerBandLayer.transform.localPosition = new Vector3(0, posY, tickerBandLayer.transform.localPosition.z);;
                        changes = true;
                    }
                    // vertical scale
                    float scaleY = tickerBand.verticalSize * WorldMapGlobe.overlayHeight;
                    if (tickerBandLayer.transform.localScale.y != scaleY)
                    {
                        tickerBandLayer.transform.localScale = new Vector3(WorldMapGlobe.overlayWidth, scaleY, 1.0f);
                        changes = true;
                    }
                    // alpha
                    float alpha;
                    if (tickerBand.alphaChanging)
                    {
                        DateTime now     = DateTime.Now;
                        float    elapsed = (float)(now - tickerBand.alphaTimer).TotalSeconds;
                        alpha = Mathf.Lerp(tickerBand.alphaStart, goodAlpha, elapsed / tickerBand.fadeSpeed);
                        if (alpha == goodAlpha)
                        {
                            tickerBand.alphaChanging = false;
                            if (goodAlpha == 0)
                            {
                                tickerBandLayer.SetActive(false);
                            }
                        }
                    }
                    else
                    {
                        alpha = goodAlpha;
                    }
                    // Assigns the color & alpha
                    Color    color = new Color(tickerBand.backgroundColor.r, tickerBand.backgroundColor.g, tickerBand.backgroundColor.b, alpha);
                    Material mat   = tickerBandLayer.GetComponent <Renderer> ().sharedMaterial;
                    if (mat.color != color)
                    {
                        mat.color = color;
                        changes   = true;
                    }
                }
            }

            if (changes)
            {
                map.requestMapperCamShot = true;
            }
            return(changes);
        }