Game Data study - XianWorld/xxxgame GitHub Wiki

Know How

C# native object serialize / deserialize

  • YamlSerializer-Fork: A library that serialize / deserialize C# native objects into YAML1.2 text.

Unity asset format and management

Unity asset object

  • Audio Clip

    • Format: The audio file formats that Unity can import are .aif, .wav, .mp3, and .ogg. Unity can also import tracker modules in the .xm, .mod, .it, and .s3m formats.
    • Asset Class: AudioClip
    • Component: AudioSource/AudioListener
  • MonoScript

    • Format: .cs/.js/..
    • Class: MonoScript(TextAsset)
  • Text Asset:

    • Format: .txt/.html/.htm/.xml/.bytes/json/.csv/yaml/.fnt
    • Class: TextAsset
  • Mesh:

    • Format: Unity can read .FBX, .dae (Collada), .3DS, .dxf and .obj files, Unity can also import, through conversion: Max, Maya, Blender, Cinema4D, Modo, Lightwave & Cheetah3D files, e.g. .MAX, .MB, .MA etc. By default, .fbx, .max, .jas and .c4d files have a scale of 0.01, .mb, .ma, .lxo, .dxf, .blend and .dae files have a scale of 1.0 and .3ds files have a scale of 0.1.
    • Asset Class: Mesh
    • Component: MeshFilter/MeshRenderer/SkinnedMeshRenderer
  • Font

    • Format: Supported Font formats are TrueType Fonts (.ttf files) and OpenType Fonts (.otf files).
  • Custom fonts

    • Format: .fontsettings
  • PhysicsMaterial2D

    • Format: .physicsmaterial2d
    • Asset Class: PhysicsMaterial2D
    • Component: Collider2D
  • PhysicMaterial

    • Format: .physicMaterial
    • Asset Class: PhysicMaterial
    • Component: Collider
  • Flare

    • Format: .flare
    • Asset Class: Flare
    • Component: LensFlare
  • Shader

    • Format: .shader
    • Asset Class: Shader
  • ComputeShader

    • Format: .compute
    • Asset Class: ComputeShader
  • Material

    • Format: .material
    • Asset Class: Material
    • Component: MeshRenderer/SkinnedMeshRenderer
  • Procedural Materials

    • Format: Unity’s Procedural Material system is based around an industry standard product called Substance, developed by Allegorithmic. A Procedural Material is supplied as a Substance Archive file (SBSAR) which you can import like any other asset.
    • Asset Class: Material
  • Texture2D

    • Format: Unity can read the following file formats: PSD, TIFF, JPG, TGA, PNG, GIF, BMP, IFF, PICT. It should be noted that Unity can import multi-layer PSD & TIFF files just fine.
    • Asset Class: Texture2D
  • Movie Texture

    • Format: Video files are imported via Apple QuickTime. Supported file types are what your QuickTime installation can play (usually .mov, .mpg, .mpeg, .mp4, .avi, .asf).
    • Asset Class: MovieTexture
  • Cubmap: .cubmap

    • Format: .material
    • Asset Class: Material
  • Render Texture

    • Format: .rendertexture
    • Asset Class: RenderTexture
    • Component: Camera
  • Animation Clip

    • Format: .anim
    • Asset Class: AnimationClip
    • Component: Animation/Animator(AnimatorController)
  • Animator controller

    • Format: .controller
    • Asset Class: AnimatorController
    • Component: Animator
  • Animator overide controller

    • Format: .overridecontroller
    • Asset Class: AnimatorOverrideController
  • Prefeb

    • Format: .prefab
    • Asset Class: GameObject?

Unity asset importer/manager/processor

  • AssetPostprocessor
  • AssetModificationProcessor
  • AssetImporter
  • AssetDatabase
  • AssetBundle
  • AssetPreview

Meta File

Unity use meta file and file GUID to manage and associate all resource files. Meta file:

fileFormatVersion: 2
guid: aa314cb43ff282a4fa08dff1b6f23117
NativeFormatImporter:
  userData: 

YAML format

Some special files are fomat in YAML,

Unity prefeb file:

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &100000
GameObject:
  m_ObjectHideFlags: 0
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  serializedVersion: 4
  m_Component:
  - 4: {fileID: 400000}
  - 33: {fileID: 3300000}
  - 23: {fileID: 2300000}
  - 54: {fileID: 5400000}
  - 64: {fileID: 6400000}
  - 114: {fileID: 11400002}
  - 114: {fileID: 11400000}
  m_Layer: 0
  m_Name: Axe
  m_TagString: Untagged
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_StaticEditorFlags: 0
  m_IsActive: 1
--- !u!4 &400000
Transform:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  m_LocalPosition: {x: 9.21761227, y: .0560611784, z: -.801264763}
  m_LocalScale: {x: 1, y: 1, z: 1}
  m_Children: []
  m_Father: {fileID: 0}
--- !u!23 &2300000
Renderer:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  m_Enabled: 1
  m_CastShadows: 1
  m_ReceiveShadows: 1
  m_LightmapIndex: 255
  m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
  m_Materials:
  - {fileID: 2100000, guid: 1b7c5d2ac9ccda1489ae45d65ab9d520, type: 2}
  m_SubsetIndices: 
  m_StaticBatchRoot: {fileID: 0}
  m_UseLightProbes: 0
  m_LightProbeAnchor: {fileID: 0}
  m_ScaleInLightmap: 1
