Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- loop
- dfs
- dynamic
- Material
- 기초
- Programming
- parameter
- 백준
- 파이썬
- W3Schools
- Unity
- String
- DP
- Class
- github
- Tutorial
- Unreal Engine 5
- 시작해요 언리얼 2022
- Basic
- guide
- 문제풀이
- Algorithm
- python
- 재귀
- w3school
- c++
- C#
- UE5
- 오류
- 프로그래밍
Archives
- Today
- Total
행복한 개구리
Unity UGUI 21.05.01 과제 겸 복습 본문


Budget들의 amount는 정상적으로 대입됐다. 하트의 1.4624...는 시간기능을 뭘 넣어야할 지 몰라서 아무거나 넣어봤는데 저런게 나왔다 ㅎ... 나중에 고칠예정(뻣뻣하게 고정된 수를 주기 싫어서 저런 기능을 넣어봤는데 실패다)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIProfile : MonoBehaviour
{
public Button btn;
public Text userName;
public Slider hp;
public Slider exp;
void Start()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserInfo
{
public int id;
public string email;
public string pw;
public string name;
public int lvl;
public int hp;
public int exp;
public int budget_id;
public UserInfo(int id, string email, string pw, string name, int lvl, int hp, int exp, int budget_id)
{
this.id = id;
this.email = email;
this.pw = pw;
this.name = name;
this.lvl = lvl;
this.hp = hp;
this.exp = exp;
this.budget_id = budget_id;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserData
{
public int id;
public int lvl;
public string name;
public int hp;
public int exp;
public int budget_id;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Linq;
public class DataManager
{
public Dictionary<int, BudgetData> dicBudgetData;
public Dictionary<int, UserData> dicUserData;
static DataManager instance;
public static DataManager GetInstance()
{
if(instance == null)
{
instance = new DataManager();
}
return instance;
}
public void LoadDatas()
{
var budgetTa = Resources.Load<TextAsset>("Datas/budget_data");
var budgetJson = budgetTa.text;
this.dicBudgetData = JsonConvert.DeserializeObject<BudgetData[]>(budgetJson).ToDictionary(x => x.id);
var userTa = Resources.Load<TextAsset>("Datas/user_data");
var userJson = userTa.text;
this.dicUserData = JsonConvert.DeserializeObject<UserData[]>(userJson).ToDictionary(x => x.id);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIItemHeartBudget : UIItemBudget
{
public Text time;
public int Max { get; set; }
public override void Init(int amount)
{
if (amount > this.Max)
{
this.amount.text = this.Max.ToString();
this.time.text = "FULL";
}
else
{
base.Init(amount);
this.time.text = Time.realtimeSinceStartup.ToString();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UILobby : MonoBehaviour
{
public UIItemBudget[] budgets;
public UIMenuItem[] menus;
public Button login;
public Button fb;
public Button profile;
enum eMenuType
{
Item, Shop, Message, Mission, Ranking, Setting
}
public enum eBudgetType
{
Heart, Coin, Gem
}
void Start()
{
Init();
}
public void Init()
{
DataManager.GetInstance().LoadDatas();
var budgetId = DataManager.GetInstance().dicUserData[3].budget_id;
var budgetData = DataManager.GetInstance().dicBudgetData[budgetId];
for (int i = 0; i < this.menus.Length; i++)
{
var btn = this.menus[i].btn;
var idx = i;
btn.onClick.AddListener(() => { Debug.Log((eMenuType)idx); });
}
var heartBudget = (UIItemHeartBudget)GetUIBudget(eBudgetType.Heart);
heartBudget.Max = 5;
heartBudget.Init(budgetData.h_amount);
var coinBudget = GetUIBudget(eBudgetType.Coin);
coinBudget.Init(budgetData.c_amount);
var gemBudget = GetUIBudget(eBudgetType.Gem);
gemBudget.Init(budgetData.g_amount);
}
public UIItemBudget GetUIBudget(eBudgetType type)
{
return this.budgets[(int)type];
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
public class UIMenuItem : MonoBehaviour
{
public Button btn;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
public class UIItemBudget : MonoBehaviour
{
public Text amount;
public Button btn;
public virtual void Init(int amount)
{
this.amount.text = amount.ToString();
this.btn.onClick.AddListener(() => { Debug.Log(amount); });
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BudgetData
{
public int id;
public int h_amount;
public int c_amount;
public int g_amount;
}
아직도 UILobby부분에서 메뉴와 자산을 불러올 때 왜 idx를 사용해야 하며 클릭시 사용하지 않았을 때랑 결과가 다른지 이해가 되지 않았다 그 외는 이젠 전부 수월하게 작성가능했고 긴장이 풀려서 그런지 많이 진행하지 않았다.
'Unity > 복습' 카테고리의 다른 글
| Unity 복습 21.05.03. 데이터 저장&불러오기 // 쉐이더 (0) | 2021.05.03 |
|---|---|
| Unity UGUI 21.05.02. 과제 겸 복습 (0) | 2021.05.02 |
| Unity 21.04.28. 개념복습 (0) | 2021.04.28 |
| Unity 개념복습 21.04.27 (0) | 2021.04.27 |
| Unity 복습 21.04.27. 데이터 저장과 불러오기 (0) | 2021.04.27 |