コード例 #1
0
        private void DebugAllConfigBtn_onClick()
        {
            TestLogData data = TestLogXmlConfig.GetData(0);

            Debug.LogFormat(
                "{0} -> Data: {1}",
                typeof(TestLogXmlConfig).Name,
                data.ToString()
                );

            data = TestLogXmlDocConfig.GetData(1);
            Debug.LogFormat(
                "{0} -> Data: {1}",
                typeof(TestLogXmlDocConfig).Name,
                data.ToString()
                );

            Debug.LogFormat(
                "{0} -> Data: {1}",
                typeof(TestLogJsonConfig).Name,
                TestLogJsonConfig.Get <TestLogJsonConfig>().data
                );

            Debug.LogFormat(
                "{0} -> Data: {1}",
                typeof(TestLogTxtConfig).Name,
                TestLogTxtConfig.Get <TestLogTxtConfig>().ToString()
                );
        }
コード例 #2
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static TestLogData GetData(int id)
        {
            TestLogXmlDocConfig config = Get <TestLogXmlDocConfig>();

            if (config == null || config.m_DataDict == null)
            {
                throw new FormatException("Config is not formated. Check the console panel.");
            }

            TestLogData data;

            if (!config.m_DataDict.TryGetValue(id, out data))
            {
                Debug.LogErrorFormat(
                    "Data in config '{0}' is not found. ID: {1}.",
                    typeof(TestLogXmlDocConfig).Name,
                    id.ToString()
                    );
                return(null);
            }
            return(data);
        }