简体   繁体   中英

Unity3d WebGL browser communication form

I have a program running through unity3d webGL, it works pretty well but I found getting feedback from people within the program is becoming a problem.

So I created a very basic form that the user can fill out in the program, press send and it will send to me.

My problem is that the information coming through is a sequence of numbers and not the messages.

Here is the various parts of the code if you spot something please let me know.

C# Unity3d form code

public void Send_help()
{
    string the_date = DateTime.Now.ToString ("yyyy MMMMM dd");
    string the_message = help_message.text;
    string the_email = help_email.text;

    Tcontroller.GetComponent<Trcontroller> ().Send_helpMessage (the_date,the_email,the_message);
    Help_stuff.gameObject.SetActive (false);
    audio.PlayOneShot (next);
}

The Send_helpMessage in the Tcontroller

private static extern void Message_help(string d, string e, string m);
[DllImport("__Internal")] //The imported function in my pluggin

public void Send_helpMessage(string date, string email, string message)
{
    Message_help (date, email, message);
}

The pluggin code

    var talk = {
        Message_help: function(d,e,m)
        {
            Send_message_help(d,e,m);
        }

    };

    mergeInto(LibraryManager.library, talk); 

The website code

    var this_date = '';
    var this_email = '';
    var this_message = '';

    function Send_message_help(d,e,m)
    {
        this_date = d;
        this_email = e;
        this_message = m;

        var Data = '&this_date='+this_date+'&this_email='+this_email+'&this_message='+this_message;
        $.ajax({
            url : "message.php",
            type: "POST",
            data : Data
        }); 
    };

Finally the pHp code

$MS = new mysqli ( $db_host, $db_username, $db_pass, $db_name );

    $this_date = $_POST['this_date'];
    $this_email = $_POST['this_email'];
    $this_message = $_POST['this_message'];


    $sqlupdate_user_message = "INSERT into contact(email, date, message) values('$this_email','$this_date','$this_message')";
    mysqli_query ( $connMS, $sqlupdate_user_message );

    mysqli_close($MS);

You can put any type of string value you want, the output to the database comes across as numbers

db_view

I know that WebGL is still new but it serves my purpose and everything else in terms of communication between webgl and the database has been fine with the exception of this form. Thanks for help in advance.

Please try this in plugin code(*.jslib):

var talk = {
    Message_help: function(d,e,m)
    {
        var date = Pointer_stringify(d);
        var email = Pointer_stringify(e);
        var message = Pointer_stringify(m);
        Send_message_help(date,email,message);
    }

};

mergeInto(LibraryManager.library, talk); 

When you send string from Unity WebGL to jslib, you need Pointer_stringify helper function to change it back to string. You can find more on this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM