Beispiel #1
0
    public static void ExportMap(SceneMap map)
    {
        //string exportDir = Application.dataPath+"/../Export/Data";

        string exportDir = MapUtil.DataPath();

        exportDir += "MapData/";

        if (!Directory.Exists(exportDir))
        {
            Directory.CreateDirectory(exportDir);
        }

        string path = exportDir + "/MapUnit_" + map.sceneId + ".bytes";

        MapHelper.ExportMap(path, map);

        MapHelper.ExportMapNPCIDS(exportDir + "/MapUnit_" + map.sceneId + ".csv", map);

        Debug.LogFormat("导出场景{0}数据到{1}", map.sceneId, path);
    }
Beispiel #2
0
	public static void ExportEvents(SceneMap map,string path = null){
		int mapId = 10;
		if (map != null) {
			mapId = map.sceneId;
		}

		string exportDir = MapUtil.DataPath();
		exportDir += "MapData/";
		if (!Directory.Exists (exportDir)) {
			Directory.CreateDirectory (exportDir);
		} 

		if (path == null) {			
			path = exportDir +"/MapEvent_" + mapId + ".bytes";
		} 

		SceneMap mapRoot = FindSceneRoot ();
		GameObject triggerRoot = FindTriggerRoot();
		GameObject wallRoot = FindWallRoot ();
		GameObject eventRoot = FindEventRoot (); 
		GameObject itemRoot = FindItemRoot ();
		GameObject audioRoot = FindAudioRoot ();
		GameObject areaRoot = FindAreaRoot ();

		List<Example.MapWall> walls = new List<Example.MapWall> ();
		List<Example.MapEvent> events = new List<Example.MapEvent> ();
		List<Example.MapTrigger> triggers = new List<Example.MapTrigger> (); 
		List<Example.MapEntityEvent> entityEvents = new List<Example.MapEntityEvent> ();
		List<Example.MapItem> items = new List<Example.MapItem> ();
		List<Example.MapAudioSource> audios = new List<Example.MapAudioSource> ();
		List<Example.MapArea> areas = new List<Example.MapArea> ();

		if (mapRoot == null) {
			Debug.LogError ("没有场景配置,将场景预制拖到编辑器中,或者创建一个新的场景");
			return;
		}

		if (eventRoot != null) {
			var sceneEvents = eventRoot.GetComponentsInChildren<MapEvent> ();
			foreach (var sceneEvent in sceneEvents) { 
				var mapEvent = ExportMapEvent (events,sceneEvent);  
			}
		}

		if (wallRoot != null) {
			var sceneWalls = wallRoot.GetComponentsInChildren<MapWall> ();
			foreach (var sceneWall in sceneWalls) { 
				var wall = ExportMapWall (walls,sceneWall); 
				var eventTriggers = sceneWall.GetComponentsInChildren <MapEventTrigger>(); 
				var entityEvent = ExportMapEntityEvent (eventTriggers,wall.Id,Example.MapEntityEvent.Type.WALL);
				if (eventTriggers.Length > 0) {
					entityEvents.Add (entityEvent);
				}
			}
		}

		var sceneTriggers = triggerRoot.GetComponentsInChildren<SceneTrigger> ();
		foreach (var sceneTrigger in sceneTriggers) { 		
			var trigger = ExportMapTrigger (triggers,sceneTrigger);
			var eventTriggers = sceneTrigger.GetComponentsInChildren <MapEventTrigger>();
			foreach (var eventTrigger in eventTriggers) { 	 
				if (eventTrigger.eventType == MapEventTriggerType.TriggerIn) {
					trigger.InActions = ExportMapEventActions (eventTrigger.GetComponentsInChildren<MapEventAction>(),trigger.Id.ToString());
				}else if (eventTrigger.eventType == MapEventTriggerType.TriggerOut) {
					trigger.OutActions = ExportMapEventActions (eventTrigger.GetComponentsInChildren<MapEventAction>(),trigger.Id.ToString());
				}
			}
			 
		}

		foreach (var npc in mapRoot.npcList) {
			var eventTriggers = npc.GetComponentsInChildren <MapEventTrigger>(); 
			var entityEvent = ExportMapEntityEvent (eventTriggers,npc.objectId,Example.MapEntityEvent.Type.NPC);
			if (eventTriggers.Length > 0) {
				entityEvents.Add (entityEvent);
			}
		}

		if (itemRoot != null) { 
			var sceneItems = itemRoot.GetComponentsInChildren<SceneItem> ();
			foreach (var sceneItem in sceneItems) { 
				if (string.IsNullOrEmpty (sceneItem.itemId)) {
					//GameObject.DestroyImmediate (sceneItem.gameObject);
					Debug.LogErrorFormat("{0} not valid item object",MapEventHelper.GetGameObjectPath(sceneItem.transform));
					continue;
				}
				var item = ExportMapItem (items,sceneItem); 
				var eventTriggers = sceneItem.GetComponentsInChildren <MapEventTrigger>(); 
				var entityEvent = ExportMapEntityEvent (eventTriggers,item.Id,Example.MapEntityEvent.Type.ITEM);
				if (eventTriggers.Length > 0) {
					entityEvents.Add (entityEvent);
				}
			}
		}

		if (audioRoot != null) { 
			var audioSources = audioRoot.GetComponentsInChildren<MapAudioSource> ();
			foreach (var audioSource in audioSources) {  
				var audio = ExportMapAudioSource (audios,audioSource); 
			}
		}

		if (areaRoot != null) { 
			var mapAreas = areaRoot.GetComponentsInChildren<MapArea> ();
			foreach (var mapArea in mapAreas) {  
				var area = ExportMapArea (areas,mapArea); 
			}
		}
		 


		Example.MapEventData mapEventData = new Example.MapEventData ();
		mapEventData.Walls = walls;
		mapEventData.Events = events;
		mapEventData.Triggers = triggers;
		mapEventData.EntityEvents = entityEvents;
		mapEventData.Items = items;
		mapEventData.AudioSources = audios;
		mapEventData.Areas = areas;

		var bytes = Example.MapEventData.SerializeToBytes (mapEventData);
		FileStream fs = new FileStream (path, FileMode.Create);
		fs.Write (bytes,0,bytes.Length);
		fs.Close ();

		/*var prefab = PrefabUtility.GetPrefabParent (wallRoot); 
		PrefabUtility.ReplacePrefab (wallRoot,prefab);
		//prefab = PrefabUtility.GetPrefabParent (itemRoot); 
		//PrefabUtility.ReplacePrefab (itemRoot,prefab);
		prefab = PrefabUtility.GetPrefabParent (eventRoot); 
		PrefabUtility.ReplacePrefab (eventRoot,prefab);
		prefab = PrefabUtility.GetPrefabParent (triggerRoot); 
		PrefabUtility.ReplacePrefab (triggerRoot,prefab);*/

		Debug.LogFormat ("导出场景事件{0}数据到{1}",mapId,path);
	}
