Showing posts with label Unity3d-HowTo. Show all posts
Showing posts with label Unity3d-HowTo. Show all posts

How to enable Unity Collaborate

 In this unity game development tutorial, you learn how to enable Unity Collaborate step by step. This tutorial will show you step by step guide to enable/start unity collaborate in your unity3d projects.

Learn More: Unity Collaborate Limitations/Disadvantages

 Let's get started:

1. Open services

Step # 1 - Open Services

Step # 2: Turn on Collaborate Feature

Step # 3: Select Organization 

Step # 4: Select Organization and Create Project ID

Step # 5: Now Click on Collaborate Toggle



Step #6: Install Collaborate Latest Package.


Step #7: Select File that you want to update on server.

Step # 8: Write comment and publish.




Step # 10: Now you can check history.


Get Request in Unity C# | Get data from a URL in unity

 You often require to access a URL/API endpoint in order to get/post data or communicate to a web server. For this reason, unity provides UnityWebRequest Class. The class specifically designed to handle HTTP communications. It provides set of functions especially Get and Post function to deal with data retrieval and data post operations: Here are the ways to use it:

Get Request: A common way to access data from a URL. Suppose you are trying to get JSON data from a URL/API (given below) and here is our working example URL

https://jsonplaceholder.typicode.com/todos/1

void Start()

    {

        string getURL = "https://jsonplaceholder.typicode.com/todos/1";

        StartCoroutine(GetReq(getURL));

    }

 

    IEnumerator GetReq(string url)

    {

        UnityWebRequest req = UnityWebRequest.Get(url);

        yield return req.SendWebRequest();//wait until request competed

 

        if (req.isNetworkError)//if the networkerror is true then, there is an error.

        {

            Debug.Log("Error While Sending: " + req.error);

        }

        else

        {

            Debug.Log("Received: " + req.downloadHandler.text);

        }

    }


If you have json string then you can deserailze it. Here is the detailed tutorail.

Unity Json Serialization or Deserialization for Beginners

 In this tutorial, you will learn how to convert an object to JSON (JSON serialization) or Deserialization (JSON text to Object). This thing is often helpful to deal with response of reset APIs or database interaction related task or to save or interact with data in unity. Let's learn JSON serialisation in Unity3d step by step:

  1. Make  a class that you want to use as json, for example below I have created score class:

public Scores{

public int playerNo;

public string  playeName;

public string playerScore

}

2.     2.  Now if we want to make it work with JSON serialize. we have to use Serializable attribute in top of the class name

[Serializable]

public Scores{

public int playerNo;

public string  playeName;

public string playerScore

}

3.      3. Create objects of above class:

Scores scores = new Scores();

Scores. playerNo = 1;

Scores. playeName = “Faizan”;

Scores. playerScore = 100;

The object has created and now we are able to convert it to JSON text.

4.     4. To convert the Unity C# Object to JSON string, we can use the built-in static class of Unity named JsonUtility. Here is how it work

String jsonStr = JsonUtility.ToJson(scores);

Note that we have used ToJson method to convert object to JSON. The output of the above string will be like this:

‘{" playerNo ":1," playeName ":faizan," playerScore ":"100"}’

5.       Now if we want to convert the JSON string back to Normal C# Object (deserialization) we can use FromJson method of the same JsonUtility Class

  1. Scores jsonToObject = JsonUtility.FromJson<Scores>(jsonStr)

Not that jsonStr contains the full json string that we made in step 4.

This is smallest way to do JSON seralization and deserializatiin in unity without using any third-party plugins or dependency. If you don't want to use built-in Unity3d c# serialisation classes then you can also use third party plugins or nuGet package like newtonsoft. Here is the way to import newtonsoft DLL in Unity3d.

 

Unity WebGL Conversion Guide - Steps to consider For Unity Webgl Conversion

 There are some common steps you need to repeat whenever you make Unity WebGL build or if you want to convert your project into WebGL. Beware I am not using Unity 2020.

