void Awake() { _resourceTypeList = Resources.Load <ResourceTypeListSO>(nameof(ResourceTypeListSO)); _resourceTypeTransformDictionary = new Dictionary <ResourceTypeSO, Transform>(); Transform resourceTemplate = transform.Find("resourceTemplate"); resourceTemplate.gameObject.SetActive(false); int index = 0; foreach (ResourceTypeSO resourceType in _resourceTypeList.list) { // Create new gameobjects Transform resourceTransform = Instantiate(resourceTemplate, transform); resourceTransform.gameObject.SetActive(true); // Place gameobjects float offsetAmount = -160f; resourceTransform.GetComponent <RectTransform>().anchoredPosition = new Vector2(offsetAmount * index, 0); // Get the correct images, from a field in the scriptable objects! resourceTransform.Find("image").GetComponent <Image>().sprite = resourceType.sprite; // Cache the information to bring into other method. Needs to be called after Start() _resourceTypeTransformDictionary[resourceType] = resourceTransform; index++; } }
private void Awake() { _resourceTypeList = Resources.Load <ResourceTypeListSO>(nameof(ResourceTypeListSO)); resourceTypeTransformDictionary = new Dictionary <ResourceTypeSO, Transform>(); Transform resourceTemplate = transform.Find("resourceTemplate"); resourceTemplate.gameObject.SetActive(false); int index = 0; foreach (ResourceTypeSO resourceType in _resourceTypeList.list) { Transform resourceTransform = Instantiate(resourceTemplate, this.transform); resourceTransform.gameObject.SetActive(true); resourceTransform.GetComponent <RectTransform>().anchoredPosition = new Vector2(offset * index, 0f); resourceTransform.Find("image").GetComponent <Image>().sprite = resourceType.sprite; resourceTypeTransformDictionary[resourceType] = resourceTransform; ++index; } }
private void Awake() { resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); Transform resourceTemplate = transform.Find("resourceTemplate"); resourceTemplate.gameObject.SetActive(false); int index = 0; foreach (ResourceTypeSO resourceType in resourceTypeList.list) { Transform resourceTransform = Instantiate(resourceTemplate, transform); resourceTransform.gameObject.SetActive(true); float offsetAmount = -160f; resourceTransform.GetComponent <RectTransform>().anchoredPosition = new Vector2(offsetAmount * index, 0); resourceTransform.Find("image").GetComponent <Image>().sprite = resourceType.sprite; resourceTypeTransformDictionary[resourceType] = resourceTransform; index++; } }
private void Awake() { resTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); resTypeTrmDict = new Dictionary <ResourceTypeSO, Transform>(); Transform resTmpTrm = transform.Find("resourceTemplate"); resTmpTrm.gameObject.SetActive(false); int idx = 0; foreach (var item in resTypeList.resList) { // 생성 및 활성화 Transform resTrn = Instantiate(resTmpTrm, transform); resTrn.gameObject.SetActive(true); // 위치 적용 float offsetAmount = -160f; resTrn.GetComponent <RectTransform>().anchoredPosition = new Vector2(offsetAmount * idx, 0); // 이미지 적용 resTrn.Find("image").GetComponent <Image>().sprite = item.sprite; resTypeTrmDict[item] = resTrn; idx++; } }
private void Awake() { //加载所有资源类型 resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); resourceTypeTransformDictionary = new Dictionary <ResourceTypeSO, Transform>(); //找到自己的子物体UI Transform resourceTemplate = transform.Find("resourceTemplate"); //设置禁用游戏物体隐藏 resourceTemplate.gameObject.SetActive(false); int index = 0; foreach (ResourceTypeSO resourceType in resourceTypeList.list) { //生成实例 Transform resourceTransform = Instantiate(resourceTemplate, transform); resourceTransform.gameObject.SetActive(true); //设置生成的资源UI实例位置点 float offsetAmount = -160f; resourceTransform.GetComponent <RectTransform>().anchoredPosition = new Vector2(offsetAmount * index, 0); //设置生成的资源UI实例的精灵图片 resourceTransform.Find("image").GetComponent <Image>().sprite = resourceType.sprite; //将生成的资源UI实例加入 map字典中 resourceTypeTransformDictionary[resourceType] = resourceTransform; index++; } }
private void Update() { if (Input.GetKeyDown(KeyCode.T)) { ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); AddResource(resourceTypeList.list[1], 2); TestLogResourceAmountDictionary(); } }
// Update is called once per frame private void Update() { //Testing if it works add resources if (Input.GetKeyDown(KeyCode.Space)) { ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); addResource(resourceTypeList.getResourcesTypeList()[0], 1); TestLogDic(); } }
private void Awake() { //Initialize the dictionary with current types of resources and set to 0 resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); foreach (ResourceTypeSO resourceType in resourceTypeList.getResourcesTypeList()) { resourceAmountDictionary[resourceType] = 0; } }
private void Awake() { Instance = this; resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); foreach (ResourceTypeSO resourceType in resourceTypeList.list) { resourceAmountDictionary[resourceType] = 0; } }
private void Awake() { Instance = this; _resourceAmounts = new Dictionary <ResourceTypeSO, int>(); resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); // Iterate each predefined type and set value to zero on awake foreach (var resourceType in resourceTypeList.list) { _resourceAmounts.Add(resourceType, 0); } }
private void Awake() { Instance = this; resourceAmountDic = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); foreach (ResourceTypeSO resType in resTypeList.resList) { resourceAmountDic[resType] = 0; } TestLogResAmountDic(); }
private void Awake() { Instance = this; _resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(nameof(ResourceTypeListSO)); foreach (ResourceTypeSO resourceType in resourceTypeList.list) { _resourceAmountDictionary[resourceType] = 0; } TestLogResourceAmountDictionary(); }
private void Awake() { Instance = this; //初始化map resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); //加载资源集合list ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); //遍历资源集合,然后添加到 map中,key为资源类,value为资源的数量 foreach (ResourceTypeSO resourceType in resourceTypeList.list) { resourceAmountDictionary[resourceType] = 0; } }
void Awake() { Instance = this; _resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(nameof(ResourceTypeListSO)); foreach (ResourceTypeSO resourceType in resourceTypeList.list) { _resourceAmountDictionary[resourceType] = 0; } foreach (ResourceAmount resourceAmount in startingResourceAmountList) { AddResource(resourceAmount.resourceType, resourceAmount.amount); } }
private void Awake() { Instance = this; resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); foreach (ResourceTypeSO resourceType in resourceTypeList.list) { resourceAmountDictionary[resourceType] = 0; } // DEVMOD foreach (ResourceAmount resourceAmount in startingResouceAmountList) { AddResource(resourceAmount.resourceType, resourceAmount.amount); } // END }
private void Awake() { Instance = this; resourceAmountDic = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); foreach (ResourceTypeSO resType in resTypeList.resList) { resourceAmountDic[resType] = 0; } foreach (var item in startingResAmount) { AddResource(item.resourceType, item.amount); } //TestLogResAmountDic(); }
private void Awake() { resourceTypeList = Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name); resourceTemplate.gameObject.SetActive(false); resourceTypeTransformDictionary = new Dictionary <ResourceTypeSO, Transform>(); int index = 0; foreach (ResourceTypeSO resourceType in resourceTypeList.list) { Transform resourceTransform = Instantiate(resourceTemplate, transform); resourceTransform.gameObject.SetActive(true); resourceTypeTransformDictionary[resourceType] = resourceTransform; float offsetAmount = -145f; resourceTransform.GetComponent <RectTransform>().anchoredPosition = new Vector2(offsetAmount * index, 0); resourceTransform.GetChild(0).GetComponent <Image>().sprite = resourceType.sprite; index++; } ResourceManager.Instance.OnResourceChangedEvent += ResourceUIListenTo_OnResourceChangedEvent; }
private void Awake() { resourceTypeList = (Resources.Load <ResourceTypeListSO>(typeof(ResourceTypeListSO).Name)); resourceTypeTransform = new Dictionary <ResourceTypeSO, Transform>(); Transform resourceTemplate = transform.Find("resourceTemplate"); resourceTemplate.gameObject.SetActive(false); Transform wood = Instantiate(resourceTemplate, transform); wood.gameObject.SetActive(true); wood.GetComponent <RectTransform>().anchoredPosition = new Vector2(-160, 0); wood.Find("image").GetComponent <Image>().sprite = resourceTypeList.list[0].sprite; resourceTypeTransform[resourceTypeList.list[0]] = wood; Transform stone = Instantiate(resourceTemplate, transform); stone.gameObject.SetActive(true); stone.GetComponent <RectTransform>().anchoredPosition = new Vector2(-300, 0); wood.Find("image").GetComponent <Image>().sprite = resourceTypeList.list[1].sprite; resourceTypeTransform[resourceTypeList.list[1]] = stone; }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this); } else { _instance = this; } resourceAmountDictionary = new Dictionary <ResourceTypeSO, int>(); ResourceTypeListSO resourceTypeList = Resources.Load <ResourceTypeListSO>(nameof(ResourceTypeListSO)); foreach (ResourceTypeSO resourceType in resourceTypeList.list) { resourceAmountDictionary[resourceType] = 0; } TestLogResourceAmountDictionary(); }
private void Awake() { monsterResourceList = Resources.Load <ResourceTypeListSO>(monsterName + "PartList"); textList = GetComponentsInChildren <TextMeshProUGUI>(); }