--- !u!33 &3300000
MeshFilter:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  m_Mesh: {fileID: 4300000, guid: 504ba419c62c689499e5396a57ad1acd, type: 3}
--- !u!54 &5400000
Rigidbody:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  serializedVersion: 2
  m_Mass: 1
  m_Drag: 0
  m_AngularDrag: .0500000007
  m_UseGravity: 1
  m_IsKinematic: 0
  m_Interpolate: 0
  m_Constraints: 0
  m_CollisionDetection: 0
--- !u!64 &6400000
MeshCollider:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  m_Material: {fileID: 0}
  m_IsTrigger: 0
  m_Enabled: 1
  serializedVersion: 2
  m_SmoothSphereCollisions: 0
  m_Convex: 1
  m_Mesh: {fileID: 4300000, guid: 504ba419c62c689499e5396a57ad1acd, type: 3}
--- !u!114 &11400000
MonoBehaviour:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: aa584fbee541324448dd18d8409c7a41, type: 3}
  m_Name: 
  subId: 0
  ownerId: 0
  group: 0
  prefixBackup: -1
  observed: {fileID: 0}
  synchronization: 0
  onSerializeTransformOption: 3
  onSerializeRigidBodyOption: 2
  instantiationId: 0
--- !u!114 &11400002
MonoBehaviour:
  m_ObjectHideFlags: 1
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 100100000}
  m_GameObject: {fileID: 100000}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: a668f3eb948b1db4e977bb626bc0abf3, type: 3}
  m_Name: 
  item: {fileID: 11400000, guid: aa314cb43ff282a4fa08dff1b6f23117, type: 2}
  pickUpDistance: 5
  lookAtItem: 1
  playPickUpAnimation: 1
--- !u!1001 &100100000
Prefab:
  m_ObjectHideFlags: 1
  serializedVersion: 2
  m_Modification:
    m_TransformParent: {fileID: 0}
    m_Modifications: []
    m_RemovedComponents: []
  m_ParentPrefab: {fileID: 0}
  m_RootGameObject: {fileID: 100000}
  m_IsPrefabParent: 1
  m_IsExploded: 1

Unity ScriptObject asset file:

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_PrefabParentObject: {fileID: 0}
  m_PrefabInternal: {fileID: 0}
  m_GameObject: {fileID: 0}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: 2ef8fc99f4f971045a37fca630b1a139, type: 3}
  m_Name: Axe
  itemName: Axe
  description: Axe
  prefab: {fileID: 100000, guid: df1e6b0cae2d51047a316662028a2315, type: 2}
  stackable: 0
  icon: Axe
  neededCraftingItems:
  - item: {fileID: 11400000, guid: e6dc07ba35630a1408407f8b4fe36a09, type: 2}
    amount: 1
  - item: {fileID: 11400000, guid: 1557710d8ba3c9b40b001cbc43fd5b9c, type: 2}
    amount: 1
  - item: {fileID: 11400000, guid: 1a7084ca7a3ff004e87242b20d56cf14, type: 2}
    amount: 1
  dropSound: {fileID: 8300000, guid: f70f48cdb8e76d34c9e50e4ab73ebd1c, type: 3}
  buyPrice: 22
  sellPrice: 18
  coolDown: 0
  characterClasses:
  - Warlock
  bonus: []
  equipmentRegion: 3
  overrideMouseTalent: {fileID: 0}
  overrideIdle: {fileID: 0}

Save/Load asset & serialize/deserialize Object

Use AssetDatabase.CreateAsset/AssetDatabase.SaveAssets to serialize Object to asset file or create/modify meta file.

Use EditorUtility.SetDirty to set dirty flag to notify unity the asset is dirty.

Use Resources.Load/AssetDatabase.LoadAssetAtPath to check meta file and deserialize Object from asset file, like this:

	public static Object Load(string path, Type systemTypeInstance) 
        {
            Object asset = null;

            if (File.Exists (path))
            {
                Stream stream = File.OpenRead (path);
                XmlSerializer deserializer = new XmlSerializer (systemTypeInstance);
                asset = (Object)deserializer.Deserialize (stream);
                stream.Close ();
            }

            return asset; 
        }

References

Game Data Editor

Game Data Editor is the complete data management package for Unity. GDE will manage your game data with minimal configuration. It handles all data serialization and provides generated custom data classes for fast access and modification on the fly.

Full Inspector: Inspect Everything

Full Inspector super-powers the Inspector so that it just works, even with generics and inheritance. Enjoy a proper list editor. See why Full Inspector is so well loved -- you won't be able to use Unity without it after trying it out!

Full Inspector seamlessly integrates your favorite serializer into Unity, whether is be Full Serializer, Json.NET, protobuf-net, BinaryFormatter, or a custom solution.

Advanced Inspector

You won't need to write custom editor ever again.

The Advanced Inspector gives you full control over how items are displayed, named, colored or even created, directly from attributes.

Generic Inspector

Sick of writing custom inspector ? This package is for you ! 45 C# Attributes to easily and quickly create beautiful and efficient custom inspectors.