Je reviens..
Avec de nouveau des problèmes si non cela ne serait pas drôle.
En fait j'ai fait des class Managers : "GUI, MYSQL, Network, input,..."
Sur ces script j'ai une: public static void ConectSQL()
Dans la qu'elle se trouve des variables non static...
Lorsque je fais appel à la fonction directement depuis la class aucun soucis, mais lorsque je fais appels à cette même fonction via un autre script... vous vous doutez certainement de l'érreur ( An object reference is required to access non-static member `MysqlManager.ConectSQL()' )
Normal je sais j'essaie d'accéder à une variable non static via une fonction static dans une autre class...
Dans le passé j'avais réussi à faire fonctionné ce script... mais je ne sais plus comment
Si une âme généreuse peu m'aider ce serais bien gentil
je colle les codes en rapport si jamais mon explicatif n'est pas compris
Code : Tout sélectionner
public class MysqlManager : MonoBehaviour {
public static string host, database, dbuser, dbpassword;
public Text TxtLogin;
private string Username;
private string Password;
private string Password2;
private string Mail;
public static string connectionString;
private MySqlConnection con = null;
public static void ConectSQL(){
connectionString = "Server=" + host + ";Database=" + database + ";User=" + dbuser + ";Password=" + dbpassword + ";Pooling=true;Charset=utf8;";
try{
con= new MySqlConnection(connectionString);
con.Open();
Debug.Log(con.State.ToString ());
} catch(IOException Ex){
Debug.Log(Ex.ToString ());
}
}
void OnApplicationQuit(){
Debug.Log ("Application férmée");
if (con != null && con.State.ToString () != "Closed") {
con.Close ();
Debug.Log ("SQL Shutdown");
}
}
public static void Register(){
ConectSQL ();
string cmdString = "INSERT INTO user (username, password, mail) VALUES ('" + GUIManager.IfUsername + "', '" + GUIManager.IfPassword + "', '" + GUIManager.IfMail + "')";
MySqlCommand cmd = new MySqlCommand (cmdString, con);
try {
cmd.ExecuteReader ();
Debug.Log("Register successful");
GUIManager.TxtClient.text = "Register successful";
} catch(IOException Ex) {
Debug.Log (Ex);
}
cmd.Dispose ();
con.Close ();
}
void CheckSql (){
if (con != null) {
Debug.Log(con.State.ToString ());
} else {
Debug.Log("Closed");
}
}
Code : Tout sélectionner
if (MenuIs == "CreateAccount") {
GUI.Box (new Rect (Screen.width/2 - 50, Screen.height/2 - 10, 100, 20), "Create Account");
GUI.Box (new Rect (Screen.width/2 - 90, Screen.height/2 + 15, 100, 20), "Username :");
IfUsername = GUI.TextField (new Rect (Screen.width/2 , Screen.height/2 +15, 120, 20), IfUsername);
GUI.Box (new Rect (Screen.width/2 - 90, Screen.height/2 + 40, 100, 20), "Password :");
IfPassword = GUI.TextField (new Rect (Screen.width/2 , Screen.height/2 +40, 120, 20), IfPassword);
GUI.Box (new Rect (Screen.width/2 - 125, Screen.height/2 + 65, 125, 20), "Confirm Password :");
IfPassword2 = GUI.TextField (new Rect (Screen.width/2 , Screen.height/2 +65, 120, 20), IfPassword2);
GUI.Box (new Rect (Screen.width/2 - 75, Screen.height/2 + 90, 75, 20), "E-mail :");
IfMail = GUI.TextField (new Rect (Screen.width/2 , Screen.height/2 +90, 120, 20), IfMail);
if(IfUsername != "" && IfPassword != "" && IfPassword2 != "" && IfMail != ""){
if (GUI.Button (new Rect (Screen.width/2 - 75, Screen.height/2 + 135, 150, 30), "Create Account")) {
//todo for create account
Debug.Log("Script create account");
if (IfPassword != IfPassword2) {
createrror = "Password no match";
}
TxtClient.text = createrror;
if (IfUsername == "verification BDD") {
//verification Unique username
createrror = "Username already use";
}
if (IfMail == "verification BDD") {
//verification Unique mail
createrror = "Mail already use";
} else {//creating account
MysqlManager.Register();
}
}
}
}// END Menu create account