123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class ProductParse : MonoBehaviour
- {
- public string ID
- {
- get
- {
- return this.m_strID;
- }
- }
- public string GetName()
- {
- return this.GetData(ProductParse.KEY_NAME);
- }
- public int GetPrice()
- {
- int result;
- try
- {
- int num = -1;
- string data = this.GetData(ProductParse.KEY_PRICE);
- if (!int.TryParse(data, out num))
- {
- throw new Exception("値段のデータに不正な値が入っている\n値:" + data);
- }
- result = num;
- }
- catch (Exception ex)
- {
- NDebug.Assert(ex.Message, false);
- Debug.LogError(ex.Message);
- result = 0;
- }
- return result;
- }
- public string GetImageName()
- {
- return this.GetData(ProductParse.KEY_IMAGE);
- }
- public string GetDescription()
- {
- return this.GetData(ProductParse.KEY_DESC);
- }
- private static void InitProductList()
- {
- if (ProductParse.m_ProductList != null)
- {
- return;
- }
- ProductParse.m_ProductList = new Dictionary<string, Dictionary<string, string>>();
- Dictionary<string, string> dictionary = new Dictionary<string, string>();
- dictionary.Add(string.Empty, string.Empty);
- }
- private Dictionary<string, string> GetDataDic()
- {
- ProductParse.InitProductList();
- Dictionary<string, string> result;
- try
- {
- if (!ProductParse.m_ProductList.ContainsKey(this.m_strID))
- {
- throw new Exception("商品ID[" + this.m_strID + "]の情報が存在しない");
- }
- result = ProductParse.m_ProductList[this.m_strID];
- }
- catch (Exception ex)
- {
- NDebug.Assert(ex.Message, false);
- Debug.LogError(ex.Message);
- result = null;
- }
- return result;
- }
- private string GetData(string key)
- {
- string result;
- try
- {
- Dictionary<string, string> dataDic = this.GetDataDic();
- if (!dataDic.ContainsKey(key))
- {
- throw new Exception("商品データのキー[" + key + "]は存在しない");
- }
- result = dataDic[key];
- }
- catch (Exception ex)
- {
- NDebug.Assert(ex.Message, false);
- Debug.LogError(ex.Message);
- result = null;
- }
- return result;
- }
- private static string KEY_NAME = "name";
- private static string KEY_PRICE = "price";
- private static string KEY_IMAGE = "image";
- private static string KEY_DESC = "desc";
- private static Dictionary<string, Dictionary<string, string>> m_ProductList;
- private string m_strID;
- }
|