local Logon={}
local go=nil --游戏物体
local username=nil --用户名输入
local password=nil --密码输入
local logonBtn=nil --登录按钮
local regionBtn=nil --注册按钮
--初始化面板
function Logon:Init()
go = GameObject.Instantiate(Resources.Load("Logon")) --加载登录面板
username=go.transform:Find("BG/UserName/Sprite"):GetComponent("UIInput") --获取登录面板下的用户名输入框
password=go.transform:Find("BG/Password/Sprite"):GetComponent("UIInput") --获取登录面板下的密码输入框
logonBtn=go.transform:Find("BG/Logon"):GetComponent("UIButton").gameObject --获取登录面板下的登录按钮
regionBtn=go.transform:Find("BG/Region"):GetComponent("UIButton").gameObject --获取登录面板下的注册按钮
Utils.AddClick(logonBtn,Logon.logonClick) --登录按钮添加事件
Utils.AddClick(regionBtn,Logon.regionClick) --注册按钮添加事件
end
--登录按钮的点击事件
function Logon.logonClick()
local userName=username.value --给用户名赋值
local userPwd = password.value --给密码赋值
logonname=username.value --给登录名赋值
print(string.byte(userName)) --输出用户名
if(string.byte(userName)>68 and string.byte(userName)<200) then --判断用户名带字母后的阿西马值
if(string.len(userName)>=6) then --判断用户名长度
print("123")
coroutine.start(Logon.LoadWWW,Logon,userName,userPwd) --协成
end
else
print("不符合要求")
end
end
--注册按钮点击事件
function Logon.regionClick()
GameObject.Destroy(go) --登录面板销毁
Region:Init() --注册初始化
end
--加载Web服务器
function Logon:LoadWWW(user,pwd)
local url=string.format("http://127.0.0.1:8080/WebService1.asmx/Logon?userName=%s&userPwd=%s",user,pwd) --网址get请求
local www=WWW(url)
coroutine.www(www)
assem=www.text
print(assem)
if assem=="sucess" then
GameObject.Destroy(go) --登录面板销毁
air:Init() --飞机面板初始化
end
end
return Logon
local Region={}
local go=nil
local username=nil
local password=nil
local logonBtn=nil
local regionBtn=nil
function Region:Init()
go = GameObject.Instantiate(Resources.Load("Region"))
username=go.transform:Find("BG/UserName/Sprite"):GetComponent("UIInput")
password=go.transform:Find("BG/Password/Sprite"):GetComponent("UIInput")
logonBtn=go.transform:Find("BG/LogonBtn"):GetComponent("UIButton").gameObject
regionBtn=go.transform:Find("BG/RegionBtn"):GetComponent("UIButton").gameObject
pwd=go.transform:Find("BG/Psd/Sprite"):GetComponent("UIInput")
Utils.AddClick(logonBtn,Region.logonClick)
Utils.AddClick(regionBtn,Region.regionClick)
end
function Region.logonClick()
GameObject.Destroy(go)
Logon.Init()
end
function Region.regionClick()
local userName=username.value
local userPwd = password.value
local pp=pwd.value
print(string.byte(userName))
if(string.byte(userName)>68 and string.byte(userName)<200 and string.byte(userPwd)>68 and string.byte(userPwd)<200) then
if(string.len(userName)>=6 and string.len(userPwd)<200) then
if(string.len(userName)>=6 and string.len(userPwd)>=6) then
if(pp==userPwd) then
coroutine.start(Region.LoadWWW,Region,userName,userPwd)
end
end
end
else
print("不符合要求")
end
end
function Region:LoadWWW(user,pwd)
local url=string.format("http://127.0.0.1:8080/WebService1.asmx/RegionDemo?userName=%s&userPwd=%s",user,pwd)
local www=WWW(url)
coroutine.www(www)
assem=www.text
print(assem)
if assem=="sucess" then
GameObject.Destroy(go)
Logon:Init()
end
end
return Region
local air={}
local go=nil
local begin=nil
local gg=nil
local timer=nil
local num=20
local hp=nil
local ws=1
function air:Init()
gg = GameObject.Instantiate(Resources.Load("Demo"))
begin=gg.transform:Find("Begin"):GetComponent("UIButton").gameObject
timer=gg.transform:Find("Countdown/timer"):GetComponent("UILabel")
hp=gg.transform:Find("HP/hp"):GetComponent("UILabel")
gr=gg.transform:Find("Grade/grade"):GetComponent("UILabel")
Utils.AddClick(begin,air.BeginDemo)
end
local a=0
function air.BeginDemo()
print("123")
coroutine.start(LoadWWW)
end
function LoadWWW()
local url="http://127.0.0.1:8080/StreamingAssets/air.unity3d"
local conect=WWW(url)
coroutine.www(conect)
if conect.error==nil then
GameWWW(conect)
end
end
function GameWWW(conect)
greencube=conect.assetBundle:LoadAsset("GreenCube")--绿障碍物
redcube=conect.assetBundle:LoadAsset("RedCube")--红障碍物
blackcube=conect.assetBundle:LoadAsset("BlackCube")--黑障碍物
cube={greencube,redcube,blackcube}
go=GameObject.Instantiate(conect.assetBundle:LoadAsset("air"))
Move()
bullet=conect.assetBundle:LoadAsset("BoltPre")
end
function Move()
UpdateBeat:Add(Update)
end
function Update()
local h=Input.GetAxis("Horizontal")
local v=Input.GetAxis("Vertical")
if(h~=0 or v~=0) then
go.transform:Translate(Vector3.New(h,0,v))
end
v3=go.transform.position
--边界限定
v3.x= Mathf.Clamp(v3.x+h*0.2,-4,4)
v3.z= Mathf.Clamp(v3.z+v*0.2,-5,7)
go.transform.position=v3
num=num-Time.deltaTime
timer.text=tostring(math.ceil(num))
sum=tonumber(hp.text)
if num<=0 or sum==0 then
timer.text=tostring(0)
if ws==1 then
Ranking:Init()
gg:SetActive(false)
ws=2
end
else
DJ()
end
ZD()
end
--子弹生成于删除
function ZD()
if(Input.GetMouseButtonDown(0)) then
bu1=GameObject.Instantiate(bullet)
bu1.transform.position=go.transform.position+Vector3.New(1/90,0,2)
GameObject.Destroy(bu1.gameObject,3)
end
end
index=0
--障碍物
function DJ()
index=index+Time.deltaTime
if(index>=5) then
index=0
dj=nil
for k,v in pairs(cube) do
dj=GameObject.Instantiate(v)
end
dj.transform.position=Vector3.New(Random.Range(-3,3),go.transform.position.y,Random.Range(5,7))
GameObject.Destroy(dj.gameObject,5)
end
end
return air
local Ranking={}
local user=nil
local grade=nil
local go=nil
local us=nil
local usergrad=nil
function Ranking:Init()
go=GameObject.Instantiate(Resources.Load("Ranking"))
user=go.transform:Find("Scroll View/Container/user"):GetComponent("UILabel")
grade=go.transform:Find("Scroll View/Container/grade"):GetComponent("UILabel")
print(gr.text)
grade.text=gr.text
user.text=logonname
print(grade.text)
end
return Ranking;