コード例 #1
0
ファイル: EntityManager.cs プロジェクト: c2001324/Leo
    public Entity Create(string keyName, RoomInstance room, HexCell cell, BaseParams param)
    {
        JEntityConfig config = GetEntityConfig(keyName);

        if (config == null)
        {
            Debug.LogError("找不到名为 " + keyName + "的EntityConfig");
            return(null);
        }

        Type type = config.entityType;

        if (type == null)
        {
            Debug.LogError(keyName + " 找不到类型 " + config.type);
            return(null);
        }

        EntityModel entityModel = EntityModelManager.instance.GetEntityModel(config.entityModel);

        if (entityModel == null)
        {
            Debug.LogError("找不到  " + keyName + "的EntityModel " + config.entityModel);
            return(null);
        }

        HexagonsWithCenter cells = room.hexRoom.FindClearCellsInRange(config.size, cell, -1);

        if (cells == null)
        {
            Debug.LogError("找不到出生点!对象" + keyName);
            return(null);
        }
        //保证Y轴

        uint oid = 0;

        do
        {
            oid = GuidCreator.GetOid();
        }while (m_EntityDict.ContainsKey(oid));
        Entity entity = Entity.CreateEntity(type, oid, keyName, config, entityModel, cells, param);

        if (entity != null)
        {
            m_EntityDict.Add(entity.oid, entity);
            room.AddEntity(entity);
            entity.Born(cells);
        }
        return(entity);
    }