2022년 6월 8일 수요일

Unity TextBubble(말풍선)

 





using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;


using UnityEngine.UI;

public class TextBubble : MonoBehaviour
{

    public TextMeshProUGUI target;
    public string[] value;

   

    public HorizontalLayoutGroup textGroup;
    public GameObject TextImage;
    bool isOn;

    IEnumerator ActiveBubble;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(AutoStart());
       
    }

    IEnumerator AutoStart()
    {
        value = new string[3];

        value[0] = "(주)테스크는 2006년 1월 차량용 \n " +
                    "배기계 부품 전문 제조기업인 \n" +
                    "(주)정도정밀 에서 분사하여 \n" +
                    "고객에게 새로운 가치를 \n" +
                    " 제공하고  환경 친화적 \n" +
                    "자동차 부품 개발에 집중하고 있습니다. \n";



        value[1] = "새롭게 설립된 회사로 그간 \n" +
                    "끊임없는 연구개발 투자와 \n" +
                    "신기술 도입을 통해 차량용 \n" +
                    "배기계 부품의 개발 및 제조 전문기업으로 \n" +
                    "확고한 위상을 구축하고 있습니다.";

        value[2] = "진정한 글로벌 경쟁력을 갖추고 \n" +
                    "무한 성장할 수 있는 발판을 \n" +
                    "확고히 다져나가고 있습니다.";

        isOn = true;

        yield return new WaitForSeconds(2f);

        ActiveTextBubble();
        textGroup.padding = new RectOffset(1, 1, 0, 1);
    }


    void OnMouseDown()
    {
        if (TextImage.activeSelf)
        {
            TextImage.SetActive(false);
            return;
        }

        if (!TextImage.activeSelf)
        {
            TextImage.SetActive(true);
            return;
        }

        if (!isOn)
            return;
    }


    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("1"))
        {
            ActiveTextBubble();
        }
    }


    void ActiveTextBubble()
    {
        isOn = false;
        target.text = "";
        if (ActiveBubble != null)
        {
            StopCoroutine(ActiveBubble);
            ActiveBubble = null;
        }
        ActiveBubble = CreateTextBubble();
        StartCoroutine(ActiveBubble);
    }


    IEnumerator CreateTextBubble()
    {

        foreach (var x in value)
        {
            target.text = "";
            for (int i = 0; i < x.Length; i++)
            {
                target.text += x[i];
                yield return new WaitForSeconds(0.05f);
            }
            yield return new WaitForSeconds(1.5f);
        }

       
    }
}





댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...