- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359
- 纳金币
- 335582
- 精华
- 0
|
算是比较实用的一段代码了,可以参考借鉴下!
var url:String;
var tmrValue:float=0;
var tmrMax:float=6;
var adRect:Rect = new Rect(10,10,728,90);
var keepRatio:boolean = true;
private var www:WWW;
private var tmpWWW:WWW;
private var info;
private var tmpTexture;
private var adLink;
private var lastRect:Rect;
function Start () {
tmrValue = tmrMax;
lastRect = adRect;
}
function Update()
{
if(keepRatio)
{
if(lastRect != adRect)
{
var per:float;
if(adRect.width != lastRect.width)
{
per = adRect.width/lastRect.width;
adRect.height = adRect.height * per;
print(per);
}else if(adRect.height != lastRect.height)
{
per = adRect.height/lastRect.height;
adRect.width = adRect.width * per;
print(per);
}
}
lastRect = adRect;
}
tmrValue += Time.deltaTime;
if(tmrValue >= tmrMax)
{
tmrValue -= tmrMax;
tmpWWW = new WWW(url);
}
if(tmpWWW != null && tmpWWW.isDone)
{
info = tmpWWW.text.Split(":"[0]);
www = new WWW("http:" + info[1]);
adLink = info[2];
tmpWWW = null;
}
if(www != null && www.isDone)
{
tmpTexture = www.texture;
www = null;
}
}
function OnGUI()
{
var tmpGuiStyle:GUIStyle = new GUIStyle();
tmpGuiStyle.margin = RectOffset(0,0,0,0);
tmpGuiStyle.padding = RectOffset(0,0,0,0);
tmpGuiStyle.border = RectOffset(0,0,0,0);
tmpGuiStyle.overflow = RectOffset(0,0,0,0);
if(GUI.Button(adRect, tmpTexture, tmpGuiStyle))
{
Application.OpenURL("http://" + adLink);
}
}
PHP file:
<?php
$tmp = rand(0,5);
echo "http://yourwebsite.com/" . $tmp . ".png:yourwebsite.com?adValue=" . $tmp;
//You would put your connecting to sql database code here and echo out the correct url instead of this.
?> |
|