Ejemplo n.º 1
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           = Instantiate(Resources.Load <Font>("WMSK/Font/Lato"));
                defaultFont.name      = "Lato";
                defaultFont.hideFlags = HideFlags.DontSave;
                Material fontMaterial = Instantiate(Resources.Load <Material>("WMSK/Materials/Font"));                // this material is linked to a shader that has into account zbuffer
                fontMaterial.mainTexture = defaultFont.material.mainTexture;
                //fontMaterial.hideFlags = HideFlags.DontSave;
                defaultFont.material      = fontMaterial;
                fontMaterial.renderQueue += 5;
            }
            if (defaultShadowMaterial == null)
            {
                defaultShadowMaterial = Instantiate(defaultFont.material);
                //defaultShadowMaterial.hideFlags = HideFlags.DontSave;
                defaultShadowMaterial.renderQueue--;
            }

            UpdateTickerBands();
        }
Ejemplo n.º 2
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);
                }
            }
        }
        void Start()
        {
            tm = GetComponent <TextMesh>();
            if (tickerText == null || tm == null)
            {
                DestroyImmediate(this);
            }

            tickerBand  = WMSK.instance.GetComponent <WMSK_Ticker>().tickerBands[tickerText.tickerLine];
            scrollSpeed = tickerBand.scrollSpeed;

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

            if (t != null)
            {
                tmShadow = t.GetComponent <TextMesh>();
            }
            map       = WMSK.GetInstance(transform);
            startTime = map.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;
            Update();
        }
Ejemplo n.º 4
0
        // 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.3f;
            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.horizontalOffset = -0.35f;
            tickerText.textColor        = Color.yellow;
            tickerText.blinkInterval    = 0.2f;
            tickerText.duration         = 10.0f;

            // Draw it!
            map.ticker.overlayMode = true;              // make them visible on top of clouds and everything
            map.ticker.AddTickerText(tickerText);

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

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

            // Draw it!
            map.ticker.AddTickerText(tickerText);
        }
Ejemplo n.º 5
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;
            }

            Font     customFont           = tickerText.font ?? defaultFont;
            Material customShadowMaterial = 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, pos, customFont, tickerText.textColor, tickerText.drawTextShadow, customShadowMaterial, tickerText.shadowColor, tickerText.anchor).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(WMSK.mapWidth, tickerBand.verticalSize * WMSK.mapHeight, 1.0f);

            float textScale = 0.003f * tickerText.textMeshSize.y * tickerText.textScale;

            tickerTextObj.transform.localScale = new Vector3(textScale * parentSize.y / parentSize.x, textScale, 1.0f);
            tickerText.textMeshSize            = new Vector2(WMSK.mapWidth * tickerBandObj.transform.localScale.x * tickerText.textMeshSize.x * tickerTextObj.transform.localScale.x,
                                                             WMSK.mapHeight * tickerBandObj.transform.localScale.y * tickerText.textMeshSize.y * tickerTextObj.transform.localScale.y);
            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, _overlayMode ? -0.0001f : -0.002f);
        }
Ejemplo n.º 6
0
        public bool UpdateTickerBands()
        {
            bool changes = false;

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

            // Check base ticker layer
            if (tickerBaseLayer == null)
            {
                changes = true;
                Camera     cameraMain   = map.cameraMain;
                GameObject overlayLayer = overlayMode ? cameraMain.gameObject : map.GetOverlayLayer(true);
                if (overlayLayer == null)
                {
                    return(changes);
                }
                Transform t = overlayLayer.transform.Find("TickersLayer");
                if (t == null)
                {
                    tickerBaseLayer           = new GameObject("TickersLayer");
                    tickerBaseLayer.hideFlags = HideFlags.DontSave;
                    tickerBaseLayer.transform.SetParent(overlayLayer.transform, false);
                }
                else
                {
                    tickerBaseLayer = t.gameObject;
                }
                if (_overlayMode)
                {
                    float z = cameraMain.nearClipPlane + 0.005f;
                    tickerBaseLayer.transform.localPosition = new Vector3(0, 0, z);
                    Vector3 pos0 = cameraMain.transform.InverseTransformPoint(cameraMain.ScreenToWorldPoint(new Vector3(0, 0, z)));
                    Vector3 pos1 = cameraMain.transform.InverseTransformPoint(cameraMain.ScreenToWorldPoint(new Vector3(cameraMain.pixelWidth, cameraMain.pixelHeight, z)));
                    tickerBaseLayer.transform.localScale = new Vector3(pos1.x - pos0.x, pos1.y - pos0.y, 1);
                }
                else
                {
                    tickerBaseLayer.transform.localPosition = new Vector3(0, 0, -0.03f);
                }
                tickerBaseLayer.layer = overlayLayer.layer;
            }

            // 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>("WMSK/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;
                    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;                     // * WMSK.mapHeight;
                    if (tickerBandLayer.transform.localScale.y != scaleY)
                    {
                        tickerBandLayer.transform.localScale = new Vector3(1.0f, 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;
                    }
                }
            }

            return(changes);
        }