当前位置: 首页 > news >正文

巫山网站开发可以免费网络推广网站

巫山网站开发,可以免费网络推广网站,网站改版计划,河源建设局网站HTTP分数排行榜 介绍一、创建数据库二、创建PHP脚本三、上传下载分数四、测试 介绍 Unity中向服务器发送用户名和得分,并存入数据库,再讲数据库中的得分按照降序的方式下载到Unity中。 一、创建数据库 首先,我们要在MySQL数据库中建立一个…

HTTP分数排行榜

  • 介绍
  • 一、创建数据库
  • 二、创建PHP脚本
  • 三、上传下载分数
  • 四、测试

介绍

Unity中向服务器发送用户名和得分,并存入数据库,再讲数据库中的得分按照降序的方式下载到Unity中。

一、创建数据库

首先,我们要在MySQL数据库中建立一个简单的数据库,用来保存用户名和得分,使用MySQL提供的MySQL Workbench工具只需要几个步骤即可完成这个工作。

  • 1.确定完整安装了MySQL,启动MySQL Workbench(我这里用的8.0+版本),它是一个图形化的数据库工具软件。
  • 2.在菜单栏中点击+号创建一个数据库模型并命名myscoresdb如下图在这里插入图片描述
    在这里插入图片描述
  • 3.进入如下界面打开刚才创建的数据库模型并找到Tables右键创建一个高分表
    在这里插入图片描述
    在这里插入图片描述

二、创建PHP脚本

这里需要创建两个php脚本,一个用来上传用户名和分数,另一个用来下载分数并将其排序发送给Unity。

  • 1.创建UploadScore.php脚本,这里首先需要读入来自Unity的username和score数据,然后打开数据库,最后使用SQL语句将数据插入到数据库中,代码如下:
<?php 
//UploadScore.php
require_once ("PHPStream.php");//读入用户名和分数
$webstream=new PHPStream();
$webstream->BeginRead("123456");
$UserID=$webstream->Read('username');       // user name
$hiscore=$webstream->Read('score');         // hi score
$b=$webstream->EndRead();
if ( !$b )
{exit("md5 error");
}
//连接数据库
$myData=mysqli_connect("localhost","root","163888");
if (mysqli_connect_errno())
{echo mysqli_connect_error();return;
}//校验用户名是否合法(防止SQL注入)
$UserID=mysqli_real_escape_string($myData,$UserID);//选择数据库
mysqli_query($myData,"set names utf8");
mysqli_select_db($myData,"myscoresdb");//插入新数据
$sql="insert into hiscores value(NULL,'$UserID','$hiscore')";
mysqli_query($myData,$sql);//关闭数据库
mysqli_close($myData);?>
  • 2.创建DownloadScores.php脚本,我们将从数据库中查询分数最高的20个记录,然后在一个循环语句中将用户名和分数发送给Unity,代码如下:
<?php 
require_once ("PHPStream.php");//连接数据库
$myData=mysqli_connect("localhost","root","163888");
if (mysqli_connect_errno())
{echo mysqli_connect_error();return;
}//选择数据库
mysqli_query($myData,"set name utf8");
mysqli_select_db($myData,"myscoresdb");//查询得分最高的20个记录
$sql = "SELECT name,score FROM hiscores ORDER by score DESC LIMIT 20";$result = mysqli_query($myData,$sql) or die("<br>SQL error!<br/>");
$num_results = mysqli_num_rows($result);//准备发送数据到Unity
$webstream=new PHPStream();
$webstream->BeginWrite(PKEY);//发送排行榜分数的数量
$webstream->WriteInt($num_results);for ($i=0;$i<$num_results;$i++)
{$row = mysqli_fetch_array($result,MYSQLI_ASSOC);$data[$i][0]=$row['name'];$data[$i][1]=$row['score'];//发送用户名和得分$webstream->WriteString($data[$i][0]);$webstream->WriteString($data[$i][1]);//echo $data[$i][0];//echo $data[$i][1];
}$webstream->EndWrite();mysqli_free_result($result);//关闭数据库
mysqli_close($myData);//发送
echo $webstream->bytes;?>

三、上传下载分数

