/// <summary>
        /// 创建数据表。
        /// </summary>
        /// <param name="dataRowType">数据表行的类型。</param>
        /// <param name="name">数据表名称。</param>
        /// <param name="dataTableData">要解析的数据表数据。</param>
        /// <returns>要创建的数据表。</returns>
        public DataTableBase CreateDataTable(Type dataRowType, string name, object dataTableData)
        {
            if (dataRowType == null)
            {
                throw new GameFrameworkException("Data row type is invalid.");
            }

            if (!typeof(IDataRow).IsAssignableFrom(dataRowType))
            {
                throw new GameFrameworkException(Utility.Text.Format("Data row type '{0}' is invalid.", dataRowType.FullName));
            }

            TypeNamePair typeNamePair = new TypeNamePair(dataRowType, name);

            if (HasDataTable(dataRowType, name))
            {
                throw new GameFrameworkException(Utility.Text.Format("Already exist data table '{0}'.", typeNamePair.ToString()));
            }

            Type          dataTableType = typeof(DataTable <>).MakeGenericType(dataRowType);
            DataTableBase dataTable     = (DataTableBase)Activator.CreateInstance(dataTableType, name);

            InternalCreateDataTable(dataTable, dataTableData);
            m_DataTables.Add(typeNamePair, dataTable);
            return(dataTable);
        }
        private void InternalCreateDataTable(DataTableBase dataTable, object dataTableData)
        {
            GameFrameworkDataSegment[] dataRowSegments = null;
            object dataTableUserData = null;

            try
            {
                dataRowSegments   = m_DataTableHelper.GetDataRowSegments(dataTableData);
                dataTableUserData = m_DataTableHelper.GetDataTableUserData(dataTableData);
            }
            catch (Exception exception)
            {
                if (exception is GameFrameworkException)
                {
                    throw;
                }

                throw new GameFrameworkException(Utility.Text.Format("Can not get data row segments with exception '{0}'.", exception.ToString()), exception);
            }

            if (dataRowSegments == null)
            {
                throw new GameFrameworkException("Data row segments is invalid.");
            }

            foreach (GameFrameworkDataSegment dataRowSegment in dataRowSegments)
            {
                if (!dataTable.AddDataRow(dataRowSegment, dataTableUserData))
                {
                    throw new GameFrameworkException("Add data row failure.");
                }
            }
        }
Beispiel #3
0
        private void InternalCreateDataTable(DataTableBase dataTable, Stream stream)
        {
            IEnumerable <GameFrameworkSegment <Stream> > dataRowSegments = null;

            try
            {
                dataRowSegments = m_DataTableHelper.GetDataRowSegments(stream);
            }
            catch (Exception exception)
            {
                if (exception is GameFrameworkException)
                {
                    throw;
                }

                throw new GameFrameworkException(Utility.Text.Format("Can not get data row segments with exception '{0}'.", exception.ToString()), exception);
            }

            if (dataRowSegments == null)
            {
                throw new GameFrameworkException("Data row segments is invalid.");
            }

            foreach (GameFrameworkSegment <Stream> dataRowSegment in dataRowSegments)
            {
                if (!dataTable.AddDataRow(dataRowSegment))
                {
                    throw new GameFrameworkException("Add data row failure.");
                }
            }
        }
        /// <summary>
        /// 创建数据表。
        /// </summary>
        /// <param name="dataRowType">数据表行的类型。</param>
        /// <param name="name">数据表名称。</param>
        /// <param name="text">要解析的数据表文本。</param>
        /// <returns>要创建的数据表。</returns>
        public DataTableBase CreateDataTable(Type dataRowType, string name, string text)
        {
            if (dataRowType == null)
            {
                throw new GameFrameworkException("Data row type is invalid.");
            }

            if (!typeof(IDataRow).IsAssignableFrom(dataRowType))
            {
                throw new GameFrameworkException(string.Format("Data row type '{0}' is invalid.", dataRowType.FullName));
            }

            if (HasDataTable(dataRowType, name))
            {
                throw new GameFrameworkException(string.Format("Already exist data table '{0}'.", Utility.Text.GetFullName(dataRowType, name)));
            }

            Type          dataTableType = typeof(DataTable <>).MakeGenericType(dataRowType);
            DataTableBase dataTable     = (DataTableBase)Activator.CreateInstance(dataTableType, name);

            string[] dataRowTexts = m_DataTableHelper.SplitToDataRows(text);
            foreach (string dataRowText in dataRowTexts)
            {
                dataTable.AddDataRow(dataRowText);
            }

            m_DataTables.Add(Utility.Text.GetFullName(dataRowType, name), dataTable);
            return(dataTable);
        }
    static int CreateDataTable(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityGameFramework.Runtime.DataTableComponent), typeof(System.Type), typeof(string)))
            {
                UnityGameFramework.Runtime.DataTableComponent obj = (UnityGameFramework.Runtime.DataTableComponent)ToLua.ToObject(L, 1);
                System.Type arg0 = (System.Type)ToLua.ToObject(L, 2);
                string      arg1 = ToLua.ToString(L, 3);
                GameFramework.DataTable.DataTableBase o = obj.CreateDataTable(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityGameFramework.Runtime.DataTableComponent), typeof(System.Type), typeof(string), typeof(string)))
            {
                UnityGameFramework.Runtime.DataTableComponent obj = (UnityGameFramework.Runtime.DataTableComponent)ToLua.ToObject(L, 1);
                System.Type arg0 = (System.Type)ToLua.ToObject(L, 2);
                string      arg1 = ToLua.ToString(L, 3);
                string      arg2 = ToLua.ToString(L, 4);
                GameFramework.DataTable.DataTableBase o = obj.CreateDataTable(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityGameFramework.Runtime.DataTableComponent.CreateDataTable"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        /// <summary>
        /// 销毁数据表。
        /// </summary>
        /// <param name="dataTable">要销毁的数据表。</param>
        /// <returns>是否销毁数据表成功。</returns>
        public bool DestroyDataTable(DataTableBase dataTable)
        {
            if (dataTable == null)
            {
                throw new GameFrameworkException("Data table is invalid.");
            }

            return(InternalDestroyDataTable(new TypeNamePair(dataTable.Type, dataTable.Name)));
        }
Beispiel #7
0
        private DataTableBase InternalGetDataTable(string fullName)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(fullName, out dataTable))
            {
                return(dataTable);
            }
            return(null);
        }
        private DataTableBase InternalGetDataTable(TypeNamePair typeNamePair)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(typeNamePair, out dataTable))
            {
                return(dataTable);
            }

            return(null);
        }
