I’m attempting to use the Unity Browser as a sort of 3D interactive database viewer.
Is there a method or tutorial somewhere that someone can point me to so I can begin working on creating a persistant visual database based on user input for specific feilds?
Your question has quite a big scope and tutorials on database related stuff is scares. If you can elaborate a bit what your database will hold, how complicated, what platform are you planning to use (php, asp.net?) etc. It normally works on the pricniple of posting var values to something like a php file, which them do the database interaction. But like I said, you need to be a bit more specific.
I’m attempting to to create a database that will contain simple information. Think of it like a gamer clan database. The basic information it would contain is the following:
First Name
Last Name
Alias/Nick
Geographic Location
Game
Clan Name
History Past Games, Genres, Clans
I was thinking of putting this into a SQL database, but I’m curious if Unity can read data from those files? If not SQL, can Unity read other database types? If not, what other methods can I use to accomplish the same results? The purpose is to create a visual database/history in real time to the viewer via the Unity Web Player. This is kind of an experiment on interface and information interaction.
I’m interested also in transferring information from a database into a unity browser and back.
i can can create a var with a value from a database such as
var x = <%RESPONSE.WRITE(valueFromDataBase)%>
how do i get the Unity browser to take that value and use it to as the x value for an object’s position or rotation?
then how do you make the Unit Browser update that variable in the web browser which i could then assign to form input and write back to the database.
thank you
The first part of your question seems pretty straight forward: assigning var x to the objects x position/rotation. As for writing an updated value back to the database, I do not know enough about scripting in Unity to help with that.
Where Unity will do all of this. (with the WWW Object and PHP or ASP code on the other side) Unity is not the best “tool” to do this in. Consider HTML and HTML5/Flash to do this in. It is lighter and handles large text documents better than Unity does.
Unity can be used to do this. Use the WWW Object to communicate to a web server, that server gets and puts information into the database. The data returned can be formatted however you need it in Unity.
So your tutorials are on how to get data from your database and return them as text, then simply use the WWW object and string processors to display the data in your application. (almost the exact explanation for any application.
)
Here is an example I used recently to read and write user login info
What I like about this is that you never leave the unity environment. I have not tested this with the web version, only stand-alone, but I cant see any reason why the web version won’t work.
Here is the code that goes into the login button.
if (GUI.Button(new Rect(Screen.width / 2 + (140), Screen.height * 0.6f, 80, 35), "Webform") uname != "" password != "")
{
results.result_url = result_url;
WWWForm form = new WWWForm();
form.AddField("uname", uname);
form.AddField("password", password);
WWW w = new WWW(variable_url, form);
StartCoroutine(Login(w));
}
this calls this part of the code/function:
IEnumerator Login(WWW w)
{
yield return w;
if (w.error == null)
{
if (w.text == "success")
{
print("suscces");
game_variables.uname = uname;
game_variables.password = password;
show_welcome = true;
show_login_details = false;
}
else
{
login_message = ("Could not log in, please try again.");
show_welcome_login_message = true;
}
}
else
{
show_welcome_login_message = true;
}
}
and here is the php script that resides in my domain
<?php
$user = $_POST['uname'];
$password = $_POST['password'];
$myServer = "myDomain.co.za";
$myUser = "my_username";
$myPass = "my_password";
$myDB = "my_game";
$con = mysql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
$selected = mysql_select_db($myDB, $con) or die("Couldn't open database $myDB");
$query = "SELECT uname, password ";
$query .= "FROM tfg_game_users ";
$query .= "WHERE uname='". $user ."' AND password = '". $password ."'";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if($numRows > 0)
{
die("success");
}
else
{
die("result: " . $user . " " . $password);
}
?>
and you can obviously use the same method to write to the database, using POST as above. Hope this can help someone, but as the code stands it is working 100%
How would I do this inside Unity? Is there a way to send SQL commands to a db-file through buttons in the Unity browser?
All of the ODBC stuff and general Database connection structures in .net reside in the System.Data Namespace. This Namespace is not accessible directly through Unity. This is not to say that there are not plugins or someone hasn’t written a way around this. But it is far simpler if you are working with a web server to use the WWW object to pass sql code or sectionalize your code to produce sql on the server using PHP or ASP.
Ok if I can’t access it directly through SQL queries. Can I access it via PHP intermediary variables ?