Пример #1
0
 public static void SetData(ushort _id, Voxel _data)
 {
     if (m_DataTable.ContainsKey(_id))
     {
         m_DataTable[_id] = _data;
     }
     else
     {
         m_DataTable.Add(_id, _data);
     }
 }
Пример #2
0
        /// <summary>
        /// Loads material data from XML file into the material data table [m_DataTable].  Will delete all existing data if it is not empty.
        /// </summary>
        /// <param name="_path">Path to XML file containing the material data</param>
        public static void LoadDataFromFile(string _path)
        {
            if (!System.IO.File.Exists(_path))
            {
                ioDebug.Log("Loading material XML file '" + _path + "' does not exist.");
                return;
            }

            ioDebug.Log("Loading " + _path + " into material table.");

            try
            {
                XmlReader xmlReader = XmlReader.Create(_path);

                if (xmlReader.EOF)
                {
                    ioDebug.Log("XML file is empty or corrupt/invalid.");
                    return;
                }

                ushort count = 0;

                while (xmlReader.Read())
                {
                    if (xmlReader.Name.Equals(TAG_TYPE) && (xmlReader.NodeType == XmlNodeType.Element))
                    {

                        ushort id = ushort.Parse(xmlReader.GetAttribute(ATR_ID));
                        string name = xmlReader.GetAttribute(ATR_NAME).Trim();
                        string desc = xmlReader.GetAttribute(ATR_DESC).Trim();
                        string isVisibleStr = xmlReader.GetAttribute(ATR_VISIBLE).ToUpper().Trim();
                        string isTranspStr = xmlReader.GetAttribute(ATR_TRANSP).ToUpper().Trim();
                        string faceTypeStr = xmlReader.GetAttribute(ATR_FACETYPE).ToUpper().Trim();

                        bool isVisible = true;
                        bool isTransp = false;

                        //Verify values are valid
                        if (!Const.IsValidBool(isVisibleStr))
                        {
                            ioDebug.Log("Error while loading material data from XML:\n   Invalid bool string '" + isVisibleStr + "' for 'IsVisible' at element '" + count + "'. Defaulting TRUE.");

                        }
                        else
                        {
                            isVisible = Const.StringToBool(isVisibleStr);
                        }

                        if (!Const.IsValidBool(isTranspStr))
                        {
                            ioDebug.Log("Error while loading material data from XML:\n   Invalid bool string '" + isTranspStr + "' for 'IsTransp' at element '" + count + "'. Defaulting FALSE.");

                        }
                        else
                        {
                            isTransp = Const.StringToBool(isTranspStr);
                        }

                        FaceType faceType = StringToFaceType(faceTypeStr);

                        Voxel data = new Voxel( id,
                                                name,
                                                desc,
                                                isVisible,
                                                isTransp,
                                                faceType);

                        m_DataTable.Add(data.id, data);
                        count++;
                    }
                }

                if (ioDebug.VERBOSE_DEBUG_ACTIVE) DebugMaterialTableToConsole();

                ioDebug.Log("Loaded " + count + " materials from '" + _path + "'.");
            }
            catch (Exception e)
            {
                //TODO
                ioDebug.Log("IsThisNeeded-" + e.StackTrace + "\n" + e.Source + " : Exception-" + e.GetBaseException().Message);
            }
        }