找回密码
 立即注册
查看: 7202|回复: 88

[网络] u3d连接网络sqlserver,并实现注册登录 教程+源码

  [复制链接]
发表于 2013-3-5 08:48 | 显示全部楼层 |阅读模式
资源信息 Tutorial Information
教程名称: u3d连接网络sqlserver,并实现注册登录 教程+源码(发帖教程)
适用引擎:   (适用引擎,为空默认为Unity)
教程语种: 中文
教程等级: 1
教程格式: 图文(请用IE9以上浏览器访问本版块)
教程作者: 转载自互联网 (如有问题请短消息联系作者或发表回复)
下载地址: (兑换积分)
点击查看原图
美丽分割线
登录注册功能已经做好了,还好比较顺利值得欣慰
注册界面


注册部分代码:
  1. using UnityEngine;
  2. using System.Collections;
  3. using Bitverse.Unity.Gui;
  4. using System;
  5. using System.Data.SqlClient;

  6. public class regsct : MonoBehaviour {
  7.     public GUISkin txtskin;
  8.         BitEditorStage form;
  9.         BitWindow regwindow;
  10.          BitButton btregist;
  11.         BitButton btexit;
  12.         BitTextField txtname;
  13.         BitTextField txtpwd;
  14.         BitTextField txtpwd1;
  15.         BitTextField txthobby;
  16.     BitToggle tgmale;
  17.     BitToggle tgFemale;
  18.     string gender;
  19.     string tempip;
  20.         // Use this for initialization
  21.         void Start () {
  22.                 form = gameObject.GetComponent<BitEditorStage>();
  23.                 regwindow = form.FindControl<BitWindow>("reg");
  24.         txtname = regwindow.FindControl<BitTextField>("txtname");
  25.         txtpwd = regwindow.FindControl<BitTextField>("txtpwd");
  26.         txtpwd1 = regwindow.FindControl<BitTextField>("txtpwd1");
  27.         txtpwd1.TextChanged += txtpwd1_TextChanged;
  28.         txthobby = regwindow.FindControl<BitTextField>("txthobby");
  29.         tgmale = regwindow.FindControl<BitToggle>("tgmale");
  30.         tgmale.ValueChanged += tgmale_ValueChanged;
  31.         tgFemale = regwindow.FindControl<BitToggle>("tgfemale");
  32.         tgFemale.ValueChanged += tgFemale_ValueChanged;
  33.                  btregist = regwindow.FindControl<BitButton>("btreg");
  34.         btregist.MouseClick += bt_reg;
  35.                 btexit = regwindow.FindControl<BitButton>("btexit");
  36.         btexit.MouseClick += bt_exit;
  37.         }
  38.     void OnGUI()
  39.     {
  40.         GUILayout.Label(tempip);
  41.     }
  42.     private void tgmale_ValueChanged(object sender, ValueChangedEventArgs e)
  43.     {
  44.         if (tgmale.Value == true)
  45.         {
  46.             tgFemale.Value = false;
  47.             gender = "m";
  48.         }
  49.         if (tgmale.Value == false && tgFemale.Value == false)
  50.         {
  51.             tgFemale.Value = true;
  52.         }
  53.         print(gender);
  54.     }
  55.     private void tgFemale_ValueChanged(object sender, ValueChangedEventArgs e)
  56.     {
  57.         if (tgFemale.Value == true)
  58.         {
  59.             tgmale.Value = false;
  60.             gender = "f";
  61.         }
  62.         if (tgmale.Value == false && tgFemale.Value == false)
  63.         {
  64.             tgmale.Value = true;
  65.         }
  66.         print(gender);
  67.     }
  68.     private void txtpwd1_TextChanged(object sender, ValueChangedEventArgs e)
  69.     {
  70.         if (txtpwd1.Text.Trim() != txtpwd.Text.Trim())
  71.         {
  72.             txtpwd1.Skin = txtskin;
  73.         }
  74.         else
  75.         {
  76.             txtpwd1.Skin = null;
  77.         }
  78.     }
  79.         private void bt_reg(object sender, MouseEventArgs e)
  80.     {
  81.         if (txtname.Text != "" && txtpwd.Text != "" && txtpwd1.Text != "" && txthobby.Text != "" && txtpwd.Text == txtpwd1.Text)
  82.         {
  83.             print(txtname.Text);
  84.             SqlConnection sqlcon = new SqlConnection("Data Source=Sql1001.u3dchina.com,2433;Initial Catalog=DB_98CEEF_test;User Id=DB_98CEEF_test_admin;Password=testtest;");
  85.             SqlCommand cmd = new SqlCommand();
  86.             cmd.Connection = sqlcon;
  87.             cmd.CommandType = System.Data.CommandType.Text;
  88.             SqlDataAdapter da = new SqlDataAdapter(cmd);
  89.             da.SelectCommand.Connection.Open();
  90.             cmd.CommandText = "insert into user_ values ('" + txtname.Text + "','" + txtpwd.Text + "','" + gender.ToString() + "','" + txthobby.Text + "')";
  91.             int i = cmd.ExecuteNonQuery();
  92.             if (i > 0)
  93.             {
  94.                 txtname.Text = "";
  95.                 txtpwd.Text = "";
  96.                 txtpwd1.Text = "";
  97.                 txthobby.Text = "";
  98.                 regwindow.Visible = false;
  99.             }
  100.             da.SelectCommand.Connection.Close();
  101.         }
  102.         else
  103.             txtname.Focus = true;
  104.     }
  105.         private void bt_exit(object sender, MouseEventArgs e)
  106.     {
  107.         txtname.Text = "";
  108.         txtpwd.Text = "";
  109.         txtpwd1.Text = "";
  110.         txthobby.Text = "";
  111.         regwindow.Visible = false;
  112.     }
  113.         // Update is called once per frame
  114.         
  115. }
