Ejemplo n.º 1
0
    /// 添加GameObject到列表
    /// id 主要是用于区分怪物
    public void addGameObject(GameObject gameobject, int id)
    {
        if (gameobject == null)
        {
            return;
        }

        ClientElementInfo cellVo           = new ClientElementInfo();
        GameObjectCellVo  gameObjectCellVo = new GameObjectCellVo();

        GameObjectDestroyCallBack gameObjectDestroyCallBack = gameobject.GetComponent <GameObjectDestroyCallBack>();       //用于监听销毁

        if (gameObjectDestroyCallBack == null)
        {
            gameObjectDestroyCallBack = gameobject.AddComponent <GameObjectDestroyCallBack> ();
        }
        gameObjectDestroyCallBack.destroyCallBack = removeGameObject;
        gameObjectDestroyCallBack.cellVo          = cellVo;

        cellVo.setSourceName(gameobject.name);
        cellVo.model = id;
        //cellVo.id = AutoId.id++;
        gameobject.name = cellVo.getSourceName() + "|" + cellVo.model;// objId;
        //cellVo.name = gameobject.name;
        gameObjectCellVo.cellVo            = cellVo;
        gameObjectCellVo.currentGameObject = gameobject;
        cellList.Add(gameObjectCellVo);

        objId += 1;
    }
Ejemplo n.º 2
0
    /// 添加GameObject到列表
    public void addGameObject(ClientElementInfo cellVo, GameObject gameobject)
    {
        if (gameobject == null)
        {
            return;
        }

        GameObjectDestroyCallBack gameObjectDestroyCallBack = gameobject.GetComponent <GameObjectDestroyCallBack>(); //用于监听销毁

        if (gameObjectDestroyCallBack == null)
        {
            gameObjectDestroyCallBack = gameobject.AddComponent <GameObjectDestroyCallBack> ();
        }
        gameObjectDestroyCallBack.destroyCallBack = removeGameObject;
        gameObjectDestroyCallBack.cellVo          = cellVo;

        GameObjectCellVo gameObjectCellVo = new GameObjectCellVo();

        gameObjectCellVo.cellVo = cellVo;

        gameobject.transform.position = gameobject.transform.position;
        gameobject.name = cellVo.getSourceName() + "|" + cellVo.model;

        gameObjectCellVo.currentGameObject = gameobject;
        cellList.Add(gameObjectCellVo);

        objId += 1;
    }
Ejemplo n.º 3
0
    public static FloatPositionVo GetVORotation(int model)
    {
        FloatPositionVo pos      = new FloatPositionVo();
        SceneConfigVo   sceneCfg = MapEditorFunctionSelector.sceneConfigVo;

        if (sceneCfg == null)
        {
            return(null);
        }
        List <SceneElementInfo> list = sceneCfg.transfer;

        if (list == null)
        {
            return(null);
        }
        ClientElementInfo info = null;

        for (int i = 0; i < list.Count; i++)
        {
            info = list[i];
            if (info.model == model)
            {
                return(info.rotation);
            }
        }
        return(null);
    }
