Software Engineering

Animation synchronization with soundtrack in Unity

Sometimes we might need to play the animations together with a separate soundtrack in Unity. However, animations and the soundtrack may be out of sync due to frame drop or other performance problems even we start playing them in the same frame. A simple but not efficient solution is to force the animation to play the exact frame as the soundtrack ever frame. Below is a code example.

Continue reading

Rigidbody.Constraints in Unity

We all know that physics affects the sense of reality greatly in VR development. As a developer, I always hope to make the physical behaviors of the virtual experience the same as the reality as far as possible. However, I met a problem several days ago. I created a vase with some roses in it, and they are separated Game Objects. However, during the playtest, roses in the vase “jumped out” strangely when I tried to lift the vase. I checked and rebuilt the colliders on the vase and the roses carefully, set the Collision Detection on the Rigidbody to be Continuous Dynamic, tried to bond the roses on the vase as its children, but all of them failed to erase the bug completely. However, my intuition told me that the problem must be related to the physical system, therefore must has something to do with the Rigidbody component.

Continue reading

A known, postponed Unity bug: Tab Button

Issue Tracker: https://issuetracker.unity3d.com/issues/pressing-tab-key-does-not-navigate-between-input-controls?_ga=1.166523063.801547011.1462557649

Bug Description

I was trying to implement a function when the Tab button was pressed. However, the function only responds for the first time. After the player presses Tab once, ALL hotkeys in the game being unresponsive. The only way to bring back hotkeys’ functions is to use the cursor click in the game. It happens for GetKey, GetKeyDown and GetButtonDown.

Noticed that the problem only occurs under editor mode and development builds. It disappears in release builds (none-development builds).

I’ve also checked EditorWindow.focusedWindow and EventSystem.current.currentSelectedGameObject. They are all correct when the problem occurs.

The bug has been marked as a “Postponed Issue” by the Unity folks, where “Postponed Issue” means:

Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.

 

Limit Max Width of a Layout Component in Unity

Original post of the problem: http://forum.unity3d.com/threads/limit-max-width-of-layout-component.316625/

Demand

A textbox with a child text component. The textbox width would increase with the length of the text up to this maximum value at which point the width would be fixed forcing the text to wrap to the next line now increasing the height of the button.

A common needed of UI. I was surprised that Unity didn’t have max width for their vertical layout component so far… But never mind, using combinations of vertical and horizontal layouts could achieve what we want.

Continue reading

Bitfields for multiple flags in Unity

Demand

Supposed we’re going to develop a shooting game. Characters in our game have several flags such as IsMoving, IsShooting, IsLoading, IsHiding… All these behaviors might happen simultaneously (or, of course, individually), say, the character can shoot while moving, can load his gun while hiding. How are we going to set these flags?

The simplest way might be allocating bools for them respectively. However, bools in C# are stored as ints and the compiler might not be able to combines/consolidates them. So if there’re 16 bools, that’s an allocation of 16 ints – wasteful. In addition, if one of those combinations (eg. IsMoving + IsShooting) are frequently used, the codes might be burden.

Following are some tips for such situation.

Continue reading

[Quote] C#中的委托和事件

委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每次见到委托和事件就觉得心里别(biè)得慌,混身不自在。本文中,我将通过两个范例由浅入深地讲述什么是委托、为什么要使用委托、事件的由来、.Net Framework中的委托和事件、委托和事件对Observer设计模式的意义,对它们的中间代码也做了讨论。

Continue reading

Review: Computer Graphics (CMU 15-462/662)

(Pictures from CMU 15-462 course site)

The Entertainment Technology Center (ETC) of CMU has a very unique curriculum policy, where the first semester is filled with 4 compulsory courses and the rest of 3 is filled with a project and an elective course respectively. Hence, when it came to the first “free elective semester”, I spent a lot of time deciding which course should I take. I decided to go for Computer Graphics at last, mainly because of the following reasons:

  1. CG has been one of the basic branches of video game since the first game was created, and is becoming more and more important for the whole entertainment industry. It brings a huge revolution of the visual experience and still has a great potential for delving;
  2. CG is closely linked to Virtual Reality and Augmented Reality, which are popularly viewed as the future of games;
  3. Many alumni of ETC highly recommended this course, saying that it explains the profound simply and is useful in their career;

So I took it. It gave me an extremely impressive semester – not only because of its intensity, but also what it left to me. I didn’t stay awake the whole night before the due day as many alumni did, but I did “suffer” a lot. There was even a time when I was super frustrated and wanted to drop off. Thankfully, I didn’t do so. Instead, I found myself learned a lot from the struggling. Hence, I would like to write a brief review of the course (mostly depends on my level) as a reference for any ETC students who will consider to take this course in the future.

Continue reading

Setting up OpenGL

The last assignment of CMU CG course is  a self-selected project (detail).

What I chose is Option F, SPH Fluid Simulation, cooperated with Sarvesh Subramanian. I implemented the SPH model, while he took charge of the Marching Cube algorithm and OpenGL part.

This post includes a tutorial of how to setup OpenGL project on Windows by Visual Studio 2015.

Continue reading