Unity项目架构设计与开发管理

原文链接:http://blog.csdn.net/u013108312/article/details/52555617
1.EmptyGO
2.Simple GameManager
3.Manager of Managers
4.MVCS(StrageloC)
5.MVVM(uFrame)
……….
1.EmptyGo
Put all the code without visual representation in the world onto an empty game object.
Use GameObject.Find() or inspector target references to communicate with each other.

3.Manager of Managers
中型以上的游戏。
MainManager customizes and manages all the sub-managers.
Submanagers operate as singletons and can easily address each other to collaborate.

//MainManager
EventManager
//Streamline messaging between classes.
AudioManager
//Control audio playback from one place.
GUIManager
//Centralize the controls to handle clicks.etc.
PoolManager
//Persist prefab instances in RAM and display them as needed.
LevelManager
//Queue up leves and perform transitions between  them. 这里有个插件可以参考一下:Mad LeveManager
GameManager
//manage the core game mechanics.usually projects pecific.
SaveManger
//Save and load user preferences and achievements.这里有个插件可以参考一下:Save Manager
MenuManger
//Control all menus animations contents and behaviors.

一个中型以上的项目至少有:

 1. Level Manager
 2. Pool Manager
 3. Save Manager

最好要有:

 1. GameManager
 2. EvemtManager
 3. MenuManager
 4. GUIManager
 5. AudioManager

内存管理问题:a simple pool design:

private List dormantObjects = new List();
public GameObject Spawn(GameOjbect go)
{
    GameObject temp = null;
    if(dormantObjects.Count > 0)
    {
        foreach(GameObject dob in dormantObjects)
        {
            if(dob.name == go.name)
            {
                temp = dob;
                dormantObjects.Remove(temp);
                return temp;
            }
        }
    }
    temp = GameObject.Instantiate(go) as GameObject;
    temp.name = go.name;
    return temp;
}
public void Despawn(GameObject go)
{
    go.transform.parent = PoolManager.transform;
    go.SetActive(false);
    dormantObjects.Add(go);
    Trim();
}
public void Trim()
{
    while(dormantObjects.Count > Capacity)
    {
        GameObject dob = dormantObjects[0];
        dormantObjects.RemoveAt(0);
        Destroy(dob);
    }
}

上面的设计出现的问题:
This pool is not able to manager the Load/Unload of prefabs.
Only dormant objects are managed in the pool,active objects must be managed out of pool separately.
The total number of dormant objects can be controlled,rather than the instances of each prefab.
A better design

  • PoolManager
    – SpawnPool
    — PrefabPool
    Active instances.
    Inactive instance.

4.StrageIOC

IBinder.Bind().To();
IBinder.Bind().To().ToName(name);

原文链接:http://blog.csdn.net/u013108312/article/details/52555617

你可能感兴趣的:(Unity3d,架构设计,管理,unity,游戏)