Beispiel #1
0
    public SkillData GetDataById(object id)
    {
        IDataBean dataBean = _GetDataById(id);

        if (dataBean != null)
        {
            return((SkillData)dataBean);
        }
        else
        {
            return(null);
        }
    }
Beispiel #2
0
    public skillTabBean GetDataById(object id)
    {
        IDataBean dataBean = _GetDataById(id);

        if (dataBean != null)
        {
            return((skillTabBean)dataBean);
        }
        else
        {
            return(null);
        }
    }
Beispiel #3
0
    public UserInfoBean GetDataById(object id)
    {
        IDataBean dataBean = _GetDataById(id);

        if (dataBean != null)
        {
            return((UserInfoBean)dataBean);
        }
        else
        {
            return(null);
        }
    }
Beispiel #4
0
    public ChaptersData GetDataById(object id)
    {
        IDataBean dataBean = _GetDataById(id);

        if (dataBean != null)
        {
            return((ChaptersData)dataBean);
        }
        else
        {
            return(null);
        }
    }
Beispiel #5
0
        /// <summary>
        /// Inits the data.
        /// </summary>
        public void InitData()
        {
            if (isInit)
            {
                return;
            }

            Type dataBeanType = GetBeanType();

//			Debug.Log (GetXlsxPath ());

            TextAsset txt = Resources.Load(GetXlsxPath()) as TextAsset;

            string dataTxt = txt.ToString();

//			Debug.Log(dataTxt);


            dataTxt = dataTxt.Replace("\r", "");
//			dataTxt = dataTxt.Replace (" ", "");
//			dataTxt = dataTxt.Replace (" ", "");
            string[] hList = dataTxt.Split('\n');


            string title = hList [2];

            string[] titles = title.Split('\t');
            string[] types  = hList [0].Split('\t');



            for (int col = 3; col < hList.Length; col++)
            {
                IDataBean dataBean = null;
                object    key      = null;

                string[] vals = hList [col].Split('\t');

                if (vals.Length != titles.Length)
                {
                    continue;
                }



                dataBean = (IDataBean)Activator.CreateInstance(dataBeanType);
                for (int row = 0; row < titles.Length; row++)
                {
                    string titleName = titles [row];

                    if (string.IsNullOrEmpty(titleName))
                    {
                        continue;
                    }

                    string typeStr = types [row];
                    string valStr  = vals [row];

//					Debug.Log(valStr);

                    if (string.IsNullOrEmpty(typeStr))
                    {
                        continue;
                    }


//					object val = null;



                    string propertyName = titleName.Substring(0, 1).ToUpper() + titleName.Substring(1);

                    PropertyInfo prop = dataBeanType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);

                    object val = Convert.ChangeType(valStr, prop.PropertyType);

//					Debug.Log("val:"+val+"      pN:"+propertyName);
                    prop.SetValue(dataBean, val, null);

                    //set dictionary id
                    if (row == 0)
                    {
                        key = val;
                    }
                }

                if (dataBean != null)
                {
                    idDataDic.Add(key, dataBean);
                }
            }

            isInit = true;
        }
Beispiel #6
0
        /// <summary>
        /// Inits the data.
        /// </summary>
        public void loadDataFile(string prePath)
        {
            if (prePath == null)
            {
                throw new Exception("没有根据平台指定前置 路径 ");
            }
            if (isInit)
            {
                return;
            }
            //这个路径应当在 是解压之后存放的  Application.persistentDataPath 中  ;
            string filePath     = prePath + "/" + GetXlsxPath();
            Type   dataBeanType = GetBeanType();

//            FileInfo info = new FileInfo (filePath);
//            if (info == null)
//            {
//                return;
//            }
//            StreamReader fiSR = info.OpenText ();
            string dataTxt = File.ReadAllText(filePath);

            //第一行是属性类型
            //第二行是注释
            //第三行才是 标题
            try
            {
                dataTxt = dataTxt.Replace("\r", "");
                string[] hList = dataTxt.Split('\n');
                if (hList.Length > 3)
                {
                    string[] types  = hList[0].Split('\t');
                    string[] titles = hList[2].Split('\t');


                    for (int col = 3; col < hList.Length; col++)
                    {
                        IDataBean dataBean = null;
                        object    key      = null;

                        string[] vals = hList[col].Split('\t');

                        if (vals.Length != titles.Length)
                        {
                            continue;
                        }


                        dataBean = (IDataBean)Activator.CreateInstance(dataBeanType);
                        for (int row = 0; row < titles.Length; row++)
                        {
                            string titleName = titles[row];

                            if (string.IsNullOrEmpty(titleName))
                            {
                                continue;
                            }

                            string typeStr = types[row];
                            string valStr  = vals[row];


                            if (string.IsNullOrEmpty(typeStr))
                            {
                                continue;
                            }

                            string propertyName = titleName.Substring(0, 1).ToUpper() + titleName.Substring(1);

                            PropertyInfo prop =
                                dataBeanType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);

                            try
                            {
                                if (prop.PropertyType.Name != "string" && valStr == "")
                                {
                                    valStr = "0";
                                }
                                if (prop.PropertyType.Name == "Boolean" && valStr != "FALSE" && valStr != "TRUE")
                                {
                                    if (valStr == "" || valStr == "0")
                                    {
                                        valStr = "FALSE";
                                    }
                                    else
                                    {
                                        valStr = "TRUE";
                                    }
                                }
                                object val = Convert.ChangeType(valStr, prop.PropertyType);

                                prop.SetValue(dataBean, val, null);
                                //set dictionary id
                                if (row == 0)
                                {
                                    key = val;
                                }
                            }
                            catch (Exception e)
                            {
                                Debuger.LogError("waite prop error -->> " + e);
                            }
                        }

                        if (dataBean != null)
                        {
                            idDataDic.Add(key, dataBean);
                        }
                    }
                }
            }
            catch (Exception exe)
            {
                Debuger.LogError("read txt tab error -->> " + exe);
            }

            isInit = true;
        }