Search Unity

Unity3d in Web-browser + asp-net + sql - possible?

Discussion in 'Getting Started' started by IvanDonets, Mar 10, 2021.

  1. IvanDonets

    IvanDonets

    Joined:
    Feb 19, 2014
    Posts:
    117
    Hello, I am studying programming, we have a course in asp.net, but it is for browser (making shops etc - 2d and no 3d and no animation, - no Unity3d). I have experience in Unity3d and in SQL (Ms sql and MySQL).

    I want to make a program like a Spinnakers Story Machine (see
    )
    it should be kiind of simple program/game for children, in which one can type simple phrases from limited dictionary (nouns, verbs etc).

    So what is required:
    user should be able to use browser (nothing to install) (I want cross-platfrom, but if not possible, I have to stick to Windows only Unity3d-client outside of www-browser). He writes a text into some textbox. Some phrase like "a dog goes to a boy". Then he presses button (usually it uses "POST" action in FORMs in HTML to send data to server to some page with back-script in C#)... then server should receive the request with text inputted. It must go to SQL-server database with 3d models matching nouns and verbs matching animation etc, - to SharpNLP (or similar program like BookNLP) to analyze the phrase/sentence, and make part-of-speech tagging (I did a bit of it already in Unity) -> then it goes to XML and JSON or similar file. Yes, it might be sended into user's browser back, and Unity3d object in web-browser should be able to gt that json file (or maybe even binary files with 3d-models fbx (or compiled fbx?) and animations and other data (like positions of 3d models, where to instantiate them, textures, animation-controller for 3d character etc) - and so when user has reloaded page (I hope it is not reloaded, but only part is POSTed and received without reloading, asynchronously like in AJAX maybe), and thus after user types a sentence - he must receive data from server and be able to see instantiated character like that Dog (from prefab sent through stream from server as file or I don't know how) and that Boy (probably all 3d-models in LEGO-style or similar, smily and happy), and when server decided the locations for the 2 models, he also sends animation for dog to animate it (him\her), aplies coordinates for pathes to go, and dog goes to the boy, like in spinnakers story machine...

    Is this all right to use asp net for this? or should I use something diferent? how do people make online unity3d games with many players? I think something like this is used?

    any advices are very welcome, and thanks to anyone who answers in advance.

    Ivan
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    yes thats possible, can use unity webrequest (for those POST/GET..)
    https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html
    or websockets would work also, if need it to be faster, there's also ready multiplayer frameworks for unity webgl.

    models can be loaded, asset store has plugins for runtime importers (OBJ is most common probably).

    another option is to use asset bundles (those need to be created inside unity editor though)
    https://learn.unity.com/tutorial/introduction-to-asset-bundles
    this is required if you want to send unity specific components and features with those models (colliders, animations, effects etc.)

    can use any server backend, asp/php/python/nodejs or anything else that you are familiar with.
     
  3. IvanDonets

    IvanDonets

    Joined:
    Feb 19, 2014
    Posts:
    117
    ngear, thank you for answering.
    I am familiar with node.js- it was my last most recent more or less complete project. I had in browser some form to do CRUD operations, one form to upload picture, few forms for creating some record in table with path to image, and similarly buttons with POST actions for delete and Update (change) record... Sleect was done using simple GET request to get most recent json file which simply lists all results from SQL database. i mean when I send request to server (I did it on my Android, installed through Termux, plus MySQL, and around 50+ libraries for node-js to make it all work, always have to run node-js daemon before using server) - it simply has running .js file (run in termux using command like "node myserver.js"), so it is very simple, and I am amazed how very little code it required.
    So ther were just few blocks which simple gets POST request, which gets a file (it required special tag for binary data, it is incomatible with posting fields from elelments withing FORM tag, like "input" etc), so user can upload picture to server. Another function on node.js server was to get another page for "create" operation, similar for update, delete, select etc. in select SQL command is simply run, and result is simply written directly to file on server. So browser simply gets it, and then inside browser user parses it to LocalStorage and generates table (though generating html file on server prooved to be more reliable and not that buggy).

    So, ngear (sorry for writing it so detailed), I think I'ld like to try Unity3d with node-js server, probably.
    If you have any links for making hello world server for Unity3d (like I described above for simple CRUD operations, I just expect to uppload some phrases, sentences to node-js or maybe other kind of server) - can you provide it?

    as for c# server. I tried to make it from scratch using some simple server which supported only GET operation to send file to browser. it was a big head-ache and buggy because of streams, and mostly crashed...
    What I managed to do, is that user had WinForms app, it could do some CRD operation locally, then if some CRUD operation is to be posted to server, - I createad 7xip (.7z) file, inserted into it picture for uploading, and .sql file with sql- command (generated in Winforms) (like "insert into mytable (variable) values ("val") ) etc
    so it was OK, then simplest c# server got the file (though it never knew the filename), unpacked it, and executed .sql file, if there was a picture - file was put on server also, and result was generated ("select * from mytable") and putted to html file as table, and sent back to user (maybe also as .7zip file with pictures in archieve etc)...

    So, I have really no idea how unity3d can do similar things. If Unity don't require browser for it, and even if that whole solution (server + client) are both on one and same local Windows PC (I have Win8.1), still I have no idea how Unity3d can access database. I believe that some common c# libraries are available, which don't require any visualization (like WinForms, WPF etc), so maybe that will work inside Unity3d. But then I really have no idea how Unity3d can change anything "on the run" (while in runtime) if it wants to get some resource from external file (especially if it is on remote server, which is not user's local PC)...

    I've got a little experience makiing simple network app in Unity3d. I tried Unity3d network manual, there was something with robot, and I even tried it with some "volunteer" here on Unity3d site - we simply wanted to make network game, but it was not that easy, beacuse it all required some "tokens" or concurent users - some kind of hosting to let some number of users play on someone's server. it worked free but no so well. i don't remember name of that Unity3d net server.

    I also tried just make very simple network Unity3d program, which can simply post some text to some port in Unity3d, so message can be received, answer is shown in some "label" in Unity.
    I may understand how this can work in 2d without animation (like in browser), but my idea is to use power of Unity's animation and 3D-graphics ... Have no idea where to start with to learn to make this all work.

    If there is some "hello world" Unity3d network app which has client and server to post something to user - say, instantiate command for 3d-model, set it's coordinates, and make it walk for example - this would be enough to make anything else. and yes, I have zero experience in Unity3d with databases. Never tried (any manual on this subject would also do). And also please tell me only about free soultions for all these (ifthere is a choice between free and commercial library for unity3d for netwrok/database etc - I'ld prefer free, say, I'ld like MySQL over MS-SQL).
     
  4. IvanDonets

    IvanDonets

    Joined:
    Feb 19, 2014
    Posts:
    117
    -------------------------------

    1) I understand what is Request from Browser (or say XML requestto get JSON or other file) especially if that's JavaScript. But what about response from Unity server? How to program that?
    Is there simple "hello world" program for posting some string to server (using this UnityWebRequest)
    and getting some answer as binary file (well, I'ld prefer to avoid streams as this is kind of "hellish hell" as to my experiance, but just get as file, and I'm not interested what's inside that "black box" - those streams, synchronization\threads and how this works inside - it's to technical to me, I not that geek) or resource etc - so that it can be downloaded into browser and shown updated\changed (I mean any CRUD operation with 3d-models-characters-actors-players and any CRUD operations with their animations, and CRUD operations for materials etc etc)... because I think it is not that good if nowadays user can get all those resources as local files. I mean, say, I have few Gigabytes animations database (Mocam library with 2500 anims from Carnegie mellon university), and I'ld like user to be able to run my app maybe even on Android phone, which usually has not that much memory, so I can't make user download those Gigabytes... and yes, best if those animations can be downloaded from server when user requires them (see "Spinakers story machine" to understand what I mean, say we just need action "walk" or "eat" or "dance" - I want to download this on user's request)..

    2 I think the word "WebSockets" is already sounding not that simple. if possible - without sockets, and some library which has sockets already pre-programmed for not that advanced programmer like me - that would be better (if possible of course, but f not, I'ld have to learn it, ok)

    3) mgear, how to post model to user?
    say I want simplest hello world app, and it has only one button which generates "get" request - to download some 3d model which is instantiated at (0,0,0). How do I send 3d model from server to browser (client, be it outside-of-browser standart Windows Unity project, now doesn't matter, but hope this would work in browser as well).

    4) yes, I want with colliders, with animations, so asset bundle is "a must"?
    and how to use it? any "hello world" with bundles (client-server version)?

    5) I have no XP with php/python, and asp-net just started to learn (one week only). I just want to know what is the best path to choose to let it accomplish in future, so I don't want to waste time learning some database/network system, which is is not possible to be applied in Unity3d (we'ld have Unity3d as a course here in IT academy, so I'ld want to already know till that time how to make some Unity3d client-server (it can be in future a course-work, or at least exam for Unity3d)... i've already have around years XP with Unity3d (well, just as hobby, before I started to learn programming on computer courses), so to not make my Unity3d knowledge be wasted, but applied also to client-server solutions (with sql-database, I hope).
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    1) text and binary receive example (here it accesses .txt url directly, but that could be your backend serving any data), https://docs.unity3d.com/Manual/UnityWebRequest-RetrievingTextBinaryData.html

    2) sockets are "always" connected, so its often easier to send commands that way (in both directions), instead of for example constantly polling with GET/POST request.

    .. ill reply more later ..

    not sure where to find most suitable tutorials to get started,
    but for each of those step, can usually find easily answers with google:

    examples googling with "unity3d nodejs", several example projects (and youtube videos visible)
    https://dev.to/cemuka/making-a-rest-service-using-node-and-express-to-use-with-unity-part-1-321n
    https://stackoverflow.com/questions/45930451/game-server-in-unity3d-by-node-js/45933582
    https://github.com/rico345100/unity-multiplayer-with-nodejs
    https://github.com/gkaragoz/Unity3D-Network-with-Node-JS-and-Socket-IO
    https://github.com/xeratol/Unity3D-NodeJS-ChatSample
    *note that you should open those projects with roughly same unity version, to avoid errors in API changes. and should consider that those are random examples, use for learning reference, probably not good idea to start building on top of those directly.