复制代码
登录部分:
  1. using UnityEngine;
  2. using System.Collections;
  3. using Bitverse.Unity.Gui;
  4. using System;
  5. using System.Data.SqlClient;

  6. public class logsct : MonoBehaviour {
  7.     int temp;
  8.     public GUISkin txtskin;
  9.     BitEditorStage form;
  10.     BitWindow logwindow;
  11.     BitTextField txtname;
  12.     BitTextField txtpwd;
  13.     BitButton btlog;
  14.     BitButton btexit;
  15.         // Use this for initialization
  16.         void Start () {

  17.         form = gameObject.GetComponent<BitEditorStage>();
  18.         logwindow = form.FindControl<BitWindow>("log");
  19.         txtname = logwindow.FindControl<BitTextField>("txtname");
  20.         txtpwd = logwindow.FindControl<BitTextField>("txtpwd");
  21.         btlog = logwindow.FindControl<BitButton>("btlog");
  22.         btlog.MouseClick += bt_log;
  23.         btexit = logwindow.FindControl<BitButton>("btexit");
  24.         btexit.MouseClick += bt_exit;
  25.         }
  26.     private void bt_log(object sender, MouseEventArgs e)
  27.     {
  28.         if (txtname.Text != "" && txtpwd.Text != "")
  29.         {
  30.             SqlConnection sqlcon = new SqlConnection("Data Source=Sql1001.webweb.com,2433;Initial Catalog=DB_98CEEF_test;User Id=DB_98CEEF_test_admin;Password=testtest;");
  31.             SqlCommand cmd = new SqlCommand();
  32.             cmd.Connection = sqlcon;
  33.             cmd.CommandType = System.Data.CommandType.Text;
  34.             cmd.CommandText = "select * from user_ where user_name='"+txtname.Text+"' and user_pwd ='"+txtpwd.Text+"'";
  35.             SqlDataAdapter da = new SqlDataAdapter(cmd);
  36.             da.SelectCommand.Connection.Open();
  37.             temp = int.Parse(da.SelectCommand.ExecuteScalar().ToString());
  38.             da.SelectCommand.Connection.Close();
  39.             if (temp != 0)
  40.                 print("login successed!");
  41.             txtname.Text = "";
  42.             txtpwd.Text = "";
  43.         }
  44.     }
  45.     private void bt_exit(object sender, MouseEventArgs e)
  46.     {
  47.         txtname.Text = "";
  48.         txtpwd.Text = "";
  49.         logwindow.Visible = false;
  50.     }
  51.         // Update is called once per frame
  52.         void Update () {
  53.         
  54.         }
  55. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

评分

参与人数 3鲜花 +1 +2 收起 理由
碧海归鸿 + 1 1
yugo215 + 1 很给力!
graywolfx21 + 1 很给力!

查看全部评分

发表于 2013-3-5 11:13 | 显示全部楼层

感谢楼主的无私分享!{:soso__11402694654016840197_7:}
发表于 2013-5-29 14:52 | 显示全部楼层
啊,看不懂啊,,我刚下载的Unity,但是提示要注册哦~~~
发表于 2013-6-1 15:28 | 显示全部楼层
找一下源码在哪里
发表于 2013-6-1 22:31 | 显示全部楼层
恳求楼主加注释好么?我连过Sqlite 没试过SqlServer
发表于 2013-7-9 22:30 | 显示全部楼层
感谢楼主的无私分享!
发表于 2013-8-21 21:31 | 显示全部楼层
不提供教程源码下载吗?
发表于 2013-9-3 11:28 | 显示全部楼层
{:soso_e176:} 楼主有没有尝试打包发布啊 我打包发布出问题
发表于 2013-10-4 14:08 | 显示全部楼层
學習了{:5_401:}
发表于 2014-1-7 10:23 | 显示全部楼层
学习了 谢楼主分享
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 02:21 , Processed in 0.664197 second(s), 34 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表