Unity 4.0 меняет способ управления активным состоянием Игровых Объектов. Теперь активное состояние Игровых Объектов наследуется дочерними Игровыми Объектами, так что при отключении любого Игрового Объекта, будут отключены и все его дочерние объекты. Мы верим что новое поведение гораздо правильнее старого, и всегда должно быть таким. Более того, грядущая новая система GUI сильно зависит от нового поведения 4.0 и была бы невозможна без него. К сожалению могут потребоваться усилия, чтобы исправить существующие проекты для работы с новым поведением Unity 4.0, и вот изменения:
У вас есть 3 Игровых Объекта: A, B и C, так что B и C являются дочерними A.
Для визуализации этих изменений, в редакторе Unity 4.0, любой неактивный Игровой Объект (любой если его свойство .activeSelf, либо у одного из его родителей, выставлено на false), будет серым в иерархии, и будет иметь серую иконку в инспекторе. Собственное свойство .activeSelf Игрового Объекта отображается его активным флажком, который может быть переключен независимо от состояния родителя (но активирует Игровой Объект, только если активны все его родители).
During the development of 4.0 our asset import pipeline has changed in some significant ways internal in order to improve performance, memory usage and determinism. For the most part these changes does not have an impact on the user with one exception: Objects in assets are not made persistent until the very end of the import pipeline and any previously imported version of an assets will be completely replaced.
The first part means that during post processing you cannot get the correct references to objects in the asset and the second part means that if you use the references to a previously imported version of the asset during post processing do store modification those modifications will be lost.
Рассмотрим небольшой пример:
public class ModelPostprocessor : AssetPostprocessor
{
public void OnPostprocessModel(GameObject go)
{
PrefabUtility.CreatePrefab("Prefabs/" + go.name, go);
}
}
In Unity 3.5 this would create a prefab with all the correct references to the meshes and so on because all the meshes would already have been made persistent, but since this is not the case in Unity 4.0 the same post processor will create a prefab where all the references to the meshes are gone, simply because Unity 4.0 does not yet know how to resolve the references to objects in the original model prefab. To correctly copy a modelprefab in to prefab you should use OnPostProcessAllAssets to go through all imported assets, find the modelprefab and create new prefabs as above.
The second example is a little more complex but is actually a use case we have seen in 3.5 that broke in 4.0. Here is a simple ScriptableObject with a references to a mesh.
public class Referencer : ScriptableObject
{
public Mesh myMesh;
}
We use this ScriptableObject to create an asset with references to a mesh inside a model, then in our post processor we take that reference and give it a different name, the end result being that when we have reimported the model the name of the mesh will be what the post processor determines.
public class Postprocess : AssetPostprocessor
{
public void OnPostprocessModel(GameObject go)
{
Referencer myRef = (Referencer)AssetDatabase.LoadAssetAtPath("Assets/MyRef.asset", typeof(Referencer));
myRef.myMesh.name = "AwesomeMesh";
}
}
This worked fine in Unity 3.5 but in Unity 4.0 the already imported model will be completely replaced, so changing the name of the mesh from a previous import will have no effect. The Solution here is to find the mesh by some other means and change its name. What is most important to note is that in Unity 4.0 you should ONLY modify the given input to the post processor and not rely on the previously imported version of the same asset.
Unity 4.0 adds a “Read/Write Enabled” option in Mesh import settings. When this option is turned off, it saves memory since Unity can unload a copy of mesh data in the game.
However, if you are scaling or instantiating meshes at runtime with a non-uniform scale, you may have to enable “Read/Write Enabled” in their import settings. The reason is that non-uniform scaling requires the mesh data to be kept in memory. Normally we detect this at build time, but when meshes are scaled or instantiated at runtime you need to set this manually. Otherwise they might not be rendered in game builds correctly.
The Model Importer in Unity 4.0 has become better at mesh optimization. The “Mesh Optimization” checkbox in the Model Importer in Unity 4.0 is now enabled by default, and will reorder the vertices in your Mesh for optimal performance. You may have some post-processing code or effects in your project which depend on the vertex order of your meshes, and these might be broken by this change. In that case, turn off “Mesh Optimization” in the Mesh importer. Especially, if you are using the SkinnedCloth component, mesh optimization will cause your vertex weight mapping to change. So if you are using SkinnedCloth in a project imported from 3.5, you need to turn off “Mesh Optimization” for the affected meshes, or reconfigure your vertex weights to match the new vertex order.
With Unity 4.0 mobile sensor input got better alignment between platforms, which means you can write less code when handling typical input on mobile platforms. Now acceleration and gyro input will follow screen orientation in the same way both on iOS and Android platforms. To take advantage of this change you should refactor your input code and remove platform and screen orientation specific code when handling acceleration and gyro input. You still can get old behavior on iOS by setting Input.compensateSensors to false.