티스토리 뷰
* 어제 아틀라스 아미지를 입히는 것 까지 성공 했으니 이제 아이템 등급에 따라 프레임의 색을 바꿔주고
결과 이미지를 터치하는 동안 팝업 창이 활성화 되게 만들어야한다.
추가 할 내용이 많지는 않아서 금방 끝낼 수 있었다. 아직 팝업에서 아이템의 info를 어떻게 보여줄 지 고민중이다
결정만 되면 팝업의 text를 DataManager와 InfoManager에서 불러오고 text를 바꿔주면 될 것 같다.
현재 주사위 확률을 임의로 정하고 결과를 보여주고 있지만 (등급/종류 로 나누고있다)
데이터 테이블이 완성되면 해당 데이터의 id를 랜덤값으로 출력하여 보여주는 방법으로 바꾸면 될 것같다.
ex1) Grade 0~3 (Wood, Iron, Gold, Diamond), Type 0~5(Arrow, Axe, Sword, Wand, Food, FullFood)
ex2) 확률을 퍼센테이지로 나눈 후 Grade와 Type을 정해서 결과 를 보여주는 방안으로 수정
*수정된 스크립트
*UIDiceDirector
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class UIDiceDirector : MonoBehaviour
{
public UIDice uiDice;
public Button btnDice;
private void Awake()
{
this.uiDice.Init();
this.btnDice.onClick.AddListener(() => {
this.uiDice.gameObject.SetActive(true);
});
}
}
*UIDice
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.U2D;
using UnityEngine.UI;
public class UIDice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public Button closeBtn;
public GameObject btnGo;
private Button rollBtn;
public DiceScript dice;
public Button dim;
public UIdiceResultPopup resultPopup;
public void Init()
{
this.dice.Init();
this.rollBtn = this.btnGo.GetComponent<Button>();
this.closeBtn.onClick.AddListener(() => {
this.gameObject.SetActive(false);
});
this.dim.onClick.AddListener(() => {
this.gameObject.SetActive(false);
});
this.rollBtn.onClick.AddListener(() => { //돌고 있는 중이면 또 눌리면 안됨
this.dice.RollDice();
this.rollBtn.interactable=false; //button컴포넌트 비활성화
StartCoroutine(this.DiceBtnSetting());
this.BtnGoColorDown();
this.dice.DiceResultImgInit();
this.closeBtn.interactable = false;
this.dim.interactable = false;
});
this.resultPopup.Init();
}
//ResultPopup
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("PointerDown");
this.resultPopup.gameObject.SetActive(true);
}
public void OnPointerUp(PointerEventData eventData)
{
Debug.Log("PointUp");
this.resultPopup.gameObject.SetActive(false);
}
//DiceResult
private IEnumerator DiceBtnSetting()
{
while (true)
{
yield return new WaitForSeconds(0.5f);
if (this.dice.rb.velocity.magnitude == 0)
{
this.dice.StopDice();
this.rollBtn.interactable = true;
this.BtnGoColorUp();
this.dice.DiceResultImg();
this.closeBtn.interactable = true;
this.dim.interactable = true;
//PercentageTest
this.dice.GradePercentage();
this.dice.TypePercentage();
yield break;
}
}
}
//ButtonSetting
private void BtnGoColorDown() //알파값 down
{
var imgBoxGo=this.btnGo.transform.Find("imgBox").GetComponent<Image>();
var txtSelectGo = this.btnGo.transform.Find("txtSelect").GetComponent<Text>();
Color imgBoxGoColor = imgBoxGo.color;
imgBoxGoColor.a = 0.5f;
imgBoxGo.color= imgBoxGoColor;
Color txtSelectGoColor= txtSelectGo.color;
txtSelectGoColor.a = 0.5f;
txtSelectGo.color= txtSelectGoColor;
}
private void BtnGoColorUp() //알파값 up
{
var imgBoxGo = this.btnGo.transform.Find("imgBox").GetComponent<Image>();
var txtSelectGo = this.btnGo.transform.Find("txtSelect").GetComponent<Text>();
Color imgBoxGoColor = imgBoxGo.color;
imgBoxGoColor.a = 1f;
imgBoxGo.color = imgBoxGoColor;
Color txtSelectGoColor = txtSelectGo.color;
txtSelectGoColor.a = 1f;
txtSelectGo.color = txtSelectGoColor;
}
}
*DiceScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
public class DiceScript : MonoBehaviour
{
private enum ErewardGrade
{
Wood=0,
Iron=1,
Gold=2,
Diamond=3
}
private enum ErewardType
{
Arrow=0,
Axe=1,
Sword=2,
Wand=3,
FullFood=4,
OneFood=5
}
private ErewardType eRewardType;
private ErewardGrade eRewardGrade;
public Rigidbody rb;
public GameObject[] resultImg; // 0 - icon , 1 - frame, 2 - initIcon
void Start()
{
this.rb = GetComponent<Rigidbody>();
}
public void Init()
{
this.transform.localPosition = new Vector3(-978.4013f, -589.6378f, -0.42f);
this.transform.rotation= Quaternion.Euler(0f, 65.3f, -90f);
}
public void RollDice()
{
this.rb.isKinematic = false;
float dirX = Random.Range(200, 700); //랜덤레인지의 폭이 좁을수록 비슷한 연출이 나옴
float dirY = Random.Range(200, 700);
float dirZ = Random.Range(200, 700);
this.transform.position = new Vector3(0, 3f, 0); //높이 y=3 로 고정
this.transform.rotation = Quaternion.identity; //회전 -> 0, 안하면 다른 위치의 y축에서 떨어짐
rb.AddForce(this.transform.up * 500); //y축으로 500만큼의 힘을 가하다
rb.AddTorque(dirX, dirY, dirZ); //3개의 축(x,y,z)에 랜덤한 힘(0~500까지의 랜덤한 수)으로 회전하는 힘을 가한다
}
//회전 멈춤, 위치고정
public void StopDice()
{
this.rb.isKinematic = true;
this.transform.DOMove(new Vector3(0, 2.5f, 0), 2f).SetEase(Ease.OutCirc);
Quaternion targetRotation = Quaternion.Euler(0f, -24.752f, 0f);
this.transform.DORotate(targetRotation.eulerAngles, 0.01f).SetEase(Ease.OutCirc);
}
//percentage(확률 컨트롤)
public void GradePercentage()
{
int ranGrade=Random.Range(0,3);
this.eRewardGrade = (ErewardGrade)ranGrade;
//Debug.LogFormat("Grade:{0}", this.eRewardGrade);
//소모아이템 frame은 Iron으로 고정
if (this.eRewardType == ErewardType.OneFood || this.eRewardType == ErewardType.FullFood)
{
this.eRewardGrade=ErewardGrade.Iron;
}
}
public void TypePercentage()
{
int ranType = Random.Range(0, 5);
this.eRewardType = (ErewardType)ranType;
//Debug.LogFormat("Type:{0}", this.eRewardType);
}
public string ResultIcon()
{
var resultGrade = this.eRewardGrade.ToString();
var resultType = this.eRewardType.ToString();
var resultIcon = resultGrade + "_" + resultType;
if (resultType == "FullFood" || resultType == "OneFood")
{
resultIcon = resultType;
}
//Debug.LogFormat("<Color=red>resultIcon:{0}</Color>", resultIcon);
return resultIcon;
}
public void ShowResultIcon()
{
var resultSprite = this.resultImg[0].GetComponent<SpriteRenderer>(); //Icon
var resultSpriteAtlas = AtlasManager.instance.GetAtlasByName("UIEquipmentIcon");
//Debug.LogFormat("ResultIcon:{0}", ResultIcon());
resultSprite.sprite = resultSpriteAtlas.GetSprite(ResultIcon());
this.resultImg[0].gameObject.transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
this.ShoewResultFrame();
}
public void ShoewResultFrame()
{
Color woodFrame = new Color();
ColorUtility.TryParseHtmlString("#B05200",out woodFrame);
Color ironFrame=new Color();
ColorUtility.TryParseHtmlString("#C0B2A6", out ironFrame);
Color goldFrame=new Color();
ColorUtility.TryParseHtmlString("#FFEE00",out goldFrame);
Color diamondFrame = new Color();
ColorUtility.TryParseHtmlString("#00FFBC",out diamondFrame);
var resultFrame=this.resultImg[1].GetComponent<SpriteRenderer>();
switch (this.eRewardGrade)
{
case ErewardGrade.Wood:
//Debug.LogFormat("{0}", woodFrame);
resultFrame.color = woodFrame;
break;
case ErewardGrade.Iron:
//Debug.LogFormat("{0}", ironFrame);
resultFrame.color = ironFrame;
break;
case ErewardGrade.Gold:
//Debug.LogFormat("{0}", goldFrame);
resultFrame.color = goldFrame;
break;
case ErewardGrade.Diamond:
//Debug.LogFormat("{0}", diamondFrame);
resultFrame.color = diamondFrame;
break;
}
}
//스프라이트 이미지 교체(확률 컨트롤이 필요함)
public void DiceResultImg()
{
this.resultImg[0].gameObject.SetActive(true); //Icon ->Type
this.resultImg[1].gameObject.SetActive(true); //Frame ->Grade
this.resultImg[2].gameObject.SetActive(false); //InitIcon
this.ShowResultIcon();
}
public void DiceResultImgInit()
{
this.resultImg[0].gameObject.SetActive(false); //Icon
this.resultImg[1].gameObject.SetActive(false); //Frame
this.resultImg[2].gameObject.SetActive(true); //InitIcon
}
}
*DiceScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class UIdiceResultPopup : MonoBehaviour
{
public DiceScript diceGo;
public void Init()
{
this.gameObject.SetActive(false);
}
public void ResultPopup()
{
var resultIcon = this.diceGo.resultImg[0];
var resultFrame = this.diceGo.resultImg[1];
}
}
*완성
'게임클라이언트 프로그래밍 > Guns N Rachel's' 카테고리의 다른 글
DataTable 제작 중 2 (0) | 2023.04.18 |
---|---|
1 Stage Boss 제작 중 (0) | 2023.04.17 |
DataTable 제작 중 1 (0) | 2023.04.15 |
Stage 1 보스 기획 (0) | 2023.04.11 |
UI Shop 화면 구성 수정 (1) | 2023.04.11 |