Ejemplo n.º 1
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.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);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            if (_ticker == null)
            {
                return;
            }
            if (tickerNames.Length < tickers.Length)
            {
                return;
            }

            bool refresh = false;

            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(blackStyle);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Ticker Band", GUILayout.Width(120));
            tickerLine = EditorGUILayout.Popup(tickerLine, tickerNames, GUILayout.Width(80));
            if (GUILayout.Button("Reset Ticker", GUILayout.MaxWidth(120)))
            {
                _ticker.ResetTickerBand(tickerLine);
                refresh = true;
            }
            if (GUILayout.Button("Reset All", GUILayout.MaxWidth(120)))
            {
                _ticker.ResetTickerBands();
                refresh = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Visible", GUILayout.Width(120));
            bool oldb = tickers[tickerLine].visible;

            tickers[tickerLine].visible = EditorGUILayout.Toggle(tickers[tickerLine].visible, GUILayout.Width(20));
            if (oldb != tickers[tickerLine].visible)
            {
                refresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Scroll Speed", GUILayout.Width(120));
            tickers[tickerLine].scrollSpeed = EditorGUILayout.Slider(tickers[tickerLine].scrollSpeed, -0.5f, 0.5f);

            if (GUILayout.Button("Static"))
            {
                tickers[tickerLine].scrollSpeed = 0;
            }


            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Vertical Offset", GUILayout.Width(120));
            float oldf = tickers[tickerLine].verticalOffset;

            tickers[tickerLine].verticalOffset = EditorGUILayout.Slider(tickers[tickerLine].verticalOffset, -0.5f, 0.5f);
            if (oldf != tickers[tickerLine].verticalOffset)
            {
                refresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Size", GUILayout.Width(120));
            oldf = tickers[tickerLine].verticalSize;
            tickers[tickerLine].verticalSize = EditorGUILayout.Slider(tickers[tickerLine].verticalSize, 0.01f, 1.0f);
            if (oldf != tickers[tickerLine].verticalSize)
            {
                refresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUIContent autoHideContent = new GUIContent("   Auto Hide", "Ticker will automatically hide if it's empty");

            oldb = tickers[tickerLine].autoHide;
            GUILayout.Label(autoHideContent, GUILayout.Width(120));
            tickers[tickerLine].autoHide = EditorGUILayout.Toggle(tickers[tickerLine].autoHide, GUILayout.Width(20));
            if (oldb != tickers[tickerLine].autoHide)
            {
                refresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Background Color", GUILayout.Width(120));
            Color oldc = tickers[tickerLine].backgroundColor;

            tickers[tickerLine].backgroundColor = EditorGUILayout.ColorField(tickers[tickerLine].backgroundColor, GUILayout.Width(50));
            if (oldc != tickers[tickerLine].backgroundColor)
            {
                refresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Fade Speed", GUILayout.Width(120));
            oldf = tickers[tickerLine].fadeSpeed;
            tickers[tickerLine].fadeSpeed = EditorGUILayout.Slider(tickers[tickerLine].fadeSpeed, 0, 5.0f);
            if (oldf != tickers[tickerLine].fadeSpeed)
            {
                refresh = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();

            EditorGUILayout.BeginVertical(blackStyle);

            // allows the user to create a sample ticker and add it to the map
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Add Sample Text", GUILayout.Width(120));
            EditorStyles.textField.wordWrap = true;
            sampleTicker.text = EditorGUILayout.TextArea(sampleTicker.text, GUILayout.Height(60));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Ticker Line", GUILayout.Width(120));
            sampleTicker.tickerLine = EditorGUILayout.Popup(sampleTicker.tickerLine, tickerNames, GUILayout.Width(80));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Horizontal Offset", GUILayout.Width(120));
            oldf = sampleTicker.horizontalOffset;
            sampleTicker.horizontalOffset = EditorGUILayout.Slider(sampleTicker.horizontalOffset, -0.5f, 0.5f);
            if (oldf != sampleTicker.horizontalOffset)
            {
                refresh = true;
            }
            if (tickers[tickerLine].scrollSpeed != 0)
            {
                DrawWarningLabel("(ignored because scroll speed)");
            }
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Text Color", GUILayout.Width(120));
            sampleTicker.textColor = EditorGUILayout.ColorField(sampleTicker.textColor, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Draw Shadow", GUILayout.Width(120));
            sampleTicker.drawTextShadow = EditorGUILayout.Toggle(sampleTicker.drawTextShadow);
            if (sampleTicker.drawTextShadow)
            {
                GUILayout.Label("Shadow Color", GUILayout.Width(120));
                sampleTicker.shadowColor = EditorGUILayout.ColorField(sampleTicker.shadowColor, GUILayout.Width(50));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Fade Duration", GUILayout.Width(120));
            sampleTicker.fadeDuration = EditorGUILayout.Slider(sampleTicker.fadeDuration, 0, 10.0f);
            EditorGUILayout.EndHorizontal();

            if (tickers[tickerLine].scrollSpeed == 0)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("   Duration", GUILayout.Width(120));
                duration = sampleTicker.duration.ToString();
                duration = EditorGUILayout.TextField(duration, GUILayout.Width(80));
                sampleTicker.duration = ToFloat(duration);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Blink Interval", GUILayout.Width(120));
            sampleTicker.blinkInterval = EditorGUILayout.Slider(sampleTicker.blinkInterval, 0, 5.0f);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Blink Repetitions", GUILayout.Width(120));
            sampleTicker.blinkRepetitions = EditorGUILayout.IntSlider(sampleTicker.blinkRepetitions, 0, 50);
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Launch Test Ticker") && Application.isPlaying)
            {
                _ticker.AddTickerText(sampleTicker);
                if (sampleTicker.duration == 0)
                {
                    sampleTicker = (TickerText)sampleTicker.Clone();                     // maintain properties but allow to create a new/different ticker without affecting previous one
                }
            }
            if (!Application.isPlaying)
            {
                DrawWarningLabel("Not available in Edit mode");
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();

            if (!Application.isPlaying && (refresh || pendingChanges))
            {
                pendingChanges = _ticker.UpdateTickerBands();
                if (pendingChanges)
                {
                    EditorUtility.SetDirty(target);
                }
            }
        }