Learn more: Unity WebGL Technical Breakdown

1. Convert to Latest Unity Version (if Possible):

Always try to use the latest Unity version if you are building for unity WebGL as unity WebGL has several issues. With each new unity release, we see different bug fixes but remember each new build brings it known issues. If you don't have any problem with the latest unity version then, you should adopt it for your WebGL project. Beware porting to your current project into the latest unity version can show significant compatibility issues, so make a backup before conversion.

2. Save Scripting Define Symbols 

Before converting to WebGL please save your scripting define symbol outside unity (separately). Scripting defines symbols will be available under player settings. Some of the symbols are lost during WebGL conversion.
Scripting define symbols in webgl


Unity WebGL Technical breakdown - How Unity WebGL Works

 A Glimpse of technical background of unity3d WebGL:

Unity support dozen of platform for application deployment and one of them is WebGL. WebGL allows you to run your content on a web. Technically, WebGL is an API that renders graphics in web browser.  Currently, it has two supported version of WebGL 1.0 and 2.0. Remember WebGL 1.0 roughly matches the functionally of OpenGL ES 2.0 while WebGL 2.0 roughly matches the functionally of OpenGL ES 3.0.

Unity WebGL Structure


Figure 1 Unity WebGL consist of these components.

How Unity Render Streaming Work?

What is unity Render Streaming?

Unity render streaming is one of the packages/or a solution that allows HD rendering via a browser. For more clarification of the concept of render streaming, see the below video. Here you can watch that how we can access HD content into different devices (laptop, tablet or even mobile) via a URL. Remember, the processing will take place on one high-end PC while the different devices can get video streaming/audio or even get a remote control of the player.

This streaming solution work on top of WebRTC. WebRTC is a free and open-source project that allows RTC (real-time communication) between web and mobile applications. Luckily unity also provides its own render streaming platform called Furioos.

How to Setup Your Own Render Streaming in Unity3d

In the below video, I have explained how to setup your own render streaming.

How to create a Basic Glass & Mirror in Unity3D

In this game development unity tutorial i have explained how to create a glass or a mirror using reflections and shader settings.

Control Object Transparency with Slider UI in Unity

In this unity game development tutorial you will learn how to control decrease or increase GameObject transparency/alpha or opacity. With the help of a slider and a C# script. I will explain how to increase or decrease opacity of an object using a c#  script. 

How to make Object Transparent in Unity3d with Script C#

How to Call one C# method from another C# script in Unity3d

Calling one method of a script from another script is common in Unity3d game development. In this Unity3d beginners tutorial I will show you how to call one c# method from another script.

How to add Serilog or Third Party Logging in Unity3d

In this video tutorial I have explained how to add third party logging system in Unity3d. This is advance logging way to log information in unity console with SeriLog. you can even write your games logs in specific text file with proper text formatting.

How to Import NuGet package in Unity3d

You often require to add third-party dll or nuget packages in Unity3d project. In this unity tutorial I will show you step by step how to add Nuget Package or dll into Unity3d project. For this tutorial we choose newtonsoft nuget package. You can adopt these steps for any nuGet package.

Here are the details,
      go to your desired NuGet package webpage.
      on the right side **Download Package** option click it.
      your package **.nupkg** file will be downloaded.
      change its extension to .zip and extract it
      go to lib and copy your package dll file from net or any netstandard folder. For [your unity project compatibility purposes][2] view this:

      open unity workspace and create plugin folder
      paste your dll file here.

Unity vector graphics package missing solution

Unity Vector graphic package is in the preview stage currently so you need to check one more setting in order to view the package in the package manager window. First of all, you need to open package manager window from the Window menu then click on advanced setting and check show preview packages.


Game Pause on error in Unity3d

For debugging purposes, you may require to pause the game on an error so that you can inspect the game situation. For this reason, you can follow these steps:

1. Write an error log in block of the code

    Debug.LogError("Exception occured");

And before running the editor open console and hit Error Pause in the console log.


The game will pause as any error occurred in the console.