public var scriptEnabled:boolean = false; //Set to true when you want the score submitted.
//public var windowRect : Rect = Rect (20, 20, 20, 20);
//public var useSizeAsPadding:boolean = true;
public var phpScriptFolder:String = "http://example.com/leaderboard/";
public var cellWidth:int = 100;
public var sortBy:String = "var0";
public var start:int = 0;
public var count:int = 100;
public var condition:String[]; //This is for selecting levels, usernames, etc. IE, using my default 4 variables,
// to check for a level named demo you would type in var3 = "Demo"
public var exclusionList:String[] = ["id"];
public var direction:String = "DESC"; //DESC for descending ASC for ascending
public var refresh:boolean = false;
//public var guiID:int = 1;
public var labelScore:GameObject;
private var i:int = 0;
var scores
:Array
= new Array
(""); private var gettingScores:boolean = false;
function Start()
{
for(i = 0; i<= count; i++)
{
scores.Push("");
}
i=0;
}
function Update()
{
if(refresh)
{
GetScores();
refresh = false;
}
}
function GetScores()
{
gettingScores = true;
var tmpExclude:String;
for(var field in exclusionList)
{
if(field != "")
{
tmpExclude += field + "~";
}
}
var conditions:String = "&conditions=";
for(i = 0; i < condition.Length; i++)
{
conditions += condition[i].Replace("=", "----").Replace(" ", "%20") + "~"; //Replace fixes not having the extra = in a url, which breaks the url.
}
var res
:WWW
= new WWW
(phpScriptFolder
+ "/getScores.php?sort=" + sortBy
+ "&direction="+ direction
+ "&start=" + start
+ "&limit=" + count
+ "&exclude=" + tmpExclude
+ conditions
); print(phpScriptFolder + "/getScores.php?sort=" + sortBy + "&direction="+ direction + "&start=" + start + "&limit=" + count + "&exclude=" + tmpExclude + conditions);
yield res;
print(res.text);
var resTmp = res.text;
var tmp:Array = resTmp.Split("\\"[0]);
scores = tmp;
gettingScores = false;
//NGUIScorePrint ();
}
function OnGUI ()
//function NGUIScorePrint ()
{
if(scriptEnabled)
{
if(scores[0] == "")
{
if(gettingScores == false)
{
GetScores();
}
}
else
{
Leaderboard();
}
if(scores[0] != "")
{
//Resets scores so that it looks for new information when displayed again.
for(i =0; i<= count; i++)
{
scores.Push("");
}
}
}
}
function Leaderboard ()
{
for(i = 0; i <= scores.Count-1; i++)
{
var tmp:Array = scores[i].ToString().Split("\\"[0]);
var j:int = 0;
for(j = 0; j <= tmp.Count-1; j++)
{
//labelScore.GetComponent(UILabel).text = tmp[j].ToString();
labelScore.GetComponent(UILabel).text = scores.ToString();
}
}
}