纳金网

标题: unity3d基本广告展示系统 [打印本页]

作者: 晃晃    时间: 2011-8-9 08:29
标题: unity3d基本广告展示系统
算是比较实用的一段代码了,可以参考借鉴下!


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.
?>
作者: Asen    时间: 2011-9-17 10:51

作者: 晃晃    时间: 2012-1-30 23:27
一帆风顺,二龙腾飞,三羊开泰,四季平安,五福临门,六六大顺,七星高照,八方来财,九九同心,十全十美。

作者: 晃晃    时间: 2012-3-4 23:27
不错不错,收藏了

作者: C.R.CAN    时间: 2012-4-20 23:26
路过、路过、快到鸟,列位请继续...ing

作者: 奇    时间: 2012-6-8 23:22
不错哦,谢谢楼主

作者: 菜刀吻电线    时间: 2012-6-17 23:21
发了那么多,我都不知道该用哪个给你回帖了,呵呵

作者: C.R.CAN    时间: 2012-6-28 23:30
不错哦,顶一下......

作者: 奇    时间: 2012-7-31 23:20
非常感谢,管理员设置了需要对新回复进行审核,您的帖子通过审核后将被显示出来,现在将转入主题

作者: 菜刀吻电线    时间: 2012-9-23 23:34
很有心,部分已收录自用,谢谢





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5