Example #1
0
        private void LoadXMLDocument(string fileName, string xml)
        {
            XmlDocument       xmlDoc  = new XmlDocument();
            XmlReaderSettings setting = new XmlReaderSettings();

            setting.IgnoreComments   = true;
            setting.IgnoreWhitespace = true;
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
            XmlReader    reader = XmlReader.Create(stream, setting);

            xmlDoc.Load(reader);
            XmlNode node = xmlDoc.FirstChild;

            do
            {
                node = node.NextSibling;
            }while (node.NodeType == XmlNodeType.Comment);

            string type = node.Attributes["type"].Value;

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            Type refType = assembly.GetType("Core.Template." + type);

            if (refType != null)
            {
                XmlNodeList          nodeList = node.ChildNodes;
                List <PrototypeData> dataList = null;

                for (int i = 0; i < nodeList.Count; i++)
                {
                    XmlNode childNode = nodeList[i];

                    if (childNode.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }

                    PrototypeData prototypeData = System.Activator.CreateInstance(refType) as PrototypeData;
                    prototypeData.LoadData(childNode);
                    if (dicData.ContainsKey(prototypeData.mPrototypeID) == false)
                    {
                        dicData.Add(prototypeData.mPrototypeID, prototypeData);
                        if (!mAllPrototyByType.TryGetValue(type, out dataList))
                        {
                            dataList = new List <PrototypeData>();
                            mAllPrototyByType.Add(type, dataList);
                        }
                        dataList.Add(prototypeData);
                    }
                    else
                    {
                        GameDebug.LogError(fileName + "表有重复ID=" + prototypeData.mPrototypeID);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 返回当前大类型下的全部对象.
        /// </summary>
        /// <returns>The data by main I.</returns>
        /// <param name="mainID">Main I.</param>
        public List <PrototypeData> GetDataByMainID(int mainID)
        {
            if (dicData == null || dicData.Count <= 0)
            {
                return(null);
            }
            List <PrototypeData> lst = new List <PrototypeData>();

            foreach (KeyValuePair <int, PrototypeData> element in dicData)
            {
                if (PrototypeData.GetMainID(element.Key) == mainID)
                {
                    lst.Add(element.Value);
                }
            }
            return(lst);
        }
Example #3
0
 public T GetPrototype <T>(int prototypeID) where T : PrototypeData
 {
     try
     {
         PrototypeData prototypeData = null;
         if (dicData.TryGetValue(prototypeID, out prototypeData))
         {
             if (prototypeData == null)
             {
                 return(null);
             }
             return(prototypeData as T);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }