유니티 엔진 클라이언트/수업 과제

[유니티] Setting 창 제작 (클립보드 복사 플러그인)

Bueong_E 2023. 2. 19. 20:08
반응형
SMALL

 

우선 클립보드에 복사하는 플러그인을 쉽게 구할수 있어 해당 플러그인을 설치하고 아래의 메서드를 사용해 클립보드에 텍스트를 복사하는 기능을 추가할수 있었다.(이미지도 가능하다)

 

https://github.com/sanukin39/UniClipboard

 

GitHub - sanukin39/UniClipboard: Simple clipboard plugin for unity

Simple clipboard plugin for unity. Contribute to sanukin39/UniClipboard development by creating an account on GitHub.

github.com

UniClipboard.GetText(); 

위의 플러그인 메서드를 사용하면 클립보드에 문자열을 복사 가능하다 (사용전 Import 필수)

 

추가적으로 버튼 외에 슬라이더와 스위치 버튼 연습이 조금 부족한듯하여 이번에 정리겸 하나하나 다시 복습하며 만들어볼수 있었다. 

 

코드

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UISetupSlider : MonoBehaviour
{
    public Slider alarmSlider;
    public Slider musicSlider;

    void Start()
    {
        alarmSlider.onValueChanged.AddListener((x) =>
        {
            Debug.LogFormat("알람 볼륨 : <color=blue>{0:0}</color>",x);
        });
        musicSlider.onValueChanged.AddListener((x) =>
        {
            Debug.LogFormat("뮤직 볼륨 : <color=green>{0:0}</color>", x);
        });

        
    }

   
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UISwitch : MonoBehaviour
{
    public Button btnSwitch;
    public GameObject uIAlarmSwitchON;
    public GameObject uIAlarmSwitchOFF;
    public Image vib;

    void Start()
    {
        this.btnSwitch.onClick.AddListener(() =>
        {
            if(this.uIAlarmSwitchOFF.activeSelf)
            {
                this.SwitchOn();
                //StartCoroutine(shake());
            }
            else
            {
                this.SwitchOFF();
            }
        });
    }

    public void SwitchOn()
    {
        Debug.LogFormat("{0} 스위치 ON",this.gameObject.name);
        this.uIAlarmSwitchON.gameObject.SetActive(true);
        this.uIAlarmSwitchOFF.gameObject.SetActive(false);

    }

    public void SwitchOFF()
    {
        Debug.LogFormat("{0} 스위치 OFF", this.gameObject.name);
        this.uIAlarmSwitchON.gameObject.SetActive(false);
        this.uIAlarmSwitchOFF.gameObject.SetActive(true);

    }

    //private IEnumerator shake()
    //{
    //    float t = 1f;
    //    float shakePower = 100f;
    //    Vector2 origin = this.vib.GetComponent<RectTransform>().position; ;

    //    while (t > 0f)
    //    {
    //        t -= 0.05f;
    //        origin = origin + (Vector2)Random.insideUnitCircle*shakePower*t;
    //        yield return null;  
    //    }

    //    this.vib.GetComponent<RectTransform>().position = origin;
    //}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using Unity.VisualScripting;

public class UIUserIDSection : MonoBehaviour
{
    public TMP_Text uerID;
    private Button btnID;

    void Start()
    {
        UniClipboard.SetText(uerID.text);

        this.btnID = this.GetComponent<Button>();
        this.btnID.onClick.AddListener(() =>
        {
            Debug.LogFormat("클립보드에 복사한 내용 : <color=red>{0}</color>", uerID.text);
            UniClipboard.GetText();
        });
    }
}

 

한가지 아쉬운 점은 스위치 UI를 On 했을경우 이미지를 떨리게 만들어주고 싶었는데 (기기의 로컬 진동을 키는 방법은 어렵지 않게 찾을수 있었지만 애니메이션으로 좀 더 확실하게 보이고 싶었다.) 주석으로 된 부분처럼 실패하였다 ㅠㅠ

이미지를 떨리게 할수 있도록 미리 만들어둔 무언가가 있을듯한데 검색하기가 쉽지 않았다....

 

반응형
LIST