petitviolet blog

    unity (4 posts)

    icon
    Written by petitviolet

    Seeded Random in Unity C#

    2023-07-30UnityC#
    Unity provide UnityEngine.Random to access 'random' capabilities, but it's not easy to test it because of its interface. This post describes how to deal with it.
    In Unity, UnityEngine.Random is to deal with random capabilities that can be used as below: cs using System; UnityEngine.Random.value It looks simple, however, as UnityEngine.Random.value is a shared value in the global scope, it's nearly impossible to test codes that are using Unity

    Singleton MonoBehavior to data live through Scene transitions

    2023-06-15UnityC#
    MonoBehavior in Unity spawn in a scene and then get destroyed when the scene is unloaded. But, data should be living even after scene transitions happens. To make it possible, keeping MonoBehaviors live before and after scene transitions.
    This post instructs how to achieve Singleton MonoBehavior in Unity C that stay living even after scene transitions. Singleton is a well-known design pattern in the industry for long time and it's useful for having data and states in-memory or limit an active instance only one at the same time. In

    How to use Firestore SDK in WebGL built by Unity

    2022-10-15UnityFirestoreC#
    Official Firestore SDK can't run on Unity WebGL. Use .jslib for interacting JS SDK and C#.
    Firebase offers Cloud Firestore which is a well-known NoSQL document datastore that has been widely used in particularly mobile app development. One of the key features of Firestore I think is realtime-ish data propagation through Firestore SDK. When a client is subscribing a (sub-)collection and

    Working with Json over HTTP in Unity

    2022-09-15UnityC#
    To send and receive JSON payload over HTTP in Unity, some techniques needed for de-/serialization.
    Unity provides handy class called UnityWebRequest for sending HTTP requests. See the document for details. [Unity - Scripting API: UnityWebRequest](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html) As the document illustrates, UnityWebRequest handles Web requests with