unity3D游戏开发之数据库

合集下载

基于Unity3D引擎的3D游戏开发技术研究

基于Unity3D引擎的3D游戏开发技术研究

基于Unity3D引擎的3D游戏开发技术研究随着科技的不断发展,3D游戏已经成为普及性的游戏形式。

而在3D游戏的开发过程中,Unity3D是被许多游戏开发者广泛使用的引擎之一。

它的图形处理技术、交互性、物理模拟都非常出色,这些特点使得它成为了一款非常适合开发3D游戏的引擎。

一、Unity3D的基本架构Unity3D的基本架构包括了引擎层和编辑器层。

其中引擎层主要是负责3D游戏的运行,而编辑器层则是为游戏开发者提供3D场景的制作和脚本的编写。

这两层结合紧密,可以使游戏开发者更加快速地开发出高品质的游戏。

引擎层主要包括以下几个组件:1. 渲染引擎:它是Unity3D中最基本的组件之一,主要负责游戏画面的渲染。

渲染引擎支持顶点着色器、像素着色器以及多种图形处理技术,可以使游戏画面变得更加真实。

2. 物理引擎:物理引擎主要处理物体的运动学和碰撞检测等物理属性。

Unity3D使用了Box2D和Havok等多个物理引擎,以达到更好的物理模拟效果。

3. 音频引擎:音频引擎用于处理游戏音效的播放和控制。

它支持多种音频格式的播放,并支持不同的音效混合技术。

编辑器层主要包括以下几个组件:1. 场景编辑器:它是Unity3D中最重要的组件之一,支持3D场景的制作。

开发者可以很方便地添加、移动、旋转、缩放3D模型,而且可以实时预览场景效果。

2. UI编辑器:用于控制游戏界面元素的制作。

例如按钮、滑块、进度条等UI元素。

3. 脚本编辑器:支持多种编程语言的代码编写,包括C#、JavaScript等语言。

游戏开发者可以在脚本编辑器中灵活掌握游戏逻辑并且修改游戏行为。

二、Unity3D的开发流程Unity3D的开发流程通常分为以下几个步骤:1. 规划: 游戏开发者需要分析游戏玩法、游戏场景需求等来确定游戏的开发方向。

在这个过程中,需要提前设计好游戏的关卡、模型、声音等元素。

此外,还需要确定游戏的目标受众以及营销策略。

2. 设计: 游戏开发者需要根据游戏规划出发,设计出游戏的关卡、模型、声音等元素,并且要将这些元素设计成可重复利用的组件。

Unity3D访问Access数据库教程

Unity3D访问Access数据库教程

学IT技能上我学院网Unity3D访问Access数据库教程Access数据库是一个轻量级的数据库,以前在学习.net应用开发的的时候相信大家都了解过。

在pc的软件开发中,很多时候,我们存储的数据量不会很大的情况都会选择他,主要他轻量级,容易部署。

更多Access的问题,可以去微软的官网查看。

在U3D中要访问Access数据库,我们需要用到两个dll,System.Data.dll和System.EnterpriseServices.dll,缺一不可。

我们找到这两个dll放到u3d的Plugins文件夹下面。

下面我们创建一个Access数据库版本是07样式是*.accdb(03版本的Access数据库的样式为*.mdb)在我们进行code的时候,要根据不同的版本进行判断啦,对于不同的Access 数据库版本,我们要对应不懂的文件后缀名。

要不然会提示你数据库文件是未知文件。

下面是读取Access的一个demo,其他的修改,添加数据都是在修改他的sql语句啦,相关的知识,可以查看Access在.net中如何对Access进行CURD操作的。

简单的代码如下:学IT技能上我学院网学IT技能上我学院网学IT技能上我学院网学IT技能上我学院网学IT技能上我学院网下一步,我们生成exe文件.执行完毕之后,我们打开生成的程序截图如下:学IT技能上我学院网为什么会出现这个问题。

我在u3d里面看到了他的显示啊,如下:其实呢,我们在部署的时候,要把数据库文件,copy到生成的文件夹下就可以啦!再次运行程序,查看效果。

如下:学IT技能上我学院网好,看到这里,你应该知道了,我今天重点要说的就是这个问题啦!下面是我在制作demo时,遇到的问题还有些是我特意测试需要注意的地方:注意:1. 一定要记住的是,访问Access数据库时,那两个dll缺一不可,缺少就会出现问题。

2. 在带有dll动态链接库的项目,要在打包时设置他的API兼容层级为.NET 2.0。

