public Dictionary <string, DefaultItemInfo> loadDefaultItemInfo() { if (m_bloadItemInfoState == false) { TextAsset text = Resources.Load <TextAsset>("Data/DefaultItemInfo"); // 리소스 로드를 통해 테이블을 로드한다. string content = text.text; // 한라인으로 데이터가 나열되어 있다. string[] line = content.Split('\n'); // '\n' 기준으로 분리해서 line배열에 대입 for (int i = 2; i < line.Length - 1; i++) // 2번째 라인부터 라인 갯수만큼 테이블 생성 (마지막NULL 한칸 제외해서 -1라인) { string[] column = line[i].Split(','); // 쉼표로 구분해 column배열에 넣는다. SCV파일은 ,로 구분되어 있으므로 DefaultItemInfo table = new DefaultItemInfo(); // 디폴트 테이블 정보를 담을 변수 생성 int index = 0; // 0번째 열부터 시작 string itemName = column[index++].Replace("\r", ""); // 저장 후 인덱스를 계속 증가시켜 읽는다. table.m_strName = column[index++].Replace("\r", ""); table.m_strExplain = column[index++].Replace("\r", ""); table.m_eType = (ITEM_TYPE)int.Parse(column[index++]); table.m_iValue = int.Parse(column[index++]); table.m_iBuyGold = int.Parse(column[index++]); m_dicDefaultItemInfo.Add(itemName, table); // 딕셔너리에 테이블 생성정보 삽입 } m_bloadItemInfoState = true; } return(m_dicDefaultItemInfo); }
private bool m_bVisibleCamera; // 카메라 안에 포함 되어 있는지 여부 // Start is called before the first frame update void Start() { m_uiCamera = GameObject.Find("NGUICamera").GetComponent <Camera>(); m_strItemImageName = "W_Sword00" + Random.Range(1, 3); // 아이템 이름을 랜덤으로 설정해서 1~2범위 m_itemInfo = DefaultDataManager.instance.m_dicDefaultItemInfo[m_strItemImageName]; // 딕셔너리에서 이름에 해당하는 아이템 정보를 받아와 저장함 m_trsPlayer = GameObject.Find("Player").GetComponent <Transform>(); // 플레이어의 좌표 }
private void explainItem() // 아이템 설명창 { if (Input.GetMouseButtonDown(0) == true) // 마우스를 클릭하면 { foreach (UIButton iterator in m_lnkLstInventoryItemButton) // 버튼 반복자로 링크드리스트를 순회 { if (iterator.state == UIButtonColor.State.Pressed) // 눌러저 있는 버튼을 찾은 경우 { DefaultItemInfo iteminfo = m_dicDefaultItemInfo[iterator.normalSprite]; // 눌러진 아이템 이미지에 맞는 정보를 찾음 if (iteminfo != null) // 정보가 있다면 { m_explainItem.gameObject.SetActive(true); // 아이템 설명창 상태 활성화 string typeExplain = null; m_explainItem.transform.position = iterator.transform.position + new Vector3(0.3f, -0.3f, 0); // 아이템 설명창 위치 설정 if (iteminfo.m_eType == ITEM_TYPE.WEAPON) // 아이템 타입에 따라 설명을 다르게 함 { typeExplain = "\n타입 : 무기\n공격력 : " + iteminfo.m_iValue; } else if (iteminfo.m_eType == ITEM_TYPE.ARMOR) { typeExplain = "\n타입 : 방어구\n방어력 : " + iteminfo.m_iValue; } else if (iteminfo.m_eType == ITEM_TYPE.POTION) { typeExplain = "\n타입 : 물약\n회복력 : " + iteminfo.m_iValue; } m_explainLabel.text = "이름 : " + iteminfo.m_strName + typeExplain + "\n설명 : " + iteminfo.m_strExplain + "\n구매가격 : " + iteminfo.m_iBuyGold; break; // 아이템 설명창은 1개면 충분하므로 리스트 순회를 중단 } } } foreach (KeyValuePair <string, UIButton> iterator in m_dicShopItemButton) // 반복자로 딕셔너리를 순회하면서 { if (iterator.Value.state == UIButtonColor.State.Pressed) // 눌러저 있는 버튼을 찾은 경우 { DefaultItemInfo iteminfo = m_dicDefaultItemInfo[iterator.Value.normalSprite]; // 눌러진 아이템 이미지에 맞는 정보를 찾음 if (iteminfo != null) // 정보가 있다면 { m_explainItem.gameObject.SetActive(true); // 아이템 설명창 상태 활성화 string typeExplain = null; m_explainItem.transform.position = iterator.Value.transform.position + new Vector3(0.3f, -0.3f, 0); // 아이템 설명창 위치 설정 if (iteminfo.m_eType == ITEM_TYPE.WEAPON) // 아이템 타입에 따라 설명을 다르게 함 { typeExplain = "\n타입 : 무기\n공격력 : " + iteminfo.m_iValue; } else if (iteminfo.m_eType == ITEM_TYPE.ARMOR) { typeExplain = "\n타입 : 방어구\n방어력 : " + iteminfo.m_iValue; } else if (iteminfo.m_eType == ITEM_TYPE.POTION) { typeExplain = "\n타입 : 물약\n회복력 : " + iteminfo.m_iValue; } m_explainLabel.text = "이름 : " + iteminfo.m_strName + typeExplain + "\n설명 : " + iteminfo.m_strExplain + "\n구매가격 : " + iteminfo.m_iBuyGold; break; // 아이템 설명창은 1개면 충분하므로 리스트 순회를 중단 } } } } else if (Input.GetMouseButtonUp(0) == true) // 마우스를 뗀 경우 { m_explainItem.gameObject.SetActive(false); // 설명창 비활성화 } }