More work done on the interface, saving data.

More work done on the interface, saving data.

I would have liked to say that I started on the loot and enemy randomization, but that is not the case.
What I thought would be an hour work job took me half a day. I have now finished with the way the randomizing feed is stored.




When a level is complete (PLG state is -off) two buttons appear in the inspector allowing the user to store the seed in a whitelist of black list.
When the time comes to generate the level the user has a larger option of choices:

  1.  Generate a completely randomly level.
  2.  Generate a  completely randomly level but it will never be one of the levels we blacklisted (if we tick on use black list).
  3. Generate a specific level from a ID we enter.
  4. Load a random level that is included in the whitelist.
In order the randomization between levels within the list to be equally random before storing the lvl ID we load the current values and check if the Id already exists, if it does then there is no need to add the ID. This is done so we do not have multiple entries of the same Id in our list. In addition to storing the ID, when we save a level either as a black or white list. It takes a screen shot of the level with the level id as its name. 

The most time consuming process was storing those images in the correct folders. I noticed when unity creates screenshots it has 2 limitations:

  1. The screenshots are stored in the main folder of your project and you can change that.
  2. You cannot take a picture of the editor window only the game window.
So after spending some time realizing that unity will not store the file in subfolders, I found a method to transfer the file like you would transfer files in an old dos command.  Unfortunately that did not work and i had to figure out that "Application.dataPath" is bugged and for some users the code would work on one machine but not the other. So I found a way from ( https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in)


public static string AssemblyDirectory
{
    get
    {
        string codeBase = Assembly.GetExecutingAssembly().CodeBase;
        UriBuilder uri = new UriBuilder(codeBase);
        string path = Uri.UnescapeDataString(uri.Path);
        return Path.GetDirectoryName(path);
    }
}



So with some trimming and combining strings I got my initial path then I created the destination path.

Now I had the 2 correct paths but still it would not transfer the file. I narrowed it down to it could not finĪ“ the file, which after many failed attempts led me to the conclusion that  the file was not created as fast as the next line was executed, you can't find something that does not exist yet.
so the class was turned into a ienumerrator  making it wait 5 sec in the background before transferring the file to its desired location.

Also the state machine is very useful as I can dictate which controls are visible in the stages, I found myself  pressing the start level when in edit mode, so I only show the start button if the application is in play mode and the machine state is -Finished.
I also hide the "Add to Whitelist"  and "Add to Blacklist" until the state is finished, to prevent the used taking screenshots of an empty canvas. In general the machine state make it really east and clean to Dictate when components in the editor are displayed.

Next up randomizing the loot and enemies.


Comments

Popular posts from this blog

Player stats and brightness.

Testing the PLG