Unity3d 连接 MySQL 数据库(使用DataSet)

Unity3d 连接 MySQL 数据库(使用DataSet)
using System.Data;
using MySql.Data.MySqlClient;
public class CMySql : MonoBehaviour {
// Global variables
public static MySqlConnection dbConnection;//Just like MyConn.conn in StoryTools before
DataSet ds = new DataSet();
try
{
MySqlDataAdapter da = new MySqlDataAdapter(sqlString, dbConnection);
da.Fill(ds);
}
catch (Exception ee)
{
throw new Exception("SQL:" + sqlString + "\n" + ee.Message.ToString());
}
}
2.導入dll
同先前的帖子 , 將MySql.data.dll Import至Assets底下 , 然後再到Unity\Editor\Data\Frameworks\Mono.framework 中
將System.Data.dll 也一起Import至Assets內 , 當然 , 如果想顯示中文的話 , 請參考中文視頻教學 , 建立一個GUISkin與字型
先前有人發了一篇如何連接 MySQL 數據庫的帖子
而我這篇是接著先前的帖子用DataSet方式將數據庫的內容呈現出來 , 當然 , 內容有做了些許的修改

Unity3d连接SQLServer数据库的技巧

Unity3d连接SQLServer数据库的技巧

{ //连接字符串 SqlConnection connstr = new SqlConnection(“Data Source=.;Initial Catalog=Exam;uid=sa;pwd=123”); SqlCommand cmd = new SqlCommand(); cmd.Connection = connstr; mandType = mandType.Text; //设置 sql 连接语句 mandText = “select * from Users”; SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.SelectCommand.Connection.Open(); string strtemp = sda.SelectCommand.ExecuteScalar().ToString(); sda.SelectCommand.Connection.Close();
Unity3d 连接 SQLServer 数据库的技巧
我们为大家收集整理了关于 Unity3d 连接 SQLServer 数据库,以方便大 家参考。 在编写代码之前需要: 1.引入程序集 System.Data.dll,位置在 C:Program FilesUnityEditorDataMonolibmonounity(我 unity 默认装在 C 盘)。 2.把 System.Data.dll 文件复制到当前 Unity 项目文件下,即 Assets 文件夹下 就可以了。 虽然在 unity 里面可以运行但是发布为 web 或者 exe 后还是连接不上,这 就还需要另外三个 dll 文件 I18N.dll,I18N.West.dll,I18N.CJK.dll ,这三个 文件和 System.data.dll 在同一个目录下,要把这个 4 个 dll 文件一起放在 Assets 文件下最后发布出来也可以连接上数据库了。 public class ConnectionSqlserver : MonoBehaviour { + strtemp); } } 希望大家学业有成,工作顺利

unity3D技术之AssetDatabase 资源数据库

unity3D技术之AssetDatabase 资源数据库

AssetDatabase 资源数据库An Interface for accessing assets and performing operations on assets. AssetDatabase是一个对资源进行读写和各种操作的接口。

[狗刨学习网]Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.注意:这是一个编辑器类,如果想使用它你需要把它放到工程目录下的Assets/Editor文件夹下。

编辑器类在UnityEditor命名空间下。

所以当使用C#脚本时,你需要在脚本前面加上 "using UnityEditor"引用。

Class Functions类函数∙ContainsIs object an asset?资源中是否存在该对象?∙IsMainAssetIs asset a main asset in the project window?该资源在Project窗口中是不是主资源?∙GenerateUniqueAssetPathCreates a new unique path for an asset.给一个资源创建一个新的唯一路径。

∙StartAssetEditingBegin Asset importing. This lets you group several asset imports together into one larger import.开始资源导入。

unity3d中连接数据库

unity3d中连接数据库

