Is there a standard/recommended directory structur

2019-03-20 01:18发布

My next project will use Unity 5.6. It will be a game and that will leverage AssetBundle for remote scenes loading. New scenes will be incrementally added afterward. Therefore I hope I won't use a too bad structure that need to be changed a lot in the later stage of the project. Is there a standard/recommended directory structure for Unity projects?

标签: unity3d
2条回答
不美不萌又怎样
2楼-- · 2019-03-20 02:11

At the end of the day, it comes down to whatever works the best for you and makes the most sense for the project. Working on small solo projects, I've found that keeping a simple folder structure separating asset types has worked well to keep things organized (Textures, Scripts, Prefabs, Sprites, etc). Another popular method is to organize by object type:

Animals
├── Crow
│   ├── script
│   └── sprite
└── Snake
    ├── script
    └── sprite

In my experience, organizing by Scene has generally not ended up working out well, especially in the case where assets are shared between scenes - stuff tends to get lost.

I suggest taking some time to mess around with your organization and see what feels right for you, especially if this is your first unity project. Moving files around after you start will not break associations in the inspector, assuming you are not searching through directories in your scripts.

If you need more help deciding, take a look at some of the links below. Link 3 in particular has a pretty lengthy discussion on this topic.

查看更多
够拽才男人
3楼-- · 2019-03-20 02:16

Unity actually does encourage the following structure:

Assets
├── Animations
│   └── ...
├── Editor
│   └── ...
├── Models
│   └── ...
├── Prefabs
│   └── ...
├── Scripts
│   └── ...
└── Textures
    └── ...

This is due to the object oriented way in which Unity thinks: Each folder contains only the information of a certain type needed for an asset. This is especially visible when you look at the Special Folders in Unity.

Even when you look at they build up their standard assets you will notice this structure. I hope you won't have a lot of scenes which do not share any assets with the other scenes, because this would be a very big waste of resources.

What is notable in the Standard Assets, is that in their demo, they have a folder called Menu which contains its own Scripts, Prefabs and Sprites folders.

So I suggest you do the following (note: This is my opinion):

  • Try to separate everything into their own folders without grouping into assets but into filetypes
  • In some cases where scenes have their own assets that are never shared, you may group them into a separate folder
  • I really do not like the idea of "static assets" and "dynamic assets" in the folder structure as proposed by the blogentry of link1 ryemoss gave you. Dynamically loaded assets require you to use the Resources folder anyway, so use this folder instead and put your grouping folders ("Bundle1", "Bundle2", etc.) inside it.
  • Never mix your system. If you think something isn't fitting, change it. But change it for the whole project. Be consistent.
  • Do not force folders to be moved up or down by adding an underscore or something equivalent as prefix.
  • Document your structure somewhere. Depending how large your project is, it may help. But folderstructures are like code, if they don't need a comment to describe what's happening, its (mostly) best.
查看更多
登录 后发表回答