[Unity3d] Serialize and Deserialize System.Guid using JsonUtility

2
Comments
[Unity3d] Serialize and Deserialize System.Guid using JsonUtility

Unity3d 5.3.0 introduced JsonUtility class which will help you with JSON serialization and deserialization. But this class has some limitation, and one of them: "You cannot serialize\deserialize System.Guid type" That's a pity, especially if you're using System.Guid in your DTO objects. But, there are solutions: You can change a data type, for example, use System.String or System.UInt32 instead of System.Guid. But if you have a lot of code which uses your DTO objects it might be painful to refac...

Read further...

Speedup Unity3d development with SSD

5
Comments
Speedup Unity3d development with SSD

I was wondering if I move my Unity3d project from HDD to SDD, how it will improve performance? There are two possible cases. First, if you already have your system  (with Unity3d editor) installed on SSD (I hope you do) and a second case is when you have only HDD (I hope you will buy SSD asap). To figure that out I made some simple tests I took a first computer with OS and programs installed on SSD and run all tests on a project which was located on HDD, then I moved the project to the SSD drive...

Read further...

[Unity3d] Yet Another State Machine for Unity3d

0
Comments

If logic in your controller to complex for 'if' or 'switch\case' constructions, here is small State Machine implementation for you. Let's start with example how to use this state machine, and then we go through implementation details: public class Test : MonoBehaviour { private StateMachine stateMachine; private State firstState = new State(); private State secondState = new CustomState(); private State finishState = new State(); // Use this for initialization void Start () { var initChild = new...

Read further...

[Unity3d] How-to play video in Unity project. MovieTexture

3
Comments
[Unity3d] How-to play video in Unity project. MovieTexture

If you want to play movie clip in your Unity3d project you need to have Pro version! If you are using Windows machine you also need to have QuickTime installed. After you have everything prepared just drag (or copy) your movie clip into Asset folder, after that you will see it imported. You need a MovieTexture instance to use imported clip. To play movie clip use following code: MovieTexture movie; public void Play() { movie.Play(); } To stop or pause: movie.Pause(); movie.Stop(); You can access...

Read further...

[Unity3d] ReadOnly InputField

1
Comments
[Unity3d] ReadOnly InputField

New UI system was introduced in Unity3d 4.6, it includes InputField control, but this field could not be read only. You can make it non interactable by disabling "Interactable" property in the editor, but then you will not be able to select and copy text from InputField. To have proper ReadOnly input field you should do small modification to the original control: using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; [AddComponentMenu("UI/Read Only Input Field", 32)]...

Read further...

[Unity3d] WaitForFrames in Coroutine

3
Comments
[Unity3d] WaitForFrames in Coroutine

If you are using Coroutines in Unity3d, you probably know about WaitForSeconds, WaitForEndOfFrame and WaitForFixedUpdate classes. Here is an example: public IEnumerator CoroutineAction() { // do some actions here yield return new WaitForSeconds(2); // wait for 2 seconds // do some actions after 2 seconds } But sometimes you need to wait for some amount of frames before executing some action. I have created simple class to help you with that: public static class WaitFor { public static IEnumerato...

Read further...

[How-To] Horizontal Field Of View for Unity3d camera

0
Comments

In Unity3d you can change only vertical field of view for a camera by default. This means whenever you change height unity will automatically scale environment. But if you change width unity will just add some space (or decrease) to left and right side of the screen (no content resizing). If you want to have opposite behavior, so when you increase width all content will  be scaled and if you increase height only space added to the view, you need to modify camera fieldOfView field. Here is a simp...

Read further...

[Fixed] Unable to parse YAML file in Unity 3d project

1
Comments

Sometimes you may get following errors: Unable to parse YAML file: [mapping values are not allowed in this context] at line 1 or Unable to parse YAML file: [could not find expected ':'] at line 2 Both of those errors usually caused by version control system (eventually by user). In first case svn added <<<<<<< .mine in to .meta file after conflict. In second case it was git, added text to highlight conflict. To fix those errors you just need to go though all .meta files and...

Read further...

[Fixed] Error building Player: Win32Exception: zipalign.exe in Unity3d

9
Comments

During building your Unity3d project for Android devices you might get following error:: "Error building Player: Win32Exception: ApplicationName='C:/Program Files (x86)/Android/android-sdk\tools\zipalign.exe', CommandLine='4 "D:\code\Game\Temp/StagingArea/Package_unaligned.apk" "D:\code\Game\Temp/StagingArea/Package.apk"', CurrentDirectory='Temp/StagingArea'" To fix this error: Go to C:\Program Files (x86)\Android\android-sdk\build-tools\20.0.0 (you may have different version) Copy zipalign.exe...

Read further...