12.18 인벤토리만들기
C#/실습 2019. 12. 18. 16:48Scene: TestPopup
코드:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json;
using System.IO;
public class TestHQ : MonoBehaviour
{
public UIPopup_SelectedStage popup_SelectedStage;
public Button stageBtn;
public Image dim;
public List<UserItem> userItems = new List<UserItem>();
UserItem[] arrUserItems;
ItemData[] ItemDatas;
private void Awake()
{
ItemDatas = JsonConvert.DeserializeObject<ItemData[]>(json); // 아이템 row 데이터 로드
{
Debug.Log("Real user Items");
arrUserItems = JsonConvert.DeserializeObject<UserItem[]>(userItemJson);
foreach(UserItem userItem in arrUserItems)
{
}
}
else//기존 유저 아이템 파일이 없다면
{
Debug.Log("Sample user Items");
arrUserItems = new UserItem[3];
arrUserItems[0] = new UserItem(ItemDatas[0].id, ItemDatas[0].name, ItemDatas[0].iconName, 2);
arrUserItems[1] = new UserItem(ItemDatas[1].id, ItemDatas[1].name, ItemDatas[1].iconName, 2);
arrUserItems[2] = new UserItem(ItemDatas[2].id, ItemDatas[2].name, ItemDatas[2].iconName, 2);
foreach (UserItem userItem in arrUserItems)
{
}
}
}
void Start()
{
stageBtn.onClick.AddListener(() =>
{
dim.gameObject.SetActive(true);
});
popup_SelectedStage.closeBtn.onClick.AddListener(() =>
{
dim.gameObject.SetActive(false);
});
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemData
{
public int id;
public string name;
public string iconName;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
public class UIPopup_SelectedStage : MonoBehaviour
{
public Button closeBtn;
public Text text;
UserInfo userInfo;
public InventoryItems[] inventoryItems;
public SpriteAtlas atlas;
public void Init(UserInfo userInfo, List<UserItem> userItems)
{
{
if(i<9)
{
}
else
{
}
}
this.userInfo = userInfo;
this.text.text = "UserName: \t" + userInfo.userName + "\n Attack: \t\t" + userInfo.atk + "\n Defense: \t" + userInfo.def + "\n Health: \t\t" + userInfo.hp;
{
inventoryItems[i].iconStatus = eItemIconStatus.have;
inventoryItems[i].userItems = userItems[i];
inventoryItems[i].gameObject.transform.GetChild(1).gameObject.transform.GetChild(0).GetComponent<Text>().text = inventoryItems[i].userItems.count.ToString();
}
{
switch(inventoryItems[i].iconStatus)
{
{
inventoryItems[i].gameObject.GetComponent<Image>().sprite = Instantiate(Resources.Load<Sprite>("MyInfo/inventory_item_lock"));
inventoryItems[i].gameObject.transform.GetChild(0).gameObject.SetActive(false);
inventoryItems[i].gameObject.transform.GetChild(1).gameObject.SetActive(false);
break;
}
{
{
string iconName = string.Format("MyInfo/{0}",inventoryItems[j].userItems.iconName);
inventoryItems[j].gameObject.transform.GetChild(0).gameObject.GetComponent<Image>().sprite = Instantiate(Resources.Load<Sprite>(iconName));
}
break;
}
{
inventoryItems[i].gameObject.GetComponent<Image>().sprite = Instantiate(Resources.Load<Sprite>("MyInfo/inventory_item_bg"));
inventoryItems[i].gameObject.transform.GetChild(0).gameObject.SetActive(false);
inventoryItems[i].gameObject.transform.GetChild(1).gameObject.SetActive(false);
break;
}
}
}
}
public void Show()
{
this.gameObject.SetActive(true);
}
public void Hide()
{
this.gameObject.SetActive(false);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserInfo
{
public string userName;
public int level;
public int atk;
public int def;
public int hp;
public UserInfo(string userName, int level, int atk, int def, int hp)
{
this.userName = userName;
this.level = level;
this.atk = atk;
this.def = def;
this.hp = hp;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum eItemIconStatus { have, none, locked}
public class InventoryItems : MonoBehaviour
{
public eItemIconStatus iconStatus;
public UserItem userItems;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserItem
{
public int id;
public string name;
public string iconName;
public int count;
public UserItem(int id, string name, string iconName, int count)
{
this.id = id;
this.name = name;
this.iconName = iconName;
this.count = count;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'C# > 실습' 카테고리의 다른 글
12.17 Unity Editor 활용해 실시간으로 Json 파일 만들기 (0) | 2019.12.17 |
---|---|
12.16 UI 버튼 만들기 (0) | 2019.12.16 |
12.13 캐릭터 선택하기(랜덤포함) (0) | 2019.12.13 |
12.09 충돌감지와 sprite활용하기(delegate) (0) | 2019.12.09 |
12.06 드래곤플라이트 구현 (0) | 2019.12.06 |