티스토리 뷰

#어제 UIPopup이 게임 씬에서 보이지 않는 문제가 있었다. canvas 에서 빠져있어서 보이지 않는 단순한 문제였다

어제 하고싶었던 UIShop과 연동하는 작업을 마무리 하자

 

*구조

*UIShopDirector 하위에 자식오브잭트로,

*씬이 시작되면 btnShop이 활성화 -> 클릭 시 UIShop활성화 ->cell을 클릭 시 팝업창 (UIPopUp)활성 -> 구매버튼 클릭 시 txtNameDetail.text 보여주기

*전체 스크립트

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

public class UIShopDirector : MonoBehaviour
{
    public UIShop uiShop;
    public Button btnShop;

    public Action uiShopAction;
    private void Awake()
    {
        //this.uiShop.gameObject.SetActive(false);
        this.btnShop.onClick.AddListener(() => { 
            this.uiShop.gameObject.SetActive(true);
        });
        this.uiShop.Init();

        this.uiShopAction = () =>
        {
            Debug.Log("UIShop Scene");
        };
    }
}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class UIShop : MonoBehaviour
{
    //dim
    public Button dim; //dim ->팝업 비활성

    //Page
    public Button btnNextPage; //이전 페이지
    public Button btnBeforePage; //다음 페이지
    
    //Tab
    public Button normalTab;
    public Button specialTab;
    public Button expendablesTab;
    public GameObject normalForcus;
    public GameObject specialForcus;
    public GameObject expendablesForcus;

    //Grid
    public Button btnCell; //클릭하면 UIShopPopup 활성
    //private List<Button> cellList=new List<Button>();

    //Close
    public Button btnClose;

    //Goods
    public Text txtGold; //재화 (골드)
    public Text txtEther; //재화(에테르)

    //UIShopPopup
    public UIShopPopup uiShopPopup;

    public void Init()
    {
        this.dim.onClick.AddListener(() => { 
            this.gameObject.SetActive(false);
        });
        this.btnClose.onClick.AddListener(() => { 
            this.gameObject.SetActive(false);
        });

        //Tab
        this.normalTab.onClick.AddListener(() => {
            //Debug.Log("normalTab");
            this.normalForcus.gameObject.SetActive(true);
        });
        this.specialTab.onClick.AddListener(() => {
            //Debug.Log("specialTab");
            this.specialForcus.gameObject.SetActive(true);
        });
        this.expendablesTab.onClick.AddListener(() => {
            //Debug.Log("expendablesTab");
            this.specialForcus.gameObject.SetActive(true);
        });

        //UIShopPopup
        this.btnCell.onClick.AddListener(() => {
            this.uiShopPopup.gameObject.SetActive(true);            
        });
        this.uiShopPopup.Init();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIShopPopup : MonoBehaviour
{
    public Button dim; //dim
    public Button btnClose; //닫기(X) 버튼 -> 팝업 창 닫힘
    public Button btnSelect; //구매 버튼 ->구입한 장비아이템 이름 보여주기
    public Button btnCancel; //취소 -> 팝업 창 닫힘
    public Text txtNameDetail;
    public void Init() 
    {
        // 팝업 창 닫기, 구매("구매한 아이템 txt 보여주기"), 취소(팝업 창 닫기)
        this.dim.onClick.AddListener(() => { 
            this.gameObject.SetActive(false); 
        });
        this.btnClose.onClick.AddListener(() => {
            this.gameObject.SetActive(false);
        });
        this.btnSelect.onClick.AddListener(() => {
            Debug.LogFormat("{0}",this.txtNameDetail.text);
            this.gameObject.SetActive(false);
        });
        this.btnCancel.onClick.AddListener(() => {
            this.gameObject.SetActive(false);
        });
    }
}

 

'게임클라이언트 프로그래밍 > Guns N Rachel's' 카테고리의 다른 글

DataTable 제작 중 1  (0) 2023.04.15
Stage 1 보스 기획  (0) 2023.04.11
UI Shop 화면 구성 수정  (1) 2023.04.11
UIDiposit 화면구성  (0) 2023.04.09
UI Shop 화면 구성  (0) 2023.04.04
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함