Esempio n. 1
0
 /// <summary>
 /// Sets the subtitle.
 /// </summary>
 /// <param name='subtitle'>
 /// Subtitle.
 /// </param>
 public override void SetSubtitle(Subtitle subtitle)
 {
     if ((subtitle != null) && !string.IsNullOrEmpty(subtitle.formattedText.text))
     {
         if (portraitImage != null)
         {
             portraitImage.sprite = UITools.CreateSprite(subtitle.GetSpeakerPortrait());
         }
         if (portraitName != null)
         {
             portraitName.text = subtitle.speakerInfo.Name;
             UITools.SendTextChangeMessage(portraitName);
         }
         if (line != null)
         {
             var typewriterEffect = line.GetComponent <UnityUITypewriterEffect>();
             if (typewriterEffect != null && typewriterEffect.enabled)
             {
                 typewriterEffect.Stop();
                 typewriterEffect.playOnEnable = false;
             }
             SetFormattedText(line, subtitle.formattedText);
             //---Was: if (typewriterEffect != null && typewriterEffect.enabled) typewriterEffect.OnEnable();
             //---Now manually start Play for more precise control.
             if (typewriterEffect != null && typewriterEffect.enabled)
             {
                 typewriterEffect.PlayText(subtitle.formattedText.text);
             }
         }
         Show();
         if (alwaysVisible && line != null)
         {
             var typewriterEffect = line.GetComponent <UnityUITypewriterEffect>();
             if (typewriterEffect != null)
             {
                 typewriterEffect.OnEnable();
             }
         }
     }
     else
     {
         if ((line != null) && (subtitle != null))
         {
             SetFormattedText(line, subtitle.formattedText);
         }
         Hide();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Sets the subtitle.
 /// </summary>
 /// <param name='subtitle'>
 /// Subtitle.
 /// </param>
 public override void SetSubtitle(Subtitle subtitle)
 {
     if ((subtitle != null) && !string.IsNullOrEmpty(subtitle.formattedText.text))
     {
         if (portraitImage != null)
         {
             portraitImage.sprite = UITools.CreateSprite(subtitle.GetSpeakerPortrait());
         }
         if (portraitName != null)
         {
             portraitName.text = subtitle.speakerInfo.Name;
         }
         if (line != null)
         {
             SetFormattedText(line, subtitle.formattedText);
         }
         Show();
         if (alwaysVisible && line != null)
         {
             var typewriter = line.GetComponent <UnityUITypewriterEffect>();
             if (typewriter != null)
             {
                 typewriter.OnEnable();
             }
         }
     }
     else
     {
         if ((line != null) && (subtitle != null))
         {
             SetFormattedText(line, subtitle.formattedText);
         }
         Hide();
     }
 }
 private bool CanTriggerAnimations()
 {
     if ((animator == null) && !lookedForAnimator)
     {
         lookedForAnimator = true;
         if (panel != null)
         {
             animator = panel.GetComponent <Animator>();
         }
         if ((animator == null) && (line != null))
         {
             animator = line.GetComponent <Animator>();
         }
     }
     return((animator != null) && (animationTransitions != null));
 }
Esempio n. 4
0
    // Get components from the Unity scene
    private void FindTextComponents()
    {
        try
        {
            addScoreButton    = addScoreButton.GetComponent <UnityEngine.UI.Button>();
            status            = status.GetComponent <UnityEngine.UI.Text>();
            displayScore      = displayScore.GetComponent <UnityEngine.UI.Text>();
            displayScoreLabel = displayScoreLabel.GetComponent <UnityEngine.UI.Text>();
            usernameInput     = usernameInput.GetComponent <UnityEngine.UI.InputField>();
            score             = score.GetComponent <UnityEngine.UI.Text>();

            for (int i = 0; i < TOTAL_SCORES; i++)
            {
                names[i]  = names[i].GetComponent <UnityEngine.UI.Text>();
                scores[i] = scores[i].GetComponent <UnityEngine.UI.Text>();
            }
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.Log(e.Message);
        }
    }
 /// <summary>
 /// Sets the subtitle.
 /// </summary>
 /// <param name='subtitle'>
 /// Subtitle.
 /// </param>
 public override void SetSubtitle(Subtitle subtitle)
 {
     if ((subtitle != null) && !string.IsNullOrEmpty(subtitle.formattedText.text))
     {
         if (portraitImage != null)
         {
             portraitImage.sprite = subtitle.GetSpeakerPortrait();
         }
         if (portraitName != null)
         {
             portraitName.text = subtitle.speakerInfo.Name;
             UITools.SendTextChangeMessage(portraitName);
         }
         if (line != null)
         {
             var typewriterEffect = line.GetComponent <UnityUITypewriterEffect>();
             if (typewriterEffect != null && typewriterEffect.enabled)
             {
                 typewriterEffect.Stop();
                 typewriterEffect.playOnEnable = false;
             }
             SetFormattedText(line, subtitle.formattedText);
             if (typewriterEffect != null && typewriterEffect.enabled)
             {
                 typewriterEffect.PlayText(subtitle.formattedText.text);
             }
         }
     }
     else
     {
         if ((line != null) && (subtitle != null))
         {
             SetFormattedText(line, subtitle.formattedText);
         }
     }
 }
Esempio n. 6
0
 private void Awake()
 {
     _stext   = text;
     textRect = text.GetComponent <RectTransform>();
 }
Esempio n. 7
0
        public static GameObject DrawRing(int ring_index,
                                          float r_ext,
                                          float epaisseur,
                                          Dictionary <int, Bouton> boutons,
                                          float marge,
                                          Color[] couleurs
                                          )
        {
            GameObject go = new GameObject();

            go.name = "ring_" + ring_index;

            int nbrboutons = boutons.Count;

            float r_int = r_ext - epaisseur;
            float angle_ouverture_deg     = (float)360 / nbrboutons;
            float angle_position_deg_init = angle_ouverture_deg / 2;

            foreach (Bouton bouton in boutons.Values)
            {
                float angle_position_deg = angle_position_deg_init + bouton.index * angle_ouverture_deg;

                GameObject btn;
                try
                {
                    btn = RingButton.DrawButton(r_ext,
                                                r_int,
                                                angle_ouverture_deg,
                                                angle_position_deg,
                                                marge);
                    if (btn == null)
                    {
                        continue;
                    }

                    btn.name             = go.name + "_btn_" + bouton.name;
                    btn.transform.parent = go.transform;

                    RingButton_Manager rb = btn.AddComponent <RingButton_Manager>();
                    //rb._name = btn.name;
                    rb._ring_index = ring_index;
                    rb._index      = bouton.index;
                    rb._SetColors(couleurs[bouton.index]);

                    //icône
                    if (bouton.icone != null)
                    {
                        try
                        {
                            Texture    texture = bouton.icone;
                            GameObject icn     = RingButton.DrawIcon(texture, 0, 0, 0);
                            if (icn != null)
                            {
                                icn.transform.parent = rb.gameObject.transform;
                                float hauteur = (r_ext - r_int - marge) / Mathf.Pow(2, 0.5f);

                                float amplitude = r_int + hauteur / 2 + marge;
                                float x         = amplitude * Mathf.Cos((90 + angle_position_deg + angle_ouverture_deg / 2) / 180 * Mathf.PI);
                                float y         = amplitude * Mathf.Sin((90 + angle_position_deg + angle_ouverture_deg / 2) / 180 * Mathf.PI);

                                if (angle_ouverture_deg == 360)
                                {
                                    x       = 0;
                                    y       = 0;
                                    hauteur = r_ext;
                                }
                                icn.transform.localScale = new Vector2(hauteur, hauteur);
                                icn.transform.Translate(x, y, -35);

                                //icn.transform.Rotate(0, 0, angle_position_deg + angle_ouverture_deg / 2);
                            }
                            rb._icone = icn;
                        }
                        catch (System.Exception ex)
                        {
                            Debug.Log(ex.Message + "\n" + ex.StackTrace);
                        }
                    }

                    //texte
                    if (bouton.label != "")
                    {
                        GameObject canvas_go = new GameObject();
                        canvas_go.transform.SetParent(rb.gameObject.transform);
                        Canvas canvas = canvas_go.gameObject.AddComponent <Canvas>();
                        canvas.renderMode  = RenderMode.WorldSpace;
                        canvas.worldCamera = Camera.main;
                        float amplitude = r_int + r_ext * 0.8f;
                        canvas.GetComponent <RectTransform>().sizeDelta = new Vector2(amplitude, amplitude);

                        GameObject text_go = new GameObject();
                        text_go.transform.SetParent(canvas_go.transform);
                        text_go.transform.Translate(0, 0, -20);
                        text_go.transform.Rotate(0, 0, angle_position_deg + angle_ouverture_deg / 2);

                        UnityEngine.UI.Text text = text_go.gameObject.AddComponent <UnityEngine.UI.Text>();
                        text.GetComponent <RectTransform>().sizeDelta = new Vector2(r_ext + r_int, r_ext + r_int);
                        text.alignment = TextAnchor.UpperCenter;
                        text.text      = bouton.label;

                        text.font                 = bouton.label_font;
                        text.fontStyle            = bouton.label_fontStyle;
                        text.resizeTextForBestFit = bouton.label_resizeTextForBestFit;
                        if (!bouton.label_resizeTextForBestFit)
                        {
                            text.fontSize = bouton.label_fontSize;
                        }
                        text.color = bouton.label_color;
                    }
                }
                catch (System.Exception ex)
                {
                    Debug.Log(ex.Message + "\n" + ex.StackTrace);
                }
            }
            return(go);
        }
Esempio n. 8
0
        public static GameObject DrawRing(Anneau anneau,
                                          float angle_initial,
                                          bool sens_horaire)
        {
            float r_int = anneau.r_int;
            float r_ext = anneau.r_ext;
            float marge = anneau.marge * (r_ext - r_int);

            GameObject go = new GameObject();

            go.name = "ring_" + anneau.index;

            int nbrboutons = anneau.butons_on_ring.Count;

            float angle_ouverture_deg = (float)360 / nbrboutons;

            if (sens_horaire)
            {
                angle_initial = -angle_initial;
            }

            float angle_position_deg_init = angle_initial + angle_ouverture_deg / 2;

            foreach (RingButton_EditorMode bouton in anneau.butons_on_ring.Values)
            {
                float angle_position_deg;
                if (sens_horaire)
                {
                    angle_position_deg = angle_position_deg_init - (bouton.button_index_on_ring_int + 1) * angle_ouverture_deg;
                }
                else
                {
                    angle_position_deg = angle_position_deg_init + (bouton.button_index_on_ring_int - 1) * angle_ouverture_deg;
                }

                //Debug.Log("Bouton \"" + bouton.name + "\" angle " + (int)angle_position_deg + " sur " + (int)angle_ouverture_deg + "°");

                GameObject btn;
                try
                {
                    btn = RingButton.DrawButton(r_ext,
                                                r_int,
                                                angle_ouverture_deg,
                                                angle_position_deg,
                                                marge);
                    if (btn == null)
                    {
                        continue;
                    }

                    btn.name             = go.name + "_btn_" + bouton.name;
                    btn.transform.parent = go.transform;

                    RingButton_Manager rb = btn.AddComponent <RingButton_Manager>();
                    bouton.ringButtonManager = rb;
                    rb._ring_index           = anneau.index;
                    rb._index = bouton.button_index_on_ring_int;
                    rb._SetColors(bouton.button_color);

                    //icône
                    if (bouton.icon != null)
                    {
                        try
                        {
                            Texture    texture = bouton.icon;
                            GameObject icn     = RingButton.DrawIcon(texture,
                                                                     r_ext, r_int,
                                                                     angle_position_deg + angle_ouverture_deg / 2);

                            icn.transform.parent = rb.gameObject.transform;
                            rb._icone            = icn;
                        }
                        catch (System.Exception ex)
                        {
                            Debug.Log(ex.Message + "\n" + ex.StackTrace);
                        }
                    }

                    //texte
                    if (bouton.label.label_show && bouton.label.label != "")
                    {
                        GameObject canvas_go = new GameObject();
                        canvas_go.transform.SetParent(rb.gameObject.transform);
                        Canvas canvas = canvas_go.gameObject.AddComponent <Canvas>();
                        canvas.renderMode  = RenderMode.WorldSpace;
                        canvas.worldCamera = Camera.main;
                        float amplitude = r_int + r_ext * 0.8f;
                        canvas.GetComponent <RectTransform>().sizeDelta = new Vector2(amplitude, amplitude);

                        GameObject text_go = new GameObject();
                        text_go.transform.SetParent(canvas_go.transform);
                        text_go.transform.Translate(0, 0, -20);
                        text_go.transform.Rotate(0, 0, angle_position_deg + angle_ouverture_deg / 2);

                        UnityEngine.UI.Text text = text_go.gameObject.AddComponent <UnityEngine.UI.Text>();
                        text.GetComponent <RectTransform>().sizeDelta = new Vector2(r_ext + r_int, r_ext + r_int);
                        text.alignment = TextAnchor.UpperCenter;
                        text.text      = bouton.label.label;

                        text.font                 = bouton.label.label_font;
                        text.fontStyle            = bouton.label.label_fontStyle;
                        text.resizeTextForBestFit = bouton.label.label_resizeTextForBestFit;
                        if (!bouton.label.label_resizeTextForBestFit)
                        {
                            text.fontSize = bouton.label.label_fontSize;
                        }
                        text.color = bouton.label.label_color;
                    }

                    //events
                    rb._OnClick = bouton.events._OnClick;
                    rb._OnEnter = bouton.events._OnEnter;
                    rb._OnExit  = bouton.events._OnExit;
                }
                catch (System.Exception ex)
                {
                    Debug.Log(ex.Message + "\n" + ex.StackTrace);
                }
            }
            return(go);
        }