Ejemplo n.º 1
0
    public static void load()
    {
        if (UnityEngine.Object.FindObjectsOfType <MapData>().Length == 0)
        {
            MessageWindow.CreateMessageBox(
                "请打开Mapdata",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
        }
        else
        {
            MapData mapData = UnityEngine.Object.FindObjectOfType <MapData>();

            // 读取新的数据
            if (Directory.Exists(MAP_ID_PATH + "/" + mapData.ID + "/MapGenerator"))
            {
                refreshFromXML();
            }
            else
            {
                MessageWindow.CreateMessageBox(
                    "没有可供导入的数据",
                    delegate(EditorWindow window) { window.Close(); },
                    delegate(EditorWindow window) { window.Close(); }
                    );
            }
        }
    }
Ejemplo n.º 2
0
    public static void createUnit()
    {
        Debug.Log("创建单位");
        if (Selection.gameObjects.Length > 0 &&
            Selection.gameObjects[0].GetComponents <MapGenerator>() != null &&
            Selection.gameObjects[0].GetComponents <MapGenerator>().Length > 0)
        {
            // 自动生成index
            int maxIndex = 0;
            foreach (var unit in Selection.gameObjects[0].GetComponentsInChildren <Unit>())
            {
                if (unit.Index > maxIndex)
                {
                    maxIndex = unit.Index;
                }
            }

            Unit unitComponent = InitializeUnit(maxIndex + 1, Selection.gameObjects[0]);

            // 选中
            EditorGUIUtility.PingObject(unitComponent.gameObject);
            Selection.activeGameObject = unitComponent.gameObject;
        }
        else
        {
            MessageWindow.CreateMessageBox(
                "请选择Generator",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
        }
    }
Ejemplo n.º 3
0
    public static void save()
    {
        // 保存新的mapData
        if (UnityEngine.Object.FindObjectsOfType <MapData>().Length != 1)
        {
            MessageWindow.CreateMessageBox(
                "mapdata数量异常,无法保存",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
            return;
        }
        MapData mapData = UnityEngine.Object.FindObjectOfType <MapData>();


        // 一键修复数据
        autoFix();

        Debug.Log("当前有" + cacheMapData.Count + "个Generator");

        // 清空原来的文件
        if (Directory.Exists(MAP_ID_PATH + "/" + mapData.ID + "/MapGenerator"))
        {
            foreach (var path in Directory.GetFiles(MAP_ID_PATH + "/" + mapData.ID + "/MapGenerator"))
            {
                File.Delete(path);
            }
        }
        else
        {
            Directory.CreateDirectory(MAP_ID_PATH + "/" + mapData.ID + "/MapGenerator");
        }



        foreach (MapGenerator generator in cacheMapData.Keys)
        {
            saveWithXML(mapData, generator);
        }

        // 旧版本
        PrefabUtility.ReplacePrefab(mapData.gameObject, PrefabUtility.CreatePrefab(MAP_ID_PATH + "/" + mapData.ID + "/" + mapData.ID + ".prefab", mapData.gameObject), ReplacePrefabOptions.ConnectToPrefab);

        MessageWindow.CreateMessageBox(
            "保存成功",
            delegate(EditorWindow window) { window.Close(); },
            delegate(EditorWindow window) { window.Close(); }
            );
        // 新版本使用
        // PrefabUtility.SaveAsPrefabAssetAndConnect(mapData.gameObject, MAP_ID_PATH + "/" + mapData.ID + "/" + mapData.ID + ".prefab", InteractionMode.AutomatedAction);
    }
Ejemplo n.º 4
0
 public static void create()
 {
     if (UnityEngine.Object.FindObjectsOfType <MapData>().Length > 0)
     {
         MessageWindow.CreateMessageBox(
             "Mapdata已打开",
             delegate(EditorWindow window) { window.Close(); },
             delegate(EditorWindow window) { window.Close(); }
             );
     }
     else
     {
         EditorWindow.GetWindow(typeof(CreateWindow), true, "创建");
     }
 }
Ejemplo n.º 5
0
    public static void createGenerator()
    {
        Debug.Log("创建生成器");

        GameObject generatorRoot = GameObject.Find("MonsterGenerator");
        MapData    mapData       = UnityEngine.Object.FindObjectOfType <MapData>();

        if (generatorRoot != null)
        {
            // 自动生成index
            int maxIndex = 0;
            int maxID    = UnityEngine.Object.FindObjectOfType <MapData>().ID * 1000;
            loadHierarchyInfoToMapDataCache();
            foreach (var generator in cacheMapData.Keys)
            {
                if (generator.Index > maxIndex)
                {
                    maxIndex = generator.Index;
                }

                if (generator.ID > maxID)
                {
                    maxID = generator.ID;
                }
            }

            MapGenerator mapGenerator = InstantializeGenerator(maxIndex + 1, maxID + 1, generatorRoot);

            // 选中
            EditorGUIUtility.PingObject(mapGenerator.gameObject);
            Selection.activeGameObject = mapGenerator.gameObject;
        }
        else
        {
            MessageWindow.CreateMessageBox(
                "请打开Map",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
        }
    }
    void OnCreatePress()
    {
        // 检索UnitID
        XmlDocument xmlFile = new XmlDocument();
        // 暂时不用检索存在
        bool isXMLExist = true;

        //Debug.Log(unitID.Substring(0, unitID.Length - 3) + "_randbehemothsstatic.xml");
        //foreach (var xmlFilePath in Directory.GetFiles(MapEditor.NINJA_XML_PATH))
        //{

        //    if (xmlFilePath.Contains(unitID.Substring(0, unitID.Length - 3) + "_randbehemothsstatic.xml") && !xmlFilePath.Contains(".meta"))
        //    {
        //        try
        //        {
        //            xmlFile.Load(MapEditor.NINJA_XML_PATH + "/" + unitID.Substring(0, unitID.Length - 3) + "_randbehemothsstatic.xml");
        //            isXMLExist = true;
        //        }
        //        catch
        //        {
        //            Debug.LogWarning("路径无效");
        //        }
        //    }
        //}

        if (!isXMLExist)
        {
            MessageWindow.CreateMessageBox(
                "请输入正确的UnitID",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
        }
        else
        {
            Close();

            //         string staticID = null;

            //XmlNode root = xmlFile.SelectSingleNode("RandBehemothsStaticMap");
            //XmlNode all_infos = root.SelectSingleNode("all_infos");
            //         foreach (XmlNode item in all_infos.SelectNodes("item"))
            //         {
            //             if (item.SelectSingleNode("id").InnerText == unitID)
            //             {
            //                 Debug.Log("找到对应的id" + item.SelectSingleNode("staic_idx").InnerText);
            //                 staticID = item.SelectSingleNode("staic_idx").InnerText;
            //             }
            //         }

            //         if (staticID != null)
            //         {
            //             // 从Ninja表检索资源

            //         }

            // 自动生成index
            int maxIndex = -1;
            foreach (var unit in Selection.gameObjects[0].GetComponentsInChildren <Unit>())
            {
                if (unit.Index > maxIndex)
                {
                    maxIndex = unit.Index;
                }
            }

            GameObject newUnit       = new GameObject();
            Unit       unitComponent = newUnit.AddComponent <Unit>();

            // 默认数据
            unitComponent.Index        = maxIndex + 1;
            unitComponent.Name         = "MonsterGenerator" + unitComponent.Index;
            unitComponent.CreateAction = -1;
            unitComponent.Direction    = -1;
            unitComponent.ID           = int.Parse(unitID);


            newUnit.transform.parent = Selection.gameObjects[0].transform;

            // 添加数据
            // Selection.gameObjects[0].GetComponent<MapGenerator>().Units.Add(unitComponent);

            // 暂时写死加载40001
            // Debug.Log(MapEditor.ACTOR_PREFAB_PATH.Substring(MapEditor.ACTOR_PREFAB_PATH.IndexOf("Config")) + "/40001");
            GameObject actor = Instantiate(Resources.Load("Actor/40001")) as GameObject;
            actor.transform.parent = newUnit.transform;


            // 选中
            EditorGUIUtility.PingObject(newUnit);
            Selection.activeGameObject = newUnit;
        }
    }
Ejemplo n.º 7
0
    // 添加监听事件
    void OnCreatePress()
    {
        Debug.Log("Create On Pressed");
        bool isMapPrefabExist = false;
        bool isMapIDExist     = false;

        // 检索Resources\Scene
        string targetMapPath = "";

        foreach (string path in Directory.GetFiles(MapEditor.MAP_PREFAB_ID_PATH))
        {
            //获取所有文件夹中包含后缀为 .prefab 的路径
            if (Path.GetExtension(path) == ".prefab" && (Path.GetFileNameWithoutExtension(path) == mapPrefabID))
            {
                isMapPrefabExist = true;
                targetMapPath    = "Scene/" + mapPrefabID;
            }
        }

        // 检索Resources\Config\Map
        DirectoryInfo mapDir = new DirectoryInfo(MapEditor.MAP_ID_PATH);

        if (mapDir.Exists)
        {
            foreach (string path in Directory.GetFiles(MapEditor.MAP_ID_PATH))
            {
                if (Path.GetFileNameWithoutExtension(path) == mapID)
                {
                    isMapIDExist = true;
                }
            }
        }

        if (!isMapPrefabExist)
        {
            // 弹出提示信息
            MessageWindow.CreateMessageBox(
                "Map prefab 不存在",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
        }
        else if (isMapIDExist)
        {
            // 是否打开地图
            MessageWindow.CreateMessageBox(
                "地图ID已存在,是否打开地图",
                delegate(EditorWindow window)
            {
                window.Close();
                Close();
                OpenWindow openWindow  = CreateInstance <OpenWindow>();
                openWindow.MapPrefabID = mapPrefabID;
                openWindow.MapID       = mapID;
                openWindow.Show();
            },
                delegate(EditorWindow window) { window.Close(); }
                );
        }
        else
        {
            MapEditor.loadMap(targetMapPath, mapID);
        }
        Close();
    }
Ejemplo n.º 8
0
    private bool SearchRelatedPrefab()
    {
        bool isMapPrefabExist = false;
        bool isMapIDExist     = false;

        // 检索Resources\Scene
        string targetMapPath = "";

        foreach (string path in Directory.GetFiles(MapEditor.MAP_PREFAB_ID_PATH))
        {
            //获取所有文件夹中包含后缀为 .prefab 的路径
            if (Path.GetExtension(path) == ".prefab" && (Path.GetFileNameWithoutExtension(path) == mapPrefabID))
            {
                isMapPrefabExist = true;
                targetMapPath    = "Scene/" + mapPrefabID;
            }
        }

        // 检索Resources\Config\Map
        DirectoryInfo mapDir = new DirectoryInfo(MapEditor.MAP_ID_PATH);

        if (mapDir.Exists)
        {
            foreach (string path in Directory.GetFiles(MapEditor.MAP_ID_PATH))
            {
                if (Path.GetFileNameWithoutExtension(path) == mapID)
                {
                    isMapIDExist = true;
                }
            }
        }

        if (isMapIDExist && isMapPrefabExist)
        {
            MapEditor.loadMap(targetMapPath, mapID);
            return(true);
        }
        else if (!isMapPrefabExist)
        {
            // 弹出提示信息
            MessageWindow.CreateMessageBox(
                "Map prefab 不存在",
                delegate(EditorWindow window) { window.Close(); },
                delegate(EditorWindow window) { window.Close(); }
                );
            return(false);
        }
        else
        {
            // 提示是否新建地图
            MessageWindow.CreateMessageBox(
                "是否新建地图",
                delegate(EditorWindow window)
            {
                window.Close();

                CreateWindow createWindow = CreateInstance <CreateWindow>();
                createWindow.MapPrefabID  = mapPrefabID;
                createWindow.MapID        = mapID;
                createWindow.Show();
            },
                delegate(EditorWindow window) { window.Close(); }
                );
            return(false);
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// 把xml里每个unit的数据加载进mapGenerator
    /// </summary>
    /// <param name="xml"></param>
    /// <param name="mapGenerator"></param>
    private static void loadUnitToGeneratorXML(XmlDocument xmlFile, MapGenerator generator)
    {
        List <Unit> units = new List <Unit>();

        foreach (Unit unit in Resources.FindObjectsOfTypeAll <Unit>())
        {
            if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(unit)) && unit.transform.parent == generator.transform)
            {
                units.Add(unit);
            }
        }
        units.Reverse();
        Debug.Log(generator.Index + "有" + units.Count + "个units");
        int index = 0;


        XmlNodeList items = xmlFile.SelectSingleNode("MonsterPackConfig").SelectSingleNode("ary").SelectNodes("item");

        Debug.Log(generator.Index + "有" + items.Count + "个items");
        if (items.Count != units.Count)
        {
            MessageWindow.CreateMessageBox(
                "Unit需要重置",
                delegate(EditorWindow window)
            {
                foreach (XmlNode item in items)
                {
                    // 更新数据
                    if (units.Count <= index)
                    {
                        // item数量多于unit, 新建unit
                        Unit newUnit = InitializeUnit(units.Count + 1, generator.gameObject);
                        units.Add(newUnit);
                    }

                    loadItemToUnitXML(units[index++], item);
                }

                if (units.Count > index)
                {
                    // 有多余的unit
                    for (int i = index; i < units.Count; i++)
                    {
                        UnityEngine.Object.DestroyImmediate(units[i].gameObject);
                    }
                }
                window.Close();
            },
                delegate(EditorWindow window)
            {
                window.Close();
                return;
            }
                );
        }
        else
        {
            foreach (XmlNode item in items)
            {
                loadItemToUnitXML(units[index++], item);
            }
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// 加载xml里面generator的数据
    /// </summary>
    /// <param name="mapID"></param>
    private static void loadGeneratorXML(string mapID)
    {
        Dictionary <int, MapGenerator> oldGenerators = new Dictionary <int, MapGenerator>();
        Dictionary <int, MapGenerator> newGenerators = new Dictionary <int, MapGenerator>();

        foreach (MapGenerator generator in Resources.FindObjectsOfTypeAll <MapGenerator>())
        {
            if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(generator)))
            {
                oldGenerators.Add(generator.ID, generator);
            }
        }

        if (Directory.Exists(MAP_ID_PATH + "/" + mapID + "/MapGenerator"))
        {
            foreach (var path in Directory.GetFiles(MAP_ID_PATH + "/" + mapID + "/MapGenerator"))
            {
                if (Path.GetExtension(path) == ".bytes")
                {
                    // 先判断是否需要重置generator
                    Debug.Log("导入的index" + int.Parse(Path.GetFileNameWithoutExtension(path).Substring(Path.GetFileNameWithoutExtension(path).Length - 3)));
                    if (!oldGenerators.ContainsKey(int.Parse(Path.GetFileNameWithoutExtension(path))))
                    {
                        MapGenerator mapGenerator = InstantializeGenerator(
                            int.Parse(Path.GetFileNameWithoutExtension(path).Substring(Path.GetFileNameWithoutExtension(path).Length - 3)),
                            int.Parse(Path.GetFileNameWithoutExtension(path)),
                            GameObject.Find("MonsterGenerator"));
                        newGenerators.Add(mapGenerator.ID, mapGenerator);
                    }
                    else
                    {
                        newGenerators.Add(int.Parse(Path.GetFileNameWithoutExtension(path)), oldGenerators[int.Parse(Path.GetFileNameWithoutExtension(path))]);
                        oldGenerators.Remove(int.Parse(Path.GetFileNameWithoutExtension(path)));
                    }
                }
            }
        }

        if (oldGenerators.Count > 0)
        {
            MessageWindow.CreateMessageBox(
                "Generator需要重置",
                delegate(EditorWindow window)
            {
                foreach (var generator in oldGenerators.Values)
                {
                    UnityEngine.Object.DestroyImmediate(generator.gameObject);
                }

                window.Close();
            },
                delegate(EditorWindow window)
            {
                window.Close();
                return;
            }
                );
        }

        foreach (var path in Directory.GetFiles(MAP_ID_PATH + "/" + mapID + "/MapGenerator"))
        {
            if (Path.GetExtension(path) == ".bytes")
            {
                // 依次加载每一个generator
                XmlDocument xmlFile    = new XmlDocument();
                FileStream  fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
                try
                {
                    xmlFile.Load(fileStream);
                }
                catch (XmlException e)
                {
                    Debug.LogWarning("加载出错" + e.Message);
                }
                fileStream.Close();
                loadUnitToGeneratorXML(xmlFile, newGenerators[int.Parse(Path.GetFileNameWithoutExtension(path))]);
            }
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 进行MapGenerator, Unit的index检查[已弃用]
    /// </summary>
    private static bool checkValidity()
    {
        MapData mapData = UnityEngine.Object.FindObjectOfType <MapData>();

        if (mapData == null)
        {
            return(true);
        }
        HashSet <int> tempHashSet = new HashSet <int>();

        Debug.LogWarning("当前有" + UnityEngine.Object.FindObjectsOfType <MapGenerator>().Length + "个MapGenerator");
        foreach (var generator in UnityEngine.Object.FindObjectsOfType <MapGenerator>())
        {
            if (!tempHashSet.Add(generator.Index))
            {
                // index already exist
                MessageWindow.CreateMessageBox(
                    generator.Name + "_" + generator.ID + "命名非法, 是否一键修复",
                    delegate(EditorWindow window)
                {
                    // 一键修复index
                    int i = UnityEngine.Object.FindObjectsOfType <MapGenerator>().Length;
                    foreach (var item in UnityEngine.Object.FindObjectsOfType <MapGenerator>())
                    {
                        item.Index = --i;
                    }
                    save();
                    window.Close();
                },
                    delegate(EditorWindow window) { window.Close(); }
                    );


                return(false);
            }
        }

        foreach (var generator in UnityEngine.Object.FindObjectsOfType <MapGenerator>())
        {
            tempHashSet.Clear();
            foreach (var unit in generator.GetComponentsInChildren <Unit>())
            {
                if (!tempHashSet.Add(unit.Index))
                {
                    // index already exist
                    MessageWindow.CreateMessageBox(
                        unit.Name + "_" + unit.ID + "命名非法, 是否一键修复",
                        delegate(EditorWindow window)
                    {
                        // 一键修复index
                        int i = 0;
                        foreach (var item in generator.GetComponentsInChildren <Unit>())
                        {
                            item.Index = i++;
                        }
                        save();
                        window.Close();
                    },
                        delegate(EditorWindow window) { window.Close(); }
                        );

                    return(false);
                }
            }
            tempHashSet.Clear();
        }
        return(true);
    }