Fxhash Unity boilerplate

This is a simple Unity project that will help you get started on fxhash. The version of Unity used is 2020.3.26f1, so I recommend downloading that one.

Installation

Clone the repository to your machine, make sure you are in your desired folder.

$ git clone https://github.com/fgrart/fxhash-unity-boilerplate.git

Description

In Assets/Scripts/ there is a RandomExample.cs script, the comments are explaining which lines are relevant to fxhash image

This part references a function that is declared in the Assets/Plugins/plugin.jslib, which takes the random from the fxhash's html snippet

[DllImport("__Internal")]
    private static extern float GetRandomFromFxhash();

In order to test random behavior you can use Unity's native Random.value or Random.Range() because you cannot test with fxhash in editor, that's we have #if UNITY_EDITOR and #if UNITY_WEBGL to specify in which environment which part of the code should run.

Once you build for WebGL and you upload it to the site, the UNITY_WEBGL code will run.

Building steps

Go to Player Build Settings like below(or pressing Ctrl+Shift+B).

image

Select WebGL as your platform by selecting it and pressing Switch Platform in the lower right part of the ui, if it's already set to WebGL(Unity Icon next to it) ignore this step.

image

Select the Player Settings.

image

Add your naming and select the WebGL tab.

image

In resolution and presentation you set the canvas size, although you can edit that in the index.html after the build. Select the minimal template.

image

In Other Settings uncheck Auto Graphics API.

image

In Publishing Settings set Compression Format to Disabled.

image

Close Player Settings, and press Build.

image

After the build is complete you will get these 2 files:

image

Open index.html and add the code found in the FxhashUnityBoilerplate/ root called "fxhashsnippet.txt" under the <title> tags . image

Fxhash snippet is lines 7-36 and 38-42 is the part that translates the snippets fxrand to GetRandomFromFxhash() in plugin.jslib which we then use in C# as our random generator.

Once you made the edits in index.html, make a .zip from both files and it's ready to be uploaded to fxhash for testing. Note: For some reason this won't work in the regular browser window, you have to go to incognito mode to test in sandbox, but it should work when you actually mint it.

Upload the .zip to sandbox and test with same and different hashes to see how the value behaves. It should look like this:

image

Conclusion

That's it! You can now use the value however you want to manipulate different aspects of your artworks

Credits

By GabrieleGenArt, nekropunk, lomz, ciphrd and fgra