상세 컨텐츠

본문 제목

[개발일지] : 주요 UI 개발내용 정리

카테고리 없음

by 강자이 2024. 7. 3. 22:44

본문

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

public class UI_Unit : UI_Popup
{
    private Unit unit;
    private void Start()
    {
        Init();
        GetText((int)Texts.TXT_AttackPower).text = unit.AttackRange.ToString();
        GetText((int)Texts.TXT_AttackSpeed).text = unit.MoveSpeed.ToString();
    }

    public override void Init()
    {
        base.Init();

        Bind<Button>(typeof(Buttons));
        Bind<TMP_Text>(typeof(Texts));
        Bind<GameObject>(typeof(GameObjects));
        Bind<Image>(typeof(Images));

        GetButton((int)Buttons.Btn_Close).gameObject.AddUIEvent((PointerEventData data) => OnButtonClicked(Buttons.Btn_Close, data));
        GetButton((int)Buttons.Blocker).gameObject.AddUIEvent((PointerEventData data) => OnButtonClicked(Buttons.Blocker, data));
    }

    private void OnButtonClicked(Buttons buttonType, PointerEventData data)
    {
        switch (buttonType)
        {
            //UIManager.Instance.ShowPopupUI<UI_Unit>();
            case Buttons.Btn_Close:                
                ClosePopupUI();
                break;
            case Buttons.Blocker:               
                ClosePopupUI();
                break;
        }
    }

    public void UpdateUnitInfo(Unit unit)
    {
        this.unit = unit;
        
    }


    //enum
    enum Buttons
    {
        Blocker,
        Btn_Close
    }

    enum Texts
    {
        TXT_Character,
        TXT_Characteristic,
        TXT_AttackPower,
        TXT_AttackPower_Increase,
        TXT_AttackSpeed,
        TXT_AttackSpeed_Increase,
        TXT_Info

    }

    enum GameObjects
    {
        
    }

    enum Images
    {
        Image_Unit,
        Image_AttackPower,
        Image_AttackSpeed,
        Image_Info,
        Image_Skill,
        Image_Character,
        Image_CharacterName,
        Image_AttackPower_IconBox,
        Image_AttackPower_Icon,
        Image_AttackPowerUp_Icon,
        Image_AttackSpeed_IconBox,
        Image_AttackSpeed_Icon,
        Image_AttackSpeedUp_Icon,        
    }
}

 

 

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

public class UI_Unit : UI_Popup
{
    //enum
    enum Buttons
    {
        Btn_Close
    }

    enum Texts
    {
        TXT_Character,
        TXT_Characteristic,
        TXT_AttackPower,
        TXT_AttackPower_Increase,
        TXT_AttackSpeed,
        TXT_AttackSpeed_Increase,
        TXT_Info

    }

    enum GameObjects
    {

    }

    enum Images
    {
        Image_Unit,
        Image_Skill,
        Image_Character        
    }
    private Unit unit;
    private void Start()
    {
        Init();
        GetText((int)Texts.TXT_AttackPower).text = unit.StatHandler.Stat.AttackRange.ToString();
        GetText((int)Texts.TXT_AttackSpeed).text = unit.StatHandler.Stat.MoveSpeed.ToString();
    }

    public override void Init()
    {
        base.Init();

        Bind<Button>(typeof(Buttons));
        Bind<TMP_Text>(typeof(Texts));
        Bind<GameObject>(typeof(GameObjects));
        Bind<Image>(typeof(Images));

        GetButton((int)Buttons.Btn_Close).gameObject.AddUIEvent((PointerEventData data) => OnButtonClicked(Buttons.Btn_Close, data));        
    }

    private void OnButtonClicked(Buttons buttonType, PointerEventData data)
    {
        switch (buttonType)
        {
            //UIManager.Instance.ShowPopupUI<UI_Unit>();
            case Buttons.Btn_Close:                
                ClosePopupUI();
                break;
        }
    }

    public void UpdateUnitInfo(Unit unit)
    {
        this.unit = unit;
    }
}

댓글 영역