Unity文件解析

Unity项目中Assets目录下常见的文件类型

1.资源文件     2.代码文件    3.序列化文件    4.文本文档     5.非序列文件     6.Meat文件

资源文件值一些创建好不能修改的文件。比如FBX文件 ,贴图文件 ,音频文件 ,视频文件 ,动画文件等 这些文件在导入unity中都会再导入时进行转化,每一个类型对应着一个AsssetImporter,比如ModelImporter,AudioImporter,TextureImporter等

代码文件 包括所有的代码文件,代码库文件,Shader文件等在导入时,unity会进行一次编译

序列化文件 通常指unity能够序列化的文件,一边是unity自身的类型prefab,mat,unity3d等 这些文件能在运行时直接反序列化成对应类的一个实例

文本文档 unity能够识别成TextAsset 比如txt xml

非序列文件

meta文件主要有两个作用

           1.定义在他同目录下,同名的非mate文件的唯一id:guid 对于unity的序列化文件来说,引用的对象就是这个guid

           2.存储资源文件的importsetting属性 每次修改导入设置都会修改mate文件

Mate文件详解

扫描二维码关注公众号,回复: 2279863 查看本文章

           由于mate文件的重要性 先来看一下mate文件的数据结构。mate文件实质上是一个文本文档采用YAML的格式书写。unity序列化的文件都是采用这种格式书写的

fileFormatVersion: 2
guid: 775866e3b54d59e4980effb0aac22008
timeCreated: 1467775326
licenseType: Pro
TextureImporter:
  fileIDToRecycleName: {}
  serializedVersion: 2
  mipmaps:
    mipMapMode: 0
    enableMipMap: 0
    linearTexture: 0
    correctGamma: 0
    fadeOut: 0
    borderMipMap: 0
    mipMapFadeDistanceStart: 1
    mipMapFadeDistanceEnd: 3
  bumpmap:
    convertToNormalMap: 0
    externalNormalMap: 0
    heightScale: 0.25
    normalMapFilter: 0
  isReadable: 0
  grayScaleToAlpha: 0
  generateCubemap: 0
  cubemapConvolution: 0
  cubemapConvolutionSteps: 7
  cubemapConvolutionExponent: 1.5
  seamlessCubemap: 0
  textureFormat: -1
  maxTextureSize: 2048
  textureSettings:
    filterMode: -1
    aniso: 0
    mipBias: -1
    wrapMode: 1
  nPOTScale: 1
  lightmap: 0
  rGBM: 0
  compressionQuality: 50
  allowsAlphaSplitting: 0
  spriteMode: 0
  spriteExtrude: 1
  spriteMeshType: 1
  alignment: 0
  spritePivot: {x: 0.5, y: 0.5}
  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
  spritePixelsToUnits: 100
  alphaIsTransparency: 0
  spriteTessellationDetail: -1
  textureType: 5
  buildTargetSettings:
  - buildTarget: iPhone
    maxTextureSize: 1024
    textureFormat: 32
    compressionQuality: 100
    allowsAlphaSplitting: 0
  - buildTarget: Android
    maxTextureSize: 1024
    textureFormat: 34
    compressionQuality: 100
    allowsAlphaSplitting: 0
  spriteSheet:
    serializedVersion: 2
    sprites: []
    outline: []
  spritePackingTag: 
  userData: 
  assetBundleName: 
  assetBundleVariant: 

比较关键的数据:

GUID 这个GUID代表这个文件,无论这个文件是什么类型 。换句话说,通过GUID就可以找到工程中的这个文件,无论他在项目的什么位置 API AssetDatabase.GUIDToAssetPath  AssetDatabase.AssetPathToGUID

ImportSetting数据 根据不同的文件类型 他的数据是不同的ImportSetting数据,比如TextureImporter等  只要把文件与mate文件同时移动到新的工程 文件的设置是不变的

fileFormatVersion: 2
guid: d9841abbabfd06a4cb5cb6cf325bb546
ModelImporter:
  serializedVersion: 16
  fileIDToRecycleName:
    100000: //RootNode
    100002: Object001
    100004: wuqi
    400000: //RootNode
    400002: Object001
    400004: wuqi
    4300000: Object001
    9500000: //RootNode
    11100000: //RootNode
    13700000: Object001

FileID 对于一个文件下面有多个文件的情况下就需要另外一种ID表示 LocalID 在mate文件中叫做FileID  FileID存储有两种方式

1对于资源文件,非序列化文件 由于不会去修改源文件 所以FileID存储在mate文件中

2对于序列化文件,自身数据里面会存储自身FileID,也会记录所有子文件的FileID  但是Mate文件中只有自身的FileID

 

Unity文件引用系统

Unity的序列化文件都是采用YMAL编写的 对于场景,prefab 材质,控制器都可以用文件打开

GameObject数据

组件数据 (Behave)___  !u!124&222222222     在YMAL中根据 124来知道当前组件是什么类型的组件

自定义脚本文件 添加一个继承自MonoBehaver的脚本挂载到摄像机上

可以看到多了一个MonoBehavior,并且里面包含一个m_Script的数据,指向对应的GUID和FileID 就能找到具体的文件识别相应的实例

Prefab数据

  m_ObjectHideFlags: 0
  serializedVersion: 2
  m_Modification:
    m_TransformParent: {fileID: 0}
    m_Modifications:
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalPosition.x
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalPosition.y
      value: 2.21
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalPosition.z
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalRotation.x
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalRotation.y
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalRotation.z
      value: 0
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_LocalRotation.w
      value: 1
      objectReference: {fileID: 0}
    - target: {fileID: 4704561243888710, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
      propertyPath: m_RootOrder
      value: 2
      objectReference: {fileID: 0}
    m_RemovedComponents: []
  m_ParentPrefab: {fileID: 100100000, guid: 39d3820a9d9b44a81ab4672a9b7309dc, type: 2}
  m_IsPrefabParent: 0

看起来很复杂,但是实际上,它就保存了最重要的几个数据:

  • Modification:每个组件的修改数据列表,但凡修改的数据,都会在这里体现。
  • ParentPrefab:表示是哪一个Prefab。

猜你喜欢

转载自blog.csdn.net/ww386362087/article/details/81114543