赞
踩
如果你的文件打开是乱码,只需要在Unity中将资源序列化选择为ForceText即可,具体操作方式如下:
资源文件是指一些创建好的、不需修改的文件。如FBX文件、音频文件、贴图文件、视频文件、动画文件(动画文件虽然被认为是配置文件,但是我们一般不回去修改它,所以也可以认为是资源文件)。资源文件在导入Unity的时候都会进行转化,每一个类型都对应一个AssetImporter,如AudioImporter、TextureImporter、ModelImporter等,在Unity中点击这类资源,在Inspector面板会出现设置界面,如下图为音频文件的设置界面。
代码文件包括所有的代码文件、代码库文件、Shader文件等,在导入的时候,Unity会进行依次编译。
序列化文件指能够序列化的文件,如Unity自身的一些类型:Prefab文件、场景文件、Asset文件(ScriptableObject)、Mat文件(材质球),这些文件在运行时可以直接反序列化为对应类的一个实例。
Prefab文件
Prefab文件的内容是通过YAML语言序列化的一个GameObject的对象,其中包含GameObject的所有描述信息,如GameObject信息,Component实例和属性等。
接下来我们结合Cube的Prefab分析Prefab文件具体都存储了什么数据。
首先我们将一个Cube制作成预制体,并命名为Prefab,找到该预制体的文件位置,打开后缀为**.Prefab**的文件,可以使用记事本或者VS等软件打开。
%YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!1 &1242430040932248662 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - component: {fileID: 1242430040932248658} - component: {fileID: 1242430040932248659} - component: {fileID: 1242430040932248656} - component: {fileID: 1242430040932248657} m_Layer: 0 m_Name: Prefab m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 --- !u!4 &1242430040932248658 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1242430040932248662} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 2.696, y: -0.09169984, z: -0.08227718} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!33 &1242430040932248659 MeshFilter: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1242430040932248662} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!23 &1242430040932248656 MeshRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1242430040932248662} m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 2 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} m_ScaleInLightmap: 1 m_ReceiveGI: 1 m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 m_StitchLightmapSeams: 1 m_SelectedEditorRenderState: 3 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 --- !u!65 &1242430040932248657 BoxCollider: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1242430040932248662} m_Material: {fileID: 0} m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0}
--- !u!1001 &44325156 PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: m_TransformParent: {fileID: 963194228} m_Modifications: - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_RootOrder value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalPosition.x value: 2.696 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalPosition.y value: -0.09169984 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalPosition.z value: -0.08227718 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalRotation.w value: 1 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalRotation.x value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalRotation.y value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalRotation.z value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalEulerAnglesHint.x value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalEulerAnglesHint.y value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - target: {fileID: 1242430040932248662, guid: 4056222df4abff6438d3de39dea17010, type: 3} propertyPath: m_Name value: Prefab objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 4056222df4abff6438d3de39dea17010, type: 3} --- !u!4 &44325157 stripped Transform: m_CorrespondingSourceObject: {fileID: 1242430040932248658, guid: 4056222df4abff6438d3de39dea17010, type: 3} m_PrefabInstance: {fileID: 44325156} m_PrefabAsset: {fileID: 0}
其中PrefabInstance里面的数据表示预制体实例的数据
m_ObjectHideFlags表示该预制体是否隐藏,0表示不隐藏。如果隐藏了不单单是在场景和游戏面板看不见预制体,在层级面板也不显示该预制体的名称
serializedVersion表示序列化版本
m_TransformParent表示该预制体的父对象的Transform组件的本地ID
m_Modifications中存储的数据有预制体的本地坐标和预制体修改的数据,如我们禁用Box Collider,场景文件中就会出现下面一串代码
- target: {fileID: 1242430040932248657, guid: 4056222df4abff6438d3de39dea17010,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
fileID对应修改的组件的本地ID
guid对应META文件中的guid,guid具体用处稍后再讲
type表示类型
propertyPath表示修改的参数名称
value表示修改之后的参数值
objectReference表示对象引用
m_CorrespondingSourceObject字段存储的是预制体的FileID和GUID,其中FIleID是预制体的Transform组件的FileID
m_PrefabInstance字段存储的是实例对象的FileID
m_PrefabAsset字段存储实例对象资源的FileID
非序列化文件是Unity无法识别的文件,比如文件夹也会被认为是一个文件,但是无法识别。
文本文件比较特殊,它不属于序列化文件,但是可以被是识别为TextAsset。很像资源文件,但是又不需要资源文件需要进行设置和转化。如txt、xml文件等。
META文件采用YAML格式
META文件的作用:
GUID
GUID是META文件中最重要的数据,可以说GUID就代表了这个文件,只要知道GUID,就可以在工程中找到这个文件。在编译器中可以使用 AssetDatabase.GUIDToAssetPath 和 AssetDatabase.AssetPathToGUID进行切换。
ImportSetting数据
第二重要的就是要保存的ImportSetting数据了,对于不同的资源文件,生成的ImportSetting也不一样。如上面说的AudioImporter、TextureImporter、ModelImporter等。根据数据和Inspector面板中的配置参数,就可以看懂每一行的含义了,此处不做详细讲解。
FileID(LocalID)
对于如图集这样的文件,一个图集中有多个图片,也就是一个文件中含有多个子文件,那么如何使用GUID来对应一个文件呢?此时,就顺理成章引入了LocalID,又称之为FileID。
FileID存储在META文件中,表示对子文件的引用,如下图可以在fileIDToRecycleName下方找到FileID跟资源命名一一对应:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。