Ejemplo n.º 4
0
    public static PositionVo GetVOPosition(int model)
    {
        PositionVo    pos      = new PositionVo();
        SceneConfigVo sceneCfg = MapEditorFunctionSelector.sceneConfigVo;

        if (sceneCfg == null)
        {
            return(pos);
        }
        List <SceneElementInfo> list = sceneCfg.transfer;

        if (list == null)
        {
            return(pos);
        }
        ClientElementInfo info = null;

        for (int i = 0; i < list.Count; i++)
        {
            info = list[i];
            if (info.model == model)
            {
                pos.x = info.location.x;
                pos.y = info.location.y;
                pos.z = info.location.z;
                return(pos);
            }
        }
        return(pos);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 角色出生点加载器
    /// </summary>
    public static void load()
    {
        if (MapEditorSceneModel.Instance.mapInfos.playerSpawn == null)
        {
            return;
        }
        ClientElementInfo cellVo = null;
        SceneObjVo        vo     = null;

        for (int index = 0; index < MapEditorSceneModel.Instance.mapInfos.playerSpawn.Count; index++)
        {
            vo = MapEditorSceneModel.Instance.mapInfos.playerSpawn[index];

            cellVo            = new ClientElementInfo();
            cellVo.id         = vo.id;
            cellVo.model      = vo.model;
            cellVo.sourceType = ElementVo.ELEMENT_TYPE_PLAYERSPAWN;

            //cellVo.localScale = new PositionVo ();
            cellVo.rotation = GetVORotation(cellVo.model);
            cellVo.location = GetVOPosition(cellVo.model);

            GameObject currentGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(string.Format("Assets/Res/EditObj/{0}.prefab", cellVo.getSourceName()));// ("Assets/Res/EditObj/" + cellVo.getSourceName());
            MapImpotrEditorModel.Instance.addLoadedInfo(cellVo, currentGameObject);
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// 加载monster资源
    /// </summary>
    public static void load()
    {
        if (MapEditorSceneModel.Instance.mapInfos.monsters == null)
        {
            return;
        }
        ClientElementInfo cellVo = null;
        ClientElementInfo vo     = null;

        for (int index = 0; index < MapEditorSceneModel.Instance.mapInfos.monsters.Count; index++)
        {
            vo           = MapEditorSceneModel.Instance.mapInfos.monsters[index];
            AutoId.id    = Math.Max(vo.id, AutoId.id);
            cellVo       = new ClientElementInfo();
            cellVo.model = vo.model;
            cellVo.id    = vo.id;
            //cellVo.entityType = vo.entityType;
            cellVo.sourceType = ElementVo.ELEMENT_TYPE_MONSTER;

            //cellVo.localScale = vo.localScale;
            cellVo.location = vo.location;
            cellVo.rotation = vo.rotation;

            GameObject currentGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(string.Format("Assets/Res/EditObj/{0}.prefab", cellVo.getSourceName()));
            MapImpotrEditorModel.Instance.addLoadedInfo(cellVo, currentGameObject);
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// 保存数据
    /// </summary>
    public void addLoadedInfo(ClientElementInfo cellVo, GameObject gameObject)
    {
        ImportEditorModel importEditor = new ImportEditorModel();

        importEditor.cellVo     = cellVo;
        importEditor.gameObject = gameObject;

        listModels.Add(importEditor);
    }
Ejemplo n.º 8
0
    /// 删除GameObject
    public void removeGameObject(ClientElementInfo gameObject)
    {
        GameObjectCellVo cellVo = existGameObject(gameObject);

        if (cellVo == null)
        {
            return;
        }
        cellList.Remove(cellVo);
    }
Ejemplo n.º 9
0
    private void InitMapInfos(int mapId)
    {
        MapInfos info = new MapInfos();

        info.allmonster   = serverModel.monsterList.data;
        info.npcs         = GetSceneObjOnListByMapId(serverModel.npcList.data, mapId);
        info.transfers    = GetSceneElementOnListByMapId(serverModel.doorList.data, mapId);
        info.playerSpawn  = GetSceneObjOnListByMapId(serverModel.playerSpawn.data, mapId);
        info.monsterSpawn = GetSceneObjOnListByMapId(serverModel.monsterSpawn.data, mapId);

        serverModel.mapInfos = info;

        string sid = serverModel.mapVo.mapresid.ToString();

        EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();       //询问有修改的场景时的 保存当前修改场景
        EditorSceneManager.OpenScene(string.Format(sceneAssetsRoot, sid)); // 打开场景
        EditorMapView.mapName = serverModel.mapVo.map_name;

        sceneConfigVo = EditorSceneConfigLoader.importScene(mapId);// 导入场景数据
        if (sceneConfigVo != null)
        {
            sceneConfigVo.resId = sid;
            for (int i = 0; i < sceneConfigVo.monster.Count; i++)
            {
                ClientElementInfo monInfo = sceneConfigVo.monster[i];
                for (int j = 0; j < serverModel.monsterList.data.Count; j++)
                {
                    SceneObjVo monVo = serverModel.monsterList.data[j];
                }
            }

            info.monsters = sceneConfigVo.monster;
        }

        //加载服务器传来的怪物数据
        EditorNpcLoader.load();          //载入NPC
        EditorElementLoader.load();      // 载入传送门
        EditorMonsterLoader.load();      // 载入Monster
        EditorPlayerSpawnLoader.load();  // 载入玩家出生点
        EditorMonsterSpawnLoader.load(); // 载入刷怪区

        Rect      wr     = new Rect(0, 0, 310, 260);
        MapEditor window = (MapEditor)GetWindowWithRect(typeof(MapEditor), wr, true, "地图编辑器");

        window.editSceneVo.isImportMap = true;
        window.editSceneVo.sceneId     = mapId;
        window.Show();

        this.Close();
    }
Ejemplo n.º 10
0
    /// 返回某个GameObject数据
    public GameObjectCellVo existGameObject(ClientElementInfo gameObject)
    {
        GameObjectCellVo cell = null;

        for (int index = 0; index < cellList.Count; index++)
        {
            cell = cellList[index];
            if (cell.currentGameObject == null)
            {
                continue;
            }

            if (cell.cellVo.Equals(gameObject) == true)
            {
                return(cell);
            }
        }
        return(null);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 处理导入地图逻辑
    /// </summary>
    public void onHandleImportMap()
    {
        if (editSceneVo.isImportMap == true)
        {
            return;
        }
        MapImpotrEditorModel.ImportEditorModel importEditorModel = null;

        //导入服务端记录的场景元素
        int totalGameObjects = MapImpotrEditorModel.Instance.totalCout();

        for (int index = 0; index < totalGameObjects; index++)
        {
            importEditorModel = MapImpotrEditorModel.Instance.getImportEditorModel(index);
            ClientElementInfo cellVo   = importEditorModel.cellVo;
            GameObject        importGO = importEditorModel.gameObject;
            GameObject        curGO    = null;
            if (importGO == null)   //如果当前的GameObject为空,就使用正方体代替
            {
                curGO      = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                curGO.name = cellVo.getSourceName();

                MeshRenderer meshRender = curGO.GetComponent <MeshRenderer>();
                Material     material   = new Material(Shader.Find("Diffuse"));
                if (curGO.name.Contains("Monster"))
                {
                    material.SetColor("_Color", Color.blue);
                }
                else if (curGO.name.Contains("Npc"))
                {
                    material.SetColor("_Color", Color.red);
                }
                else if (curGO.name.Contains("Door"))
                {
                    material.SetColor("_Color", Color.yellow);
                }
                meshRender.sharedMaterial = material;
            }
            else
            {
                curGO      = GameObject.Instantiate(importGO);
                curGO.name = cellVo.getSourceName();
            }

            //计算位置
            curGO.transform.position = new Vector3((float)cellVo.location.x, (float)cellVo.location.y, (float)cellVo.location.z);

            //计算旋转角度
            if (cellVo.rotation != null)
            {
                Vector3 currentRotation = cellVo.rotation.toRotation();
                if (currentRotation.magnitude >= 0.01f)
                {
                    curGO.transform.rotation = Quaternion.Euler(currentRotation);
                }
                else
                {
                    if (importGO != null)
                    {
                        curGO.transform.rotation = importGO.transform.rotation;
                    }
                }
            }
            MapEditorModel.Instance.addGameObject(cellVo, curGO);
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// 导出服务端需要的场景数据
    /// </summary>
    /// <param name="listCellVos">List cell vos.</param>
    /// <param name="editSceneVo">Edit scene vo.</param>
    private static void exportConfig(List <GameObjectCellVo> listCellVos, EditSceneVo editSceneVo, string outPath)
    {
        SceneConfigVo sceneConfig = new SceneConfigVo();

        sceneConfig.sceneId   = editSceneVo.sceneId;
        sceneConfig.sceneName = editSceneVo.mapName;
        sceneConfig.resId     = editSceneVo.resId;
        GameObjectCellVo curGOVo;

        for (int index = 0; index < listCellVos.Count; index++)
        {
            curGOVo = listCellVos[index];
            if (curGOVo == null || string.IsNullOrEmpty(curGOVo.cellVo.sourceType) == true)
            {
                continue;
            }
            ClientElementInfo cellVo = curGOVo.cellVo;
            cellVo.location = new PositionVo();

            if (curGOVo.currentGameObject != null)
            {
                Vector3 pos = curGOVo.currentGameObject.transform.position;
                cellVo.location.x = Mathf.Round(pos.x * 10000) / 10000;
                cellVo.location.y = Mathf.Round(pos.y * 10000) / 10000;
                cellVo.location.z = Mathf.Round(pos.z * 10000) / 10000;
                cellVo.rotation   = FloatPositionVo.toPosition(curGOVo.currentGameObject.transform.rotation.eulerAngles);
            }
            //npc
            if (cellVo.sourceType.Contains(ElementVo.ELEMENT_TYPE_NPC) == true)
            {
                sceneConfig.npcs.Add(cellVo);
                continue;
            }
            //door
            if (cellVo.sourceType.Contains(ElementVo.ELEMENT_TYPE_DOOR) == true)
            {
                sceneConfig.transfer.Add((SceneElementInfo)cellVo);
                continue;
            }
            //刷怪区
            if (cellVo.sourceType.Contains(ElementVo.ELEMENT_TYPE_MONSTERSPAWN) == true)
            {
                sceneConfig.monsterSpawn.Add(cellVo);
                continue;
            }
            //monster
            if (cellVo.sourceType.Contains(ElementVo.ELEMENT_TYPE_MONSTER) == true)
            {
                sceneConfig.monster.Add(cellVo);
                continue;
            }
            //玩家出生点
            if (cellVo.sourceType.Contains(ElementVo.ELEMENT_TYPE_PLAYERSPAWN) == true)
            {
                sceneConfig.playerSpawn.Add(cellVo);
                continue;
            }
        }
        string   filepath = Application.dataPath + string.Format(outPath, editSceneVo.sceneId);
        FileInfo t        = new FileInfo(filepath);

        if (!File.Exists(filepath))
        {
            File.Delete(filepath);
        }
        StreamWriter sw = t.CreateText();

        sw.WriteLine(JsonMapper.ToJson(sceneConfig));
        sw.Close();
        sw.Dispose();
        Debug.Log(sceneConfig.sceneName + " 导出完成!!!!!!!!!!");
    }