Beispiel #9
0
        private bool InternalDestroyDataTable(string fullName)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(fullName, out dataTable))
            {
                dataTable.Shutdown();
                return(m_DataTables.Remove());
            }
            return(false);
        }
        private bool InternalDestroyDataTable(TypeNamePair typeNamePair)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(typeNamePair, out dataTable))
            {
                dataTable.Shutdown();
                return(m_DataTables.Remove(typeNamePair));
            }

            return(false);
        }
        /// <summary>
        /// 获取所有数据表。
        /// </summary>
        /// <returns>所有数据表。</returns>
        public DataTableBase[] GetAllDataTables()
        {
            int index = 0;

            DataTableBase[] results = new DataTableBase[m_DataTables.Count];
            foreach (KeyValuePair <TypeNamePair, DataTableBase> dataTable in m_DataTables)
            {
                results[index++] = dataTable.Value;
            }

            return(results);
        }
Beispiel #12
0
        /// <summary>
        /// 获取所有数据表。
        /// </summary>
        /// <returns>所有数据表。</returns>
        public DataTableBase[] GetAllDataTables()
        {
            int index = 0;

            DataTableBase[] dataTables = new DataTableBase[m_DataTables.Count];
            foreach (DataTableBase dataTable in m_DataTables.Values)
            {
                dataTables[index++] = dataTable;
            }

            return(dataTables);
        }
Beispiel #13
0
        /// <summary>
        /// 获取所有数据表。
        /// </summary>
        /// <returns>所有数据表。</returns>
        public DataTableBase[] GetAllDataTables()
        {
            int index = 0;

            DataTableBase[] dataTables = new DataTableBase[m_DataTables.Count];
            foreach (KeyValuePair <string, DataTableBase> dataTable in m_DataTables)
            {
                dataTables[index++] = dataTable.Value;
            }

            return(dataTables);
        }
Beispiel #14
0
        /// <summary>
        /// 创建数据表。
        /// </summary>
        /// <param name="dataRowType">数据表行的类型。</param>
        /// <param name="name">数据表名称。</param>
        /// <returns>要创建的数据表。</returns>
        public DataTableBase CreateDataTable(Type dataRowType, string name)
        {
            if (m_ResourceManager == null)
            {
                throw new GameFrameworkException("You must set resource manager first.");
            }

            if (m_DataProviderHelper == null)
            {
                throw new GameFrameworkException("You must set data provider helper first.");
            }

            if (dataRowType == null)
            {
                throw new GameFrameworkException("Data row type is invalid.");
            }

            if (!typeof(IDataRow).IsAssignableFrom(dataRowType))
            {
                throw new GameFrameworkException(Utility.Text.Format("Data row type '{0}' is invalid.", dataRowType.FullName));
            }

            TypeNamePair typeNamePair = new TypeNamePair(dataRowType, name);

            if (HasDataTable(dataRowType, name))
            {
                throw new GameFrameworkException(Utility.Text.Format("Already exist data table '{0}'.", typeNamePair));
            }

            Type          dataTableType = typeof(DataTable <>).MakeGenericType(dataRowType);
            DataTableBase dataTable     = (DataTableBase)Activator.CreateInstance(dataTableType, name);

            dataTable.SetResourceManager(m_ResourceManager);
            dataTable.SetDataProviderHelper(m_DataProviderHelper);
            m_DataTables.Add(typeNamePair, dataTable);
            return(dataTable);
        }