Search Unity

Discussion String Storage Methods

Discussion in 'Scripting' started by StarBornMoonBeam, May 10, 2023.

  1. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Strings.gif

    When I was 16 in 2006 I modded some computer games, and saw that they use to often store their strings in a huge DLL. Like for full sentences of string for example. For raw development, we all know that writing a string Add("String"); is a garbage producing machine. And so sometimes its nice to specify Add(OUR_STRING) to memory, but to assemble those private strings we have to draw that data from somewhere.

    and that is where the conjecture lay.

    Do you know why a .dll would be used over a standard text file to store strings? Is there some kind of reading advantage in that?
     
  2. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    727
    It's called a Resource library. It's generally an autogenerated DLL file from a resources table (in .NET world a .resx file which is just an XML file). Very useful for localization (translation) of strings.
     
  3. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    What do you use? Do you make an xml?
     
  4. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    727
    Unfortunately resx files are not supported by Unity directly, they preferred to have their own localization system/library, but you can always recreate this functionality using your own Unity Editor scripts/tool that can read the resx files (it's just an XML file after all) and autogenerates all localization strings in a TextResources class, just like what VS does in other .NET projects:

    upload_2023-5-11_1-20-36.png

    This file is automatically generated from the resx files I have in my project. Now all I have to do to get a string is to call
    TextResources.Front_Camera
    and it returns the correct string for the current selected language (culture).

    Now I can use the standard VS resx editor tools to add/edit localizations:

    upload_2023-5-11_1-24-30.png

    Or even better, use the excellent free VS plugin ResXManager that makes it super easy to add/edit resource, translate it automatically using several online translation services, detect problems in punctuations...etc

    upload_2023-5-11_1-37-2.png

    And finally I can send the main resx file to translation companies since it's a standard format supported by most translation companies.
     
    Last edited: May 11, 2023
    StarBornMoonBeam likes this.
  5. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Wow that's pretty amazing stuff ! Thank you for sharing. Very smart because it can take a long time to do these things manually by script. I have never seen anything like this before looks like some serious stuff! I love how easy it seems to put an Arabic translation alongside. Hm

    Smart indeed. Scalable since if I had a full storied game, hell and I had a bunch of languages and I was pulling strings from text file based on which line they were, the mess that could cause if I had a Chinese file a English file a French file. But to have a nice view where the string is formally input and then some variations display alongside that's very nice.
     
    Nad_B likes this.
  6. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    727
    Don't worry about all of this, Unity's own library is pretty solid too and have nearly the same functionalities.



    Check their Quick Start guide.

    I just preferred to use Resx files and basically re-implement what Microsoft did for .NET into Unity since I'm a long time .NET developer used to work with Resx files intensively and the tools around it, and also needed to have more freedom in the resource retrieval system to implement some advanced things since I'm not using Unity standard UI system, but Noesis GUI (which is a XAML/MVVM UI system for Unity just like WPF, the framework I'm used to work with for more than 15 years) to be more productive.
     
    StarBornMoonBeam likes this.
  7. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209

    I might do the multi file approach and use regular numbers to identify lines and dock the characters out.

    I can't believe I have never done these unity early learning tutorials lol I never knew they offered this, I think I'm comfortable with a text file so il work with that.
     
    Nad_B likes this.
  8. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    727
    Do whatever you find easy/better, the most important thing is that it works.

     
    Last edited: May 11, 2023
    X3doll and StarBornMoonBeam like this.