μƒˆμ†Œμ‹

κ²Œμž„μ—”μ§„/Unity

[Unity3D] μ‹€μ œ μ‹œκ°„μ— λ”°λ₯Έ UI κ²Œμ΄μ§€ λ°” 변경에 λŒ€ν•œ κ³ μ°°

  • -
728x90

μΏ ν‚€λŸ° ν‚Ήλ€μ΄λ‚˜ 기타 λ‹€λ₯Έ λ°©μΉ˜ν˜• κ²Œμž„λ“€μ—μ„œ 보톡 μ œμž‘ν•˜λŠ” 일정 μ‹œκ°„μ΄ μ§€λ‚˜λ©΄ 보상을 받을 수 μžˆλŠ” μ‹œμŠ€ν…œμ„ κ°œλ°œν•˜κ³  μ‹Άμ—ˆλ‹€.

λ¬Όλ‘  μ„œλ²„ μ‹œκ°„μ„ κ°€μ Έμ˜€λŠ”κ²Œ λ² μŠ€νŠΈκ² μ§€λ§Œ 일단은 λ‚΄μž₯된 μ‹œκ°„μœΌλ‘œ κ΅¬ν˜„ν•΄λ³΄λ €κ³  ν•œλ‹€.

λ‚˜μ€‘μ—λŠ” μ–΄λ”” μ„œλ²„ μ‹œκ°„μ„ κ°€μ Έμ˜¬ 수 μžˆλ„λ‘ λ³€κ²½ν•  것이닀.

λ§Œμ•½ ν•Έλ“œν° μ‹œκ°„μ„ κ°€μ Έμ˜¬ 경우 μ‚¬λžŒλ“€μ΄ μž„μ˜λ‘œ ν•Έλ“œν° μ‹œκ°„μ„ λ³€κ²½ν•˜μ—¬μ„œ 이득을 μ·¨ν•˜λŠ” ν˜•νƒœκ°€ 될것이닀 - 예λ₯Ό λ“€μžλ©΄ λ‹Œν…λ„ λ™μˆ²μ˜ 무 μ‹œμŠ€ν…œ 같은 경우

 

λŒ€μΆ© νƒν—˜ μ‹œμŠ€ν…œμ΄ 있고 νƒν—˜ λ²„νŠΌμ„ λˆ„λ₯΄λ©΄ λ‚΄κ°€ νƒν—˜μ„ μ‹œμž‘ν•œ μ‹€μ œ μ‹œκ°„μ΄ μ €μž₯λ˜λ„λ‘ ν•˜λ €κ³  ν•œλ‹€.

 

public void SaveExplore(float exploreHour, float exploreMinutes)
{
    PlayerPrefs.SetFloat("exploreHour", exploreHour);
    PlayerPrefs.SetFloat("exoloreMinutes", exploreMinutes);
}

 

νƒν—˜ λ²„νŠΌμ΄ 클릭되면 μ΄λŸ¬ν•œ λŠλ‚ŒμœΌλ‘œ μœ λ‹ˆν‹°μ˜ Player Preference에 μ €μž₯을 ν•΄μ€€λ‹€.

PlayerPrefs라고 λΆ€λ₯΄λŠ”데 μžμ„Έν•œ λ‚΄μš©μ€ docsλ₯Ό 참고해보면 쒋을 것 κ°™λ‹€.

https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

 

Unity - Scripting API: PlayerPrefs

Unity stores `PlayerPrefs` data differently based on which operating system the application runs on. In the file paths given on this page, the company name and product name are the names you set in Unity’s Player Settings. Standalone Player storage locat

docs.unity3d.com

 

일단 UNITY EDITORμ—μ„œμ˜ ν˜„μž¬ μ‹œκ°„μ„ λΆˆλŸ¬μ™€λ³΄λ €κ³  ν•œλ‹€.

Debug.Log(DateTime.Now.ToString());			//λ…„,μ›”,일,μ‹œ,λΆ„,초 ν‘œμ‹œ
Debug.Log(DateTime.Now.Year.ToString());		//λ…„ ν‘œμ‹œ
Debug.Log(DateTime.Now.Month.ToString());		//μ›” ν‘œμ‹œ
Debug.Log(DateTime.Now.Day.ToString());			//일 ν‘œμ‹œ
Debug.Log(DateTime.Now.Hour.ToString());		//μ‹œ ν‘œμ‹œ
Debug.Log(DateTime.Now.Minute.ToString());		//λΆ„ ν‘œμ‹œ

 

DateTime 클래슀λ₯Ό μ΄μš©ν•΄μ„œ λΆˆλŸ¬μ˜€λ„λ‘ ν•˜κ³  λ§€ν”„λ ˆμž„λ§ˆλ‹€ μ—°λ™ν•˜λŠ”κ±΄ 아닐것 같은데..

일단은 λ§€ν”„λ ˆμž„ λ§ˆλ‹€ μ‹œκ°„μ„ λ°›μ•„μ™€μ„œ 계산을 해보도둝 ν•˜κ² λ‹€.

λ§Œμ•½ λ‚˜μ€‘μ— ν”„λ ˆμž„ μ €ν•˜κ°€ μΌμ–΄λ‚œλ‹€λ©΄ λ‹€μ‹œ μˆ˜μ •ν•΄μ•Όν•  것같닀.

 

