#Unity Arduino C# and Unamanged C++ structs
1 messages · Page 1 of 1 (latest)
ye
okay one sec I'm gonna open the project rq
here are two example structs in c
struct XYZ {
float x;
float y;
float z;
};
struct Person {
char name[25];
int age;
XYZ xyz;
};```
`Person person;`
void writeDataToPort(){
Serial.write((uint8_t*)&person, sizeof(person));
}```
then in c# (can use any frame work for UI)
int structSize = Marshal.SizeOf(typeof(Person));
byte[] buffer = new byte[structSize];```
```cs
if (serialPort.BytesToRead > 0 && readData)
{
byte[] incomingBytes = new byte[serialPort.BytesToRead];
serialPort.Read(incomingBytes, 0, incomingBytes.Length);
var student = ByteArrayToStruct<Person>(incomingBytes);
Console.WriteLine($"byte data length: {incomingBytes.Length}");
```
ive never used a struct
have you used a class before?
what does the * and & do on this
ye it just looks like a class
exactly, it does the same thing except for a few caveats
alr
it just bunches data together mainly
you used Vector3 in unity before no? or Quaternion
ye
ye i see
the reason is the structs are usually value types and handled different , in many cases its more efficient. Ideally most of the data is kept on the stack
serialPort.Read(incomingBytes, 0, incomingBytes.Length);
whats the point of that
im assuming it outputs something because its not being saved in a variable
basically this is replacement for reading strings
instead of reading strings you are reading a specific bytes
this would work over serialport should be similiar, have to revis the old project its been a while
the important part is processing that same data instead as string but raw data
yeah
im still a little confused on what to use for bluetooth
you most likely dont know any libraries
but ive gotten over my immense stupidity now and without narrowing it down to maui itll probably be easier to find videos on
like I said, bluetooth or not the framework is irrelevant lol this would work across all .net frameworks
including Unity. Unity also uses .NET
if it works on Unity it works for any other platform on .NET maui/blazor included or like i said console app
i could use unity to control the servos
i could make the gui on unity not much point though over an actual ui
yeah I mean if you write clean code it can work on all the platforms, if you want specific UI and look then yes thats where it makes a difference
Blazor - Html/CSS
Unity - Custom Editor / GUI Tools / UI Toolkit
MAUI - Native platform controls / Pain in the ass XAML
I like mostlly using Blazor cause I get to use JS and whatever library from that , as well as for CSS using things like Bootstrap or Tailwind
if its simple usecase and don't need 3D rendering or interaction heavy like unity
dumb question but blazor still uses c# at its core and not js
my js is lacking
but hell yeah xaml is a pain
i would much rather do html
yes blazor uses something called Razor files that are HTML and C# combined basically
but because blazor is web, you can also call JS functions if you wanted to
or call C# functions from JS
yeah its really being slept on
the easyness of c# but something as powerful as NextJS and other serverside frameworks.
Ofc Blazor can also use other frameworks for frontend like react or vue
and blazor can also do Client side apps so you don't need a server side rendering or you can do both (this is something you learn about later)
ServerSide is basically code that runs on another computer so people cannot decompile your code, this is especially important when handling back end stuff like Databases
Client side rendering you have to download the HTML/JS/WebAssembly document first then your local pc runs it (which opens up people seeing your code)
but still works on its own
wdym "on its own"
its still web dependant though
so if you just wanted a standalone app without needing wifi
internet has nothing to do with it though
the only difference is you're running it in a browser vs not
also there is MAUI Hybrid that embeds the Blazor parts in the WebView
ultimately depends on what features you need and what you don't need
im somewhat confused im slow sometimes mb
if it needs a browser surely that means not its own app?
or is it its own browser..?
yeah you need to distribute it like you would a regular website, but can be run locally too if you spin up a simple https server
MAUI hybrid makes it so you have it already embedded in the Naitive App
isnt flutter also like maui hybrid
I think so, I haven't used flutter
i should try doing something with servers or databases soon
ive never used them because i dont a need for either
they both do the same thing though they are both native apps
so yeah its easier to just use the c# equivalent network
albeit still infant
Unity also has this https://cloud.unity.com/
but yeah any other service also can work like AWS or Azure etc.
MongoDB is also nice
maybe ill try make a login / user system for something with a database
i made a discord bot too which needs a server
authentication and authorization is good to learn, confusing as hell at first especially if the framework doesn't have already integrated solutions with oAUTH
Unity has one with Unity Auth which is pretty nice
I can login easy using Google account then access whatever from there
ofc ontop of the regular username/pass login
what more is it other than meaning they cant use special characters and limiting the length etc any custom filtering / requirements