コード例 #1
0
 public Spawner(SpawnRuleDefine define, Map map)
 {
     this.Define = define;
     this.Map    = map;
     if (DataManager.Instance.SpawnPoints.ContainsKey(this.Map.ID))
     {
         spawnPoint = DataManager.Instance.SpawnPoints[this.Map.ID][this.Define.SpawnPoint];
     }
     else
     {
         Log.ErrorFormat("SpawnRule[{0}] SpawnPoint[{1}] not existed", this.Define.ID, this.Define.SpawnPoint);
     }
 }
コード例 #2
0
    public static void ExportSpawnPoints()
    {
        DataManager.Instance.Load();
        Scene  current      = EditorSceneManager.GetActiveScene();
        string currentScene = current.name;

        if (current.isDirty)
        {
            EditorUtility.DisplayDialog("提示", "请先保存当前场景", "确定");
            return;
        }
        if (DataManager.Instance.SpawnPoints == null)
        {
            DataManager.Instance.SpawnPoints = new Dictionary <int, Dictionary <int, SpawnPointDefine> >();
        }
        string sceneFile;

        foreach (var map in DataManager.Instance.Maps)
        {
            sceneFile = "Assets/Levels/" + map.Value.Resource + ".unity";
            if (!System.IO.File.Exists(sceneFile))
            {
                Debug.LogWarningFormat("Scene{0} not existed!", sceneFile);
                continue;
            }
            EditorSceneManager.OpenScene(sceneFile, OpenSceneMode.Single);
            SpawnPoint[] spawnPoints = GameObject.FindObjectsOfType <SpawnPoint>();
            if (!DataManager.Instance.SpawnPoints.ContainsKey(map.Value.ID))
            {
                DataManager.Instance.SpawnPoints[map.Value.ID] = new Dictionary <int, SpawnPointDefine>();
            }
            foreach (var sp in spawnPoints)
            {
                if (!DataManager.Instance.SpawnPoints[map.Value.ID].ContainsKey(sp.ID))
                {
                    DataManager.Instance.SpawnPoints[map.Value.ID][sp.ID] = new SpawnPointDefine();
                }
                SpawnPointDefine def = DataManager.Instance.SpawnPoints[map.Value.ID][sp.ID];
                def.ID        = sp.ID;
                def.MapID     = map.Value.ID;
                def.Position  = GameObjectTool.WorldToLogicN(sp.transform.position);
                def.Direction = GameObjectTool.WorldToLogicN(sp.transform.forward);
            }
        }
        DataManager.Instance.SaveSpawnPoints();
        sceneFile = "Assets/Levels/" + currentScene + ".unity";
        EditorSceneManager.OpenScene(sceneFile);

        EditorUtility.DisplayDialog("提示", "刷怪点导出完成", "确定");
    }