//νƒν—˜ μ‹œμž‘ ν•¨μˆ˜λ₯Ό call ν•  μ‹œ ν•΄λ‹Ήλ˜λŠ” ν•¨μˆ˜ call νƒν—˜μ •λ³΄λ₯Ό λ°˜ν™˜ν•¨
//exploreKindNum : νƒν—˜ μ’…λ₯˜ 번호
public exploreInfo exploreStart(int exploreKindNum)
{
     explInfo = new exploreInfo(DateTime.Now.Hour, DateTime.Now.Minute, costExplore[exploreKindNum]);
     return explInfo;
}
//νƒν—˜ μ‹œμž‘
public void exploreStart(int exploreKindNum)
{
    explInfo = exploreM.exploreStart(exploreKindNum);
    //νƒν—˜ μ‹œμž‘ μ‹œκ°„ μ €μž₯(μΆ” ν›„ 년도 μš”μΌκΉŒμ§€ μ €μž₯ν•΄μ€˜μ•Όν•¨)
    saveM.SaveExplore(explInfo.hour, explInfo.minute, explInfo.costMinute, 1);

    //UI λ§€λ‹ˆμ €μ—κ²Œ ExploreGuage μ—…λ°μ΄νŠΈ ν•  수 μžˆλ„λ‘ μ΄ˆκΈ°κ°’ λ„£μ–΄μ€Œ
    uiM.updateExploreGuage(explInfo);
}

그리고 λ§Œμ•½ νƒν—˜μ€‘μ΄λΌλ©΄ UIλ₯Ό νƒν—˜ 정보 기반으둜 계속 μ—…λ°μ΄νŠΈ ν•΄μ€˜μ•Όν•œλ‹€.

//λ§Œμ•½ νƒν—˜μ΄ μ‹œμž‘λ˜μ—ˆλ‹€λ©΄
if (explInfo.isExplore==1)
{
    uiM.updateExploreGuage(explInfo);
}
public void updateExploreGuage(exploreInfo explInfo)
{
    //남은 μ‹œκ°„ 계산
    //총 μ‹œκ°„(λΆ„)
    float exploreTime = explInfo.hour * 60.0f + explInfo.minute;
    float remainTime = (DateTime.Now.Hour - explInfo.hour) * 60.0f + (DateTime.Now.Minute - explInfo.minute);

    explRemainTimeTxt.text = (explInfo.costMinute-remainTime).ToString()+"λΆ„";

    imgExploreGuage.fillAmount = remainTime / explInfo.costMinute;
}

μ΄λ ‡κ²Œ ν•˜λ©΄ μ‹œμŠ€ν…œ λΆ„λ§ˆλ‹€ νƒν—˜ κ²Œμ΄μ§€κ°€ λ³€κ²½λ˜λŠ” 것을 확인할 수 μžˆλ‹€.

 

 

μ§€κΈˆμ€ 5λΆ„ 기쀀인데 μ§€κΈˆμ˜ μ½”λ“œλŠ” λΆ„λ‹¨μœ„λ‘œ 좜λ ₯되게 λ˜μ–΄μžˆμ–΄μ„œ ~μ‹œ~λΆ„μœΌλ‘œ 좜λ ₯될 수 μžˆλ„λ‘ λ³€κ²½ν•΄μ•Όκ² λ‹€.

그리고 λΆ„λ§ˆλ‹€ μ—…λ°μ΄νŠΈ λ˜λŠ”κ²Œ λ³΄μ΄λŠ”λ° λ„ˆλ¬΄ μ§€λ£¨ν•΄μ„œ λ‹€λ₯Έ μ‹œμŠ€ν…œλ“€ 처럼 μ΄ˆλ§ˆλ‹€ λ³΄μ΄λŠ” κ²ƒμœΌλ‘œ λ³€κ²½ν•΄μ•Όκ² λ‹€.

λ˜ν•œ μ§€κΈˆμ€ μœˆλ„μš° μ‹œμŠ€ν…œ μ‹œκ°„μ„ κ°€μ Έμ˜€λŠ”λ° λ§Œμ•½ μ•ˆλ“œλ‘œμ΄λ“œμ— λ“€μ–΄κ°€μ„œ μ‹œκ°„μ„ μž¬λŠ” 경우 λ‹€λ₯΄κ²Œ μž¬μ•Όν•  μˆ˜λ„ 있기 λ•Œλ¬Έμ—(μ„œλ²„ μ‹œκ°„μ„ λΆˆλŸ¬μ˜€λŠ”κ²Œ 제일 쒋을 λ“― ν•˜λ‹€) μ’€ 더 μˆ˜μ •μ΄ ν•„μš”ν•  것 κ°™λ‹€.

λ§Œμ•½ 더 μΆ”κ°€ν•˜κ²Œ λœλ‹€λ©΄ μΆ” ν›„ λΈ”λ‘œκ·Έ 글을 μˆ˜μ •λ³΄μ™„ν•˜λ €κ³  ν•œλ‹€.

λ°˜μ‘ν˜•
Contents

ν¬μŠ€νŒ… μ£Όμ†Œλ₯Ό λ³΅μ‚¬ν–ˆμŠ΅λ‹ˆλ‹€

이 글이 도움이 λ˜μ—ˆλ‹€λ©΄ 곡감 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€.