/*在unity3d中连接数据库收藏1.C#代码:*/using UnityEngine;using System;using System.Collections;using System.Data;using MySql.Data.MySqlClient;public class CMySql : MonoBehaviour {// Global variablespublic static MySqlConnection dbConnection;//Just like MyConn.conn in StoryTools beforestatic string host = "192.168.1.100";static string id = "mysql";//这里是你自己的数据库的用户名字,我一开始想用root,发现不行,后来添加了新的用户才可以static string pwd = "123456";static string database = "test";static string result = "";private string strCommand = "Select * from unity3d_test ORDER BY id;";public static DataSet MyObj;void OnGUI(){host = GUILayout.TextField( host, 200, GUILayout.Width(200));id = GUILayout.TextField( id, 200, GUILayout.Width(200));pwd = GUILayout.TextField( pwd, 200, GUILayout.Width(200));if(GUILayout.Button("Test")){string connectionString = string.Format("Server = {0}; Database = {1}; User ID = {2}; Password = {3};",host,database,id,pwd);openSqlConnection(connectionString);MyObj = GetDataSet(strCommand);}bel(result);}// On quitpublic static void OnApplicationQuit() {closeSqlConnection();}// Connect to databaseprivate static void openSqlConnection(string connectionString) {dbConnection = new MySqlConnection(connectionString);dbConnection.Open();result = dbConnection.ServerVersion;//Debug.Log("Connected to database."+result);}// Disconnect from databaseprivate static void closeSqlConnection() {dbConnection.Close();dbConnection = null;//Debug.Log("Disconnected from database."+result);}// MySQL Querypublic static void doQuery(string sqlQuery) {IDbCommand dbCommand = dbConnection.CreateCommand();mandText = sqlQuery;IDataReader reader = dbCommand.ExecuteReader();reader.Close();reader = null;dbCommand.Dispose();dbCommand = null;}#region Get DataSetpublic DataSet GetDataSet(string sqlString){//string sql = UnicodeAndANSI.UnicodeAndANSI.UnicodeToUtf8(sqlString);DataSet ds = new DataSet();try{MySqlDataAdapter da = new MySqlDataAdapter(sqlString, dbConnection); da.Fill(ds);}catch (Exception ee){throw new Exception("SQL:" + sqlString + "\n" + ee.Message.ToString()); }return ds;}#endregion}using UnityEngine;using System;using System.Collections;using System.Data;public class DataBaseTest : MonoBehaviour {public GUISkin myGUISkin = new GUISkin();string strID = "";string strName = "";string strSex = "";int Index = 1;// Use this for initializationvoid Start () {}void OnGUI(){GUI.skin = myGUISkin;if (GUI.Button(new Rect(100,320,100,100),"Click Me")) {foreach(DataRow dr in CMySql.MyObj.Tables[0].Rows) {if (Index.ToString() == dr["ID"].ToString()){strID = dr["ID"].ToString();strName = dr["Name"].ToString();strSex = dr["Sex"].ToString();break;}}Index++;if(Index > 5){Index = 1;}}bel(new Rect(320,100,150,70),"DataBaseTest"); bel(new Rect(300,210,150,70),strID);bel(new Rect(300,320,150,70),strName);bel(new Rect(300,430,150,70),strSex);}}2.導入dll同先前的帖子, 將MySql.data.dll Import至Assets底下, 然後再到Unity\Editor\Data\Frameworks\Mono.framework 中將System.Data.dll 也一起Import至Assets內 , 當然 , 如果想顯示中文的話 , 請參考中文視頻教學 , 建立一個GUISkin與字型3.建立數據庫內容主要是因為代碼中的這段內容static string host = "192.168.1.100";static string id = "mysql";static string pwd = "123456";static string database = "test";private string strCommand = "Select * from unity3d_test ORDER BY id;";其中host ,id , pwd 請自行設定 , 簡單的說就是連進你的MySQL啦~然後建立一個名為test的Database , 在這個test下建立一張table , 取名為unity3d_test ,接下來就為這張unity3d_test建立3個欄位 : ID , Name , Sex (記得將ID設定為primary key 且默認值為1)再來自行填入5筆資料(5筆資料的原因是腳本那邊是設定成5筆資料一個循環 , 使用者可以自行更改腳本試試)4.建立GameObject建立完GameObject後將上面兩個腳本掛上去 , 如果有建立GUISkin , 記得指定GUISkin5.執行執行後先按Test按鈕來連接數據庫 , 然後再按"Click Me"來顯示數據庫內的內容。

Unity中对SQL数据库的操作

Unity中对SQL数据库的操作在Unity中,我们有时候需要连接数据库来达到数据的读取与储存。

⽽在.NET平台下,为我们提供了公开数据访问服务的类。

客户端应⽤程序可以使⽤来连接到数据源,并查询,添加,删除和更新所包含的数据。

对于,需要了解到Connection,Command,DataReader,DataAdapter,DataSet这⼏个对象,他们是操作数据库的重要对象。

下⾯简要得介绍下这⼏个对象的作⽤以及功能(以SQL为例)。

1、Connection:它是建⽴应⽤程序与数据库之间的连接通道,起到连接数据库的功能。

其访问形式根据数据库的类型⽽定。

以SQL为例,则连接类型为SqlConnection。

这种连接需要引⼊相应数据库的命名空间,这⾥我们需要引⼊System.Data.SqlClient。

想要引⼊这个命名空间还需要System.Data.dll⽂件,就在Unity安装源⽬录下即可找到,复制导⼊Unity的Asset即可。

写法如下://声明⼀个字符串⽤于存储连接数据库字符串string s = "server=localhost;database=hasion;uid=sa;pwd=hasion";SqlConnection con = new SqlConnection(s);con.Open();这样数据库的连接就打开了。

2、Command:当应⽤程序建⽴与数据源的连接后,就需要Command对象来执⾏命令并从数据源中返回结果。

它是⼀个数据命令对象,主要功能就是向数据库发送查询、更新、删除、修改操作的SQL语句。

这边需要讲下它执⾏SQL的⼏种⽅法:ExecuteNonQuery⽅法,该⽅法是返回受影响的⾏数可⽤于统计,(如需进⾏存储过程则需更改CommandType的属性)。

写法如下://声明⼀个字符串⽤于存储连接数据库字符串string s = "server=localhost;database=hasion;uid=sa;pwd=hasion";SqlConnection con = new SqlConnection(s);con.Open();//创建SqlCommand对象,并指定其使⽤con连接数据库SqlCommand cmd = new SqlCommand();cmd.Connection = con;//设置CommandText,设置其执⾏SQL语句mandText="update Table_1 set 资产=1000 where 性别='⼥'";int i = Convert.ToInt32 (cmd.ExecuteNonQuery ());print ("查询到"+i+"个⼥性");ExecuteScalar⽅法,返回结果集合的第⼀⾏的第⼀列,常⽤语统计数据数量,⽤法如下://声明⼀个字符串⽤于存储连接数据库字符串string s = "server=localhost;database=hasion;uid=sa;pwd=hasion";SqlConnection con = new SqlConnection(s);con.Open();//创建SqlCommand对象,并指定其使⽤con连接数据库SqlCommand cmd = new SqlCommand();cmd.Connection = con;//设置CommandText,设置其执⾏SQL语句mandText="select * from Table_1 where 性别='⼥'";int i = Convert.ToInt32 (cmd.ExecuteScalar ());print ("查询到"+i+"个⼥性");ExecuteReader⽅法,返回⼀个SqlDataReader对象,可进⾏数据的读取,其⽤法如下://声明⼀个字符串⽤于存储连接数据库字符串string s = "server=localhost;database=hasion;uid=sa;pwd=hasion";SqlConnection con = new SqlConnection(s);con.Open();//创建SqlCommand对象,并指定其使⽤con连接数据库SqlCommand cmd = new SqlCommand();cmd.Connection = con;//设置CommandText,设置其执⾏SQL语句mandText="select * from Table_1";SqlDataReader st = cmd.ExecuteReader ();while (st.Read()){print(st[0].ToString());}cmd.Dispose ();上⾯的功能就是输出表格第⼀列的所有内容。

unity3D技术之导出Unity场景的所有游戏对象信息

导出Unity场景的所有游戏对象信息,一种是XML一种是JSON。

本篇文章我们把游戏场景中游戏对象的、旋转、缩放、平移与Prefab的名称导出在XML与JSON中。

然后解析刚刚导出的XML或JSON通过脚本把导出的游戏场景还原。

在Unity官网上下载随便下载一个demo Project,如下图所示这是我刚刚在官网上下载的一个范例程序。

接着将层次视图中的所有游戏对象都封装成Prefab保存在资源路径中,这里注意一下如果你的Prefab绑定的脚本中有public Object 的话,需要在代码中改一下。

用Find() FindTag()这类方法在脚本中Awake()方法中来拿,不然Prefab动态加载的时候无法赋值的,如下图所示,我把封装的Prefab对象都放在了Resources/Prefab文件夹下。

OK,现在我们就需要编写我们的导出工具、在Project视图中创建Editor文件夹,接着创建脚本MyEditor 。

如下图所示。

因为编辑的游戏场景数量比较多,导出的时候我们需要遍历所有的游戏场景,一个一个的读取场景信息。

然后取得游戏场景中所有游戏对象的Prefab的名称旋转缩放平移。

有关XML的使用请大家看我的上一篇文章: Unity3D研究院之使用C#合成解析XML与JSON (四十一)代码中我只注释重点的部分,嘿嘿。

MyEditor.csC#1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031 using UnityEngine;using System.Collections;using UnityEditor;using System.Collections.Generic;using System.Xml;using System.IO;using System.Text;using LitJson;public class MyEditor : Editor{//将所有游戏场景导出为XML格式[MenuItem ("GameObject/ExportXML")]static void ExportXML (){string filepath = Application.dataPath + @"/StreamingAssets/my.xml";if(!File.Exists (filepath)){File.Delete(filepath);}XmlDocument xmlDoc = new XmlDocument();XmlElement root = xmlDoc.CreateElement("gameObjects");//遍历所有的游戏场景foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes) {//当关卡启用if (S.enabled){//得到关卡的名称string name = S.path;//打开这个关卡EditorApplication.OpenScene(name);3233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 XmlElement scenes = xmlDoc.CreateElement("scenes");scenes.SetAttribute("name",name);foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject))) {if (obj.transform.parent == null){XmlElement gameObject = xmlDoc.CreateElement("gameObjects"); gameObject.SetAttribute("name",);gameObject.SetAttribute("asset", + ".prefab");XmlElement transform = xmlDoc.CreateElement("transform"); XmlElement position = xmlDoc.CreateElement("position");XmlElement position_x = xmlDoc.CreateElement("x");position_x.InnerText = obj.transform.position.x+"";XmlElement position_y = xmlDoc.CreateElement("y");position_y.InnerText = obj.transform.position.y+"";XmlElement position_z = xmlDoc.CreateElement("z");position_z.InnerText = obj.transform.position.z+"";position.AppendChild(position_x);position.AppendChild(position_y);position.AppendChild(position_z);XmlElement rotation = xmlDoc.CreateElement("rotation");XmlElement rotation_x = xmlDoc.CreateElement("x");rotation_x.InnerText = obj.transform.rotation.eulerAngles.x+""; XmlElement rotation_y = xmlDoc.CreateElement("y");rotation_y.InnerText = obj.transform.rotation.eulerAngles.y+""; XmlElement rotation_z = xmlDoc.CreateElement("z");rotation_z.InnerText = obj.transform.rotation.eulerAngles.z+"";rotation.AppendChild(rotation_x);rotation.AppendChild(rotation_y);rotation.AppendChild(rotation_z);XmlElement scale = xmlDoc.CreateElement("scale");XmlElement scale_x = xmlDoc.CreateElement("x");scale_x.InnerText = obj.transform.localScale.x+"";XmlElement scale_y = xmlDoc.CreateElement("y");scale_y.InnerText = obj.transform.localScale.y+"";XmlElement scale_z = xmlDoc.CreateElement("z");scale_z.InnerText = obj.transform.localScale.z+"";scale.AppendChild(scale_x);scale.AppendChild(scale_y);scale.AppendChild(scale_z);767778798081828384858687888990919293949596979899 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 transform.AppendChild(position);transform.AppendChild(rotation);transform.AppendChild(scale);gameObject.AppendChild(transform);scenes.AppendChild(gameObject);root.AppendChild(scenes);xmlDoc.AppendChild(root);xmlDoc.Save(filepath);}}}}//刷新Project视图,不然需要手动刷新哦AssetDatabase.Refresh();}//将所有游戏场景导出为JSON格式[MenuItem ("GameObject/ExportJSON")]static void ExportJSON (){string filepath = Application.dataPath + @"/StreamingAssets/json.txt";FileInfo t = new FileInfo(filepath);if(!File.Exists (filepath)){File.Delete(filepath);}StreamWriter sw = t.CreateText();StringBuilder sb = new StringBuilder ();JsonWriter writer = new JsonWriter (sb);writer.WriteObjectStart ();writer.WritePropertyName ("GameObjects");writer.WriteArrayStart ();foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes) {if (S.enabled){string name = S.path;EditorApplication.OpenScene(name);writer.WriteObjectStart();120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 writer.WritePropertyName("scenes");writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName("name");writer.Write(name);writer.WritePropertyName("gameObject");writer.WriteArrayStart ();foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject))) {if (obj.transform.parent == null){writer.WriteObjectStart();writer.WritePropertyName("name");writer.Write();writer.WritePropertyName("position");writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName("x");writer.Write(obj.transform.position.x.ToString("F5"));writer.WritePropertyName("y");writer.Write(obj.transform.position.y.ToString("F5"));writer.WritePropertyName("z");writer.Write(obj.transform.position.z.ToString("F5"));writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WritePropertyName("rotation");writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName("x");writer.Write(obj.transform.rotation.eulerAngles.x.ToString("F5"));writer.WritePropertyName("y");writer.Write(obj.transform.rotation.eulerAngles.y.ToString("F5"));writer.WritePropertyName("z");writer.Write(obj.transform.rotation.eulerAngles.z.ToString("F5"));writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WritePropertyName("scale");writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName("x");164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 writer.Write(obj.transform.localScale.x.ToString("F5"));writer.WritePropertyName("y");writer.Write(obj.transform.localScale.y.ToString("F5"));writer.WritePropertyName("z");writer.Write(obj.transform.localScale.z.ToString("F5"));writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WriteObjectEnd();}}writer.WriteArrayEnd();writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WriteObjectEnd();}}writer.WriteArrayEnd();writer.WriteObjectEnd ();sw.WriteLine(sb.ToString());sw.Close();sw.Dispose();AssetDatabase.Refresh();}}此时我们就可以导出游戏场景的信息拉,注意游戏场景的需要现在Project Setting 中注册。

Unity连接MySQL数据库

Unity连接MySQL数据库Plugins下应该有相关的dll文件如下:此外还需要两个脚本用来连接数据库,一个创建数据连接脚本类,一个脚本类使用数据连接类。

Sql连接数据库类:using MySql.Data.MySqlClient;using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text;using UnityEngine;public class SqlAccess{public static MySqlConnection dbConnection;//如果只是在本地的话,写localhost就可以。

// static string host = "localhost";//如果是局域网,那么写上本机的局域网IPstatic string host = "localhost";static string id = "root";static string pwd = "123456";static string database = "test1";public SqlAccess(){OpenSql();}public static void OpenSql(){try{string connectionString = string.Format("Server = {0};port={4};Database = {1}; User ID = {2}; Password = {3};", host, database, id, pwd, "3306");dbConnection = new MySqlConnection(connectionString);dbConnection.Open();}catch (Exception e){throw new Exception("服务器连接失败,请重新检查是否打开MySql服务。

Unity+C#游戏开发基本数据类型


1 数据类型
• (2)引用类型(Reference Types)
• C#地引用类型主要有以下几种:

类类型(Class):类是面向对象程序设计地基本单位,它由数据成员,函 数成员与嵌套类等构成,它包含对象类型(Object),数组类(Array)与
字符串类(String)等引用类型。

接口类型(Interface):接口是指定一组函数成员而不实现它们地引用 类型。
>>= <<=
类别 双目 双目 双目 双目 双目 双目 双目 双目 双目 双目 双目
描述 将右边表达式地值赋给左边地变量 将左边变量地值减去右边表达式后将结果 赋给左边地变量 将左边变量地值加上右边表达式后将结果 赋给左边地变量
将左边变量地值除以右边表达式后将结果 赋给左边地变量
将左边变量地值乘以右边表达式后将结果 赋给左边地变量 将左边变量地值除以右边表达式后将余数 赋给左边地变量
• 结构体数据类型(Struct Types)可以使一个单一地变量存储各种 数据类型地有关数据,一般地简单变量一个变量只能属于谋一种类 型,而结构体数据类型可以将有关地不同类型捆绑在一起成为一个 整体。属于用户自定义类型地范畴,结构体数据类型需用户以关键 字struct自行创建。
• 语法: • struct 结构体名称 •{ • 定义不同成员变量; •}
)与删除末
• (2)字符串英文字母大小写转换方法

字符串由大写字母转换为小写字母方法为:字符串.ToLower( 由小写字母转换为大写字母地方法为:字符串.ToUpper( )。
);反之,字符串
• 注:如输入其它字符则不转换。
• (3)判断子字符串是否出现在字符串地开头或结尾 • 判断一个指定地字符串1是否出现在字符串2地开头为:字符串
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

今天主要讲了数据库的一些内容。

数据库的作用:
1、存储大量数据,方便检索和访问
2、保持数据信息的一致、完整
3、共享和安全
4、通过组合分析,产生新的有用信息
数据库的概念:
简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进行新增、截取、更新、删除等操作。

数据库指的是以一定方式储存在一起、能为多个用户共享、具有尽可能小的冗余度的特点、是与应用程序彼此独立的数据集合。

创建数据库
数据文件:后缀是.mdf或.ndf
日志文件:后缀是.ldf
创建数据库表
输入数据库名称
这个是增量的幅度,有无上限。

数据的完整性
可靠性+追求性
包括域完整性、自定义完整性、实体完整性、引用完整性。

在数据库中建表格
列名字
数据类型设置主键

主键原则
最少性
尽量选择单个键作为主键
稳定性
尽量选择数值更新少的列作为主键。

相关文档
最新文档