Beispiel #3
0
    static void GenerateSceneAreas()
    {
        if (mapBounds.size.sqrMagnitude < 0.1f)
        {
            GenerateSceneConfguration();
        }

        var settings = GameObject.FindObjectOfType <MapAreaSettings> ();

        float resolution = settings.resolution;
        int   width      = Mathf.CeilToInt(mapBounds.size.x * resolution);
        int   height     = Mathf.CeilToInt(mapBounds.size.z * resolution);
        var   texture    = new Texture2D(width, height, TextureFormat.ARGB4444, false);

        Example.MapTile[,] tiles = new Example.MapTile[height, width];

        EditorUtility.DisplayProgressBar("GenerateSceneAreas", "", 0);

        float      total = (width * height);
        var        upper = mapBounds.max + Vector3.up;
        var        lower = mapBounds.min;
        RaycastHit hit;
        Color      color;

        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                upper.x = x / resolution + mapBounds.center.x - mapBounds.size.x / 2;
                upper.z = y / resolution + mapBounds.center.z - mapBounds.size.z / 2;
                if (Physics.Raycast(upper, Vector3.down, out hit, 1000, LayerMask.GetMask("Surface")))
                {
                    var sceneExt = hit.collider.GetComponent <SceneExt> ();
                    if (sceneExt != null)
                    {
                        var areaType = sceneExt.areaType;
                        var t4m      = hit.collider.gameObject.GetComponent("T4MObjSC");
                        if (t4m != null)
                        {
                            areaType = GetT4MAreaColor(settings, sceneExt, hit.textureCoord);
                        }
                        color = GetAreaColor(areaType);
                        texture.SetPixel(x, y, color);

                        var tile = new Example.MapTile();
                        tile.Type    = (Example.MapArea.Type)areaType;
                        tiles [y, x] = tile;
                    }
                    else
                    {
                        texture.SetPixel(x, y, Color.clear);
                    }
                }
                else
                {
                    texture.SetPixel(x, y, Color.clear);
                }
            }
            EditorUtility.DisplayProgressBar("GenerateSceneAreas", "line " + (y + 1) + "/" + height, (float)y / height);
        }

        EditorUtility.ClearProgressBar();

        int sceneID = MapManager.current.sceneId;

        texture.Apply();
        var data = texture.EncodeToPNG();

        File.WriteAllBytes(MapUtil.DataPath() + "MapArea_" + sceneID + ".png", data);

        ExportMapArea(MapUtil.DataPath() + "MapArea_" + sceneID + ".bytes", tiles, settings, width, height);
    }