在Unity3D引擎中,场景资源文件(.unity)是以2进制格式存储的,但同时它也有一种基于文本的表现格式。可在Edit>Project Setting>Editor 中设置:
1.使用binary2text.exe(win下目录:Editor\Data\Tools)可将.unity文件转换成.txt文件,只需将.unity文件拖拽到binary2text.exe上即可生成.txt;
2.Bin2Text.unity为测试场景场景中只有一个名为“sakyaer”的空物体;
3.对应这样一个场景,它的文本格式使用YAML格式存储,信息表如下:
- 其中ClassID是Unity3D中类的序列编号,如:GameObject类ClassID=1,具体类的ID参照官方网站http://docs.unity3d.com/Manual/ClassIDReference.html
- ID项为随记分配给每个实例的唯一标识
- 资源文件使用m_作为前缀
- 其中m_GameObject (file 0 path 1163297905)表现transform对gameobject的从属关系
External ReferencesID: 1 (ClassID: 29) SceneSettingsm_ObjectHideFlags 0 (unsigned int)m_PVSData (vector)size 0 (int)m_PVSObjectsArray (vector)size 0 (int)m_PVSPortalsArray (vector)size 0 (int)m_OcclusionBakeSettings (OcclusionBakeSettings)smallestOccluder 5 (float)smallestHole 0.25 (float)backfaceThreshold 100 (float)ID: 2 (ClassID: 104) RenderSettingsm_Fog 0 (bool)m_FogColor (0.5 0.5 0.5 1) (ColorRGBA)m_FogMode 3 (int)m_FogDensity 0.01 (float)m_LinearFogStart 0 (float)m_LinearFogEnd 300 (float)m_AmbientLight (0.2 0.2 0.2 1) (ColorRGBA)m_SkyboxMaterial (file 0 path 0) (PPtr<Material>)m_HaloStrength 0.5 (float)m_FlareStrength 1 (float)m_FlareFadeSpeed 3 (float)m_HaloTexture (file 0 path 0) (PPtr<Texture2D>)m_SpotCookie (file 0 path 0) (PPtr<Texture2D>)m_ObjectHideFlags 0 (unsigned int)ID: 3 (ClassID: 127) LevelGameManagerm_ObjectHideFlags 0 (unsigned int)ID: 4 (ClassID: 157) LightmapSettingsm_ObjectHideFlags 0 (unsigned int)m_LightProbes (file 0 path 0) (PPtr<LightProbes>)m_Lightmaps (vector)size 0 (int)m_LightmapsMode 1 (int)m_BakedColorSpace 0 (int)m_UseDualLightmapsInForward 0 (bool)m_LightmapEditorSettings (LightmapEditorSettings)m_Resolution 50 (float)m_LastUsedResolution 0 (float)m_TextureWidth 1024 (int)m_TextureHeight 1024 (int)m_BounceBoost 1 (float)m_BounceIntensity 1 (float)m_SkyLightColor (0.86 0.93 1 1) (ColorRGBA)m_SkyLightIntensity 0 (float)m_Quality 0 (int)m_Bounces 1 (int)m_FinalGatherRays 1000 (int)m_FinalGatherContrastThreshold 0.05 (float)m_FinalGatherGradientThreshold 0 (float)m_FinalGatherInterpolationPoints 15 (int)m_AOAmount 0 (float)m_AOMaxDistance 0.1 (float)m_AOContrast 1 (float)m_LODSurfaceMappingDistance 1 (float)m_Padding 0 (int)m_TextureCompression 0 (bool)m_LockAtlas 0 (bool)ID: 5 (ClassID: 196) NavMeshSettingsm_ObjectHideFlags 0 (unsigned int)m_BuildSettings (NavMeshBuildSettings)agentRadius 0.5 (float)agentHeight 2 (float)agentSlope 45 (float)agentClimb 0.4 (float)ledgeDropHeight 0 (float)maxJumpAcrossDistance 0 (float)accuratePlacement 0 (bool)minRegionArea 2 (float)widthInaccuracy 16.6667 (float)heightInaccuracy 10 (float)m_NavMesh (file 0 path 0) (PPtr<NavMesh>)ID: 1163297905 (ClassID: 1) GameObjectm_ObjectHideFlags 0 (unsigned int)m_PrefabParentObject (file 0 path 0) (PPtr<EditorExtension>)m_PrefabInternal (file 0 path 0) (PPtr<Prefab>)m_Component (vector)size 1 (int)data (pair)first 4 (int)second (file 0 path 1163297906) (PPtr<Component>)m_Layer 0 (unsigned int)m_Name "Sakyaer" (string)m_TagString "Untagged" (string)m_Icon (file 0 path 0) (PPtr<Texture2D>)m_NavMeshLayer 0 (unsigned int)m_StaticEditorFlags 0 (unsigned int)m_IsActive 1 (bool)ID: 1163297906 (ClassID: 4) Transformm_ObjectHideFlags 0 (unsigned int)m_PrefabParentObject (file 0 path 0) (PPtr<EditorExtension>)m_PrefabInternal (file 0 path 0) (PPtr<Prefab>)m_GameObject (file 0 path 1163297905) (PPtr<GameObject>)m_LocalRotation (Quaternionf)x 0 (float)y 0 (float)z 0 (float)w 1 (float)m_LocalPosition (0 0 0) (Vector3f)m_LocalScale (1 1 1) (Vector3f)m_Children (vector)size 0 (int)m_Father (file 0 path 0) (PPtr<Transform>)m_RootOrder 0 (int)
4.Unity3D中对于每一个资源文件都会生成对应.meta文件,该文件可以用记事本直接打开;guid(全局唯一标识符,Globally Unique Identifier)是系统随机生成的对资源的标识符,guid在游戏运行时会被用来生成一个hashid;而根据guid的前两位0a可以在工程Library目录下metadate(元数据)0a目录下找到,对应的二进制文件,该文件可以使用binary2text.exe打开,得到的txt文件,记录了.meta文件对应资源的所有详细信息。
guid: 0a4a878577c88654795d8c6aee74368d
参考文献:http://docs.unity3d.com/Manual/TextualSceneFormat.html