summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/UI/Panel/PanelTopStuffBar/UIDecorationBar.cs
blob: 6dce38489131cd81903a68d51022fd9c0f84326e (plain)
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIDecorationBar : MonoBehaviour
{
	public UIDecorationWidget m_DecorationTemplate;

	public UISimpleGrid m_DecorationGrid;

	private List<UIDecorationWidget> m_Decorations = new List<UIDecorationWidget>();

	public void Set()
	{
		m_DecorationTemplate.gameObject.SetActive(false);

		for (int i = 0; i < PlayerManager.Instance.decorations.Count; ++i)
		{
			UIDecorationWidget widget = MakeDecorationWidget(PlayerManager.Instance.decorations[i]);
			m_Decorations.Add(widget);
		}
	}

	UIDecorationWidget MakeDecorationWidget(DecorationBase decoration)
	{
		UIDecorationWidget widget = Instantiate<UIDecorationWidget>(m_DecorationTemplate);
		widget.transform.SetParent(m_DecorationGrid.transform);
		widget.gameObject.SetActive(true);
		widget.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
#if UNITY_EDITOR
		widget.name = "decoration (" + decoration.name + ")";
#endif

		UIDecorationWidgetParam param = new UIDecorationWidgetParam();
		param.decoration = decoration;
		widget.Set(param);
		return widget;
	}



}