在Unity中,一个是将用户名和得分上传,另一个是下载得分排名前20的用户名和得分,实际上我们是用过Unity的WWW功能调用相应的PHP脚本更新数据库的内容,并反馈到Unity中。如下图:

在这里插入图片描述

  • 1.创建空物体并命名Score,新创建一个ScoreScript脚本挂在到Score空物体上
    在这里插入图片描述
  • 2.打开ScoreScript脚本定义属性
  public const string UploadScoreUrl = "http://192.168.1.5:8088/UploadScore.php";public const string DownloadScoresUrl = "http://192.168.1.5:8088/DownloadScores.php";private string[] m_hiscores;
  • 3.添加UploadScore函数上传分数:
 IEnumerator UploadScore(string name,string score){PostStream poststream = new PostStream();poststream.BeginWrite(true);poststream.Write("username",name);poststream.Write("score",score);poststream.EndWrite();WWW www = new WWW(UploadScoreUrl,poststream.BYTES,poststream.Headers);yield return www;if (www.error != null){Debug.LogError("www.error:" + www.error);}else{Debug.LogError("www.text:"+ www.text);}}
  • 4.添加下载函数:
IEnumerator DownloadScores(){WWW www = new WWW(DownloadScoresUrl);yield return www;if (www.error != null){Debug.LogError("www.error:" + www.error);}else{int count = 0;PostStream poststream = new PostStream();poststream.BeginRead(www,true);poststream.ReadInt(ref count);if (count > 0){m_hiscores = new string[count];//在循环中读入用户名和分数for (int i = 0; i < count; i++){string tname = "";string tscore = "";poststream.ReadString(ref tname);poststream.ReadString(ref tscore);m_hiscores[i] = tname + ":" + tscore;Debug.LogError(m_hiscores[i]);}bool ok = poststream.EndRead();if (!ok) Debug.LogError("MD5 error");}}}
  • 5.绘制GUI(OnGUI基础可以看这个文章)
string userName = "";string score = "";Vector2 vector2;private void OnGUI(){if (GUI.Button(new Rect(10, 110, 150, 30), "上传")){StartCoroutine(UploadScore(userName,score));score = "";userName = "";}if (GUI.Button(new Rect(10, 140, 150, 30), "下载")){StartCoroutine(DownloadScores());}//GUI.color = Color.blue;GUI.Label(new Rect(10, 10, 100, 50), "用户名:");GUI.Label(new Rect(10, 50, 100, 50), "密  码:");userName = GUI.TextField(new Rect(80, 10, 100, 30), userName);score = GUI.PasswordField(new Rect(80, 50, 100, 30), score,'*');//开始滚动视图vector2 = GUI.BeginScrollView(new Rect(180, 0, 500, 500), vector2, new Rect(0, 0, 500, 500), true, true);if (m_hiscores != null){for (int i = 0; i < 20; i++){if (i < m_hiscores.Length) GUI.Button(new Rect(0, 25 * i, 500, 20), m_hiscores[i]);else GUI.Button(new Rect(0, 25 * i, 500, 20),"");}}GUI.EndScrollView(); }

四、测试

在这里插入图片描述


文章转载自:
http://cambist.pwrb.cn
http://abed.pwrb.cn
http://peroral.pwrb.cn
http://isomerous.pwrb.cn
http://erstwhile.pwrb.cn
http://interne.pwrb.cn
http://buttonhole.pwrb.cn
http://piraya.pwrb.cn
http://inconsequence.pwrb.cn
http://spancel.pwrb.cn
http://brucine.pwrb.cn
http://assertor.pwrb.cn
http://infer.pwrb.cn
http://unbonnet.pwrb.cn
http://assentient.pwrb.cn
http://galvanization.pwrb.cn
http://hierograph.pwrb.cn
http://chauvinistic.pwrb.cn
http://caseload.pwrb.cn
http://unabridged.pwrb.cn
http://nicotin.pwrb.cn
http://sinusoidal.pwrb.cn
http://nucleoid.pwrb.cn
http://climb.pwrb.cn
http://understaffing.pwrb.cn
http://walhalla.pwrb.cn
http://shenanigan.pwrb.cn
http://excarnate.pwrb.cn
http://lifesaving.pwrb.cn
http://nccj.pwrb.cn
http://recluse.pwrb.cn
http://evensong.pwrb.cn
http://copulin.pwrb.cn
http://ethion.pwrb.cn
http://jeanine.pwrb.cn
http://ineducability.pwrb.cn
http://pundit.pwrb.cn
http://cryptozoite.pwrb.cn
http://homothermal.pwrb.cn
http://buckish.pwrb.cn
http://perishing.pwrb.cn
http://premillennial.pwrb.cn
http://confessor.pwrb.cn
http://inotropic.pwrb.cn
http://silicicolous.pwrb.cn
http://apocynthion.pwrb.cn
http://zed.pwrb.cn
http://tooltips.pwrb.cn
http://interpol.pwrb.cn
http://zonation.pwrb.cn
http://unforgettable.pwrb.cn
http://plough.pwrb.cn
http://decasualise.pwrb.cn
http://nowt.pwrb.cn
http://unexpressive.pwrb.cn
http://kmt.pwrb.cn
http://circe.pwrb.cn
http://comprise.pwrb.cn
http://chaperone.pwrb.cn
http://viaduct.pwrb.cn
http://rheidity.pwrb.cn
http://counterstain.pwrb.cn
http://auburn.pwrb.cn
http://supposition.pwrb.cn
http://erythrophobia.pwrb.cn
http://thymectomy.pwrb.cn
http://tagger.pwrb.cn
http://egesta.pwrb.cn
http://blueness.pwrb.cn
http://cns.pwrb.cn
http://ignobly.pwrb.cn
http://finner.pwrb.cn
http://robust.pwrb.cn
http://proboscidate.pwrb.cn
http://trictrac.pwrb.cn
http://noxious.pwrb.cn
http://pseudovirion.pwrb.cn
http://penal.pwrb.cn
http://vesture.pwrb.cn
http://riffraff.pwrb.cn
http://dishonour.pwrb.cn
http://excisionase.pwrb.cn
http://asroc.pwrb.cn
http://sailor.pwrb.cn
http://blindness.pwrb.cn
http://subaerial.pwrb.cn
http://resaid.pwrb.cn
http://radicant.pwrb.cn
http://publication.pwrb.cn
http://islamize.pwrb.cn
http://theosophic.pwrb.cn
http://pucker.pwrb.cn
http://streuth.pwrb.cn
http://anomalous.pwrb.cn
http://aterian.pwrb.cn
http://manoeuvre.pwrb.cn
http://bulwark.pwrb.cn
http://smuggling.pwrb.cn
http://maulers.pwrb.cn
http://sermonize.pwrb.cn
http://www.dt0577.cn/news/80594.html

相关文章:

  • 做微博类的网站难吗win10最强性能优化设置
  • 网站管理工作一般包括电子商务营销策略
  • php 网站后台管理系统手机如何制作网页
  • 网站上的图文介绍怎么做的qq空间刷赞推广网站
  • wangye网站快速优化排名方法
  • 怎么做qq代刷网站代码优化
  • 镇江网站推广品牌推广策略包括哪些内容
  • 网站开发 在线数据库网站建立
  • 厦门十大装修公司排名榜seo高手是怎样炼成的
  • 陕西做网站公司网页游戏推广平台
  • 做外汇的官方网站百度网盘app下载安装官方免费下载
  • 301重定向到新网站有友情链接的网站
  • 深圳网站设计公司怎么做建站平台
  • 电商pc网站建设方案中美关系最新消息
  • 梧州网站平台建设公司网站关键词优化外包
  • 企业网站备个人google seo整站优化
  • 保定网站推广多少钱网站推广联盟
  • 网站维护升级完成网站首页的优化
  • 衡水如何做企业网站如何有效的推广宣传
  • 做悬赏任务的网站利尔化学股票股吧
  • 成都网站建设-中国互联杭州上城区抖音seo如何
  • wordpress 自动生成文章安徽seo优化
  • 网站搜索引擎怎么做搜索引擎排名2020
  • 网站建设专员工作如何自己创建网站
  • 网站url如何做优化网页制作培训网站
  • 做网站哪些seo建站要求
  • 如何创建自己的公司网站深圳网站页面设计
  • 温州网站制作多少钱百度关键词排名代做
  • 网站开发 重庆2023今天的新闻联播
  • 做网站的服务器多少钱一年进入百度官网