当前位置: 首页>>代码示例>>C#>>正文


C# Entity.Remove方法代码示例

本文整理汇总了C#中Entity.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.Remove方法的具体用法?C# Entity.Remove怎么用?C# Entity.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Entity的用法示例。


在下文中一共展示了Entity.Remove方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ent42ToEntVMF

	// Turn a Nightfire entity into a Hammer one.
	public virtual Entity ent42ToEntVMF(Entity inEnt)
	{
		if(inEnt.Angles[0] != 0) {
			inEnt["angles"] = (-inEnt.Angles[0])+" "+inEnt.Angles[1]+" "+inEnt.Angles[2];
		}
		if (!inEnt["body"].Equals(""))
		{
			inEnt.renameAttribute("body", "SetBodyGroup");
		}
		if (inEnt["rendercolor"].Equals("0 0 0"))
		{
			inEnt["rendercolor"] = "255 255 255";
		}
		if (inEnt["angles"].Equals("0 -1 0"))
		{
			inEnt["angles"] = "-90 0 0";
		}
		try
		{
			if (inEnt["model"].Substring(inEnt["model"].Length - 4).ToUpper().Equals(".spz".ToUpper()))
			{
				inEnt["model"] = inEnt["model"].Substring(0, (inEnt["model"].Length - 4) - (0)) + ".spr";
			}
		}
		catch (System.ArgumentOutOfRangeException)
		{
			;
		}
		if (inEnt.attributeIs("classname", "light_spot"))
		{
			try
			{
				inEnt["pitch"] = ((double) (inEnt.Angles[0] + System.Double.Parse(inEnt["pitch"]))).ToString();
			}
			catch (System.FormatException e)
			{
				inEnt["pitch"] = ((double) inEnt.Angles[0]).ToString();
			}
			try
			{
				if (System.Double.Parse(inEnt["_cone"]) > 90.0)
				{
					inEnt["_cone"] = "90";
				}
				else
				{
					if (System.Double.Parse(inEnt["_cone"]) < 0.0)
					{
						inEnt["_cone"] = "0";
					}
				}
			}
			catch (System.FormatException e)
			{
				;
			}
			try
			{
				if (System.Double.Parse(inEnt["_cone2"]) > 90.0)
				{
					inEnt["_cone2"] = "90";
				}
				else
				{
					if (System.Double.Parse(inEnt["_cone2"]) < 0.0)
					{
						inEnt["_cone2"] = "0";
					}
				}
			}
			catch (System.FormatException e)
			{
				;
			}
			inEnt.renameAttribute("_cone", "_inner_cone");
			inEnt.renameAttribute("_cone2", "_cone");
		}
		else
		{
			if (inEnt.attributeIs("classname", "func_wall"))
			{
				if (inEnt["rendermode"].Equals("0"))
				{
					inEnt["classname"] = "func_detail";
					for (int i = 0; i < inEnt.Brushes.Count; i++)
					{
						MAPBrush currentBrush = inEnt.Brushes[i];
						for (int j = 0; j < currentBrush.NumSides; j++)
						{
							MAPBrushSide currentSide = currentBrush[j];
							if (currentSide.Texture.Equals("special/TRIGGER", StringComparison.InvariantCultureIgnoreCase))
							{
								currentSide.Texture = "TOOLS/TOOLSHINT"; // Hint is the only thing that still works that doesn't collide with the player
							}
						}
					}
					inEnt.Remove("rendermode");
				}
				else
//.........这里部分代码省略.........
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:101,代码来源:VMFWriter.cs

示例2: entityToByteArray

	// -entityToByteArray()
	// Converts the entity and its brushes into byte arrays rather than Strings,
	// which can then be written to a file much faster. Concatenating Strings is
	// a costly operation, especially when hundreds of thousands of Strings are
	// in play. This is one of two parts to writing a file quickly. The second
	// part is to call the FileOutputStream.write() method only once, with a
	// gigantic array, rather than several times with many small arrays. File I/O
	// from a hard drive is another costly operation, best done by handling
	// massive amounts of data in one go, rather than tiny amounts of data thousands
	// of times.
	private byte[] entityToByteArray(Entity inEnt) {
		inEnt["id"] = ((System.Int32) nextID++).ToString();
		byte[] outputData;
		Vector3D origin = Vector3D.ZERO;
		if (inEnt.BrushBased) {
			inEnt.Remove("model");
		}
		if (inEnt.Brushes.Count > 0)
		{
			origin = inEnt.Origin;
		}
		string temp;
		if(inEnt["classname"].Equals("worldspawn", StringComparison.InvariantCultureIgnoreCase)) {
			temp = "world"+(char)0x0D+(char)0x0A+"{"+(char)0x0D+(char)0x0A;
		} else {
			temp = "entity"+(char)0x0D+(char)0x0A+"{"+(char)0x0D+(char)0x0A;
		}
		int len = temp.Length+3; // Closing brace, newline
		// Get the lengths of all attributes together
		foreach (string key in inEnt.Attributes.Keys) {
			len += key.Length + inEnt[key].Length + 8; // Four quotes, a space, a tab and a newline
		}
		if (inEnt.Connections.Count > 0) {
			len += 22; // tab, "connections", newline, tab, "{", newline, tab, "}", newline
			foreach (Tuple<string, string, string, string, double, int, string, Tuple<string>> connection in inEnt.Connections) {
				if(connection.Item7 == "" && connection.Rest.Item1 == "") {
					len += connection.Item1.Length + connection.Item2.Length + connection.Item3.Length + connection.Item4.Length + connection.Item5.ToString().Length + connection.Item6.ToString().Length + 13; // Two tabs, four quotes, space, four commas, newline
				} else {
					len += connection.Item1.Length + connection.Item2.Length + connection.Item3.Length + connection.Item4.Length + connection.Item5.ToString().Length + connection.Item6.ToString().Length + connection.Item7.Length + connection.Rest.Item1.Length + 15; // Two tabs, four quotes, space, six commas, newline
				}
			}
		}
		outputData = new byte[len];
		int offset = 0;
		for (int i = 0; i < temp.Length; i++) {
			outputData[offset++] = (byte)temp[i];
		}
		foreach (string key in inEnt.Attributes.Keys) {
			outputData[offset++] = (byte) (0x09); // 1
			outputData[offset++] = (byte)'\"'; // 2
			for (int j = 0; j < key.Length; j++) {
				// Then for each byte in the attribute
				outputData[j + offset] = (byte) key[j]; // add it to the output array
			}
			offset += key.Length;
			outputData[offset++] = (byte)'\"'; // 3
			outputData[offset++] = (byte)' '; // 4
			outputData[offset++] = (byte)'\"'; // 5
			for (int j = 0; j < inEnt.Attributes[key].Length; j++) {
				// Then for each byte in the attribute
				outputData[j + offset] = (byte) inEnt.Attributes[key][j]; // add it to the output array
			}
			offset += inEnt.Attributes[key].Length;
			outputData[offset++] = (byte)'\"'; // 6
			outputData[offset++] = (byte)0x0D; // 7
			outputData[offset++] = (byte)0x0A; // 8
		}
		if (inEnt.Connections.Count > 0) {
			outputData[offset++] = (byte)0x09; // tab 1
			outputData[offset++] = (byte)'c'; // 2
			outputData[offset++] = (byte)'o'; // 3
			outputData[offset++] = (byte)'n'; // 4
			outputData[offset++] = (byte)'n'; // 5
			outputData[offset++] = (byte)'e'; // 6
			outputData[offset++] = (byte)'c'; // 7
			outputData[offset++] = (byte)'t'; // 8
			outputData[offset++] = (byte)'i'; // 9
			outputData[offset++] = (byte)'o'; // 10
			outputData[offset++] = (byte)'n'; // 11
			outputData[offset++] = (byte)'s'; // 12
			outputData[offset++] = (byte)0x0D; // 13
			outputData[offset++] = (byte)0x0A; // newline 14
			outputData[offset++] = (byte)0x09; //tab 15
			outputData[offset++] = (byte)'{'; // 16
			outputData[offset++] = (byte)0x0D; // 17
			outputData[offset++] = (byte)0x0A; // newline 18
			foreach (Tuple<string, string, string, string, double, int, string, Tuple<string>> connection in inEnt.Connections) {
				string str = "";
				if(connection.Item7 == "" && connection.Rest.Item1 == "") {
					str = ""+(char)0x09 + (char)0x09 + "\""+connection.Item1+"\" \""+connection.Item2+","+connection.Item3+","+connection.Item4+","+connection.Item5.ToString()+","+connection.Item6.ToString()+"\""+(char)0x0D+(char)0x0A;
				} else {
					str = ""+(char)0x09 + (char)0x09 + "\""+connection.Item1+"\" \""+connection.Item2+","+connection.Item3+","+connection.Item4+","+connection.Item5.ToString()+","+connection.Item6.ToString()+","+connection.Item7+","+connection.Rest.Item1+"\""+(char)0x0D+(char)0x0A;
				}
				for (int j = 0; j < str.Length; j++) {
					// Then for each byte in the string
					outputData[offset++] = (byte)str[j]; // add it to the output array
				}
			}
			outputData[offset++] = (byte)0x09; // tab 19
			outputData[offset++] = (byte)'}'; // 20
//.........这里部分代码省略.........
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:101,代码来源:VMFWriter.cs

示例3: ent38ToEntVMF

	// Turn a Q2 entity into a Hammer one. This won't magically fix every single
	// thing to work in Gearcraft, for example the Nightfire engine had no support
	// for area portals. But it should save map porters some time, especially when
	// it comes to the Capture The Flag mod.
	public virtual Entity ent38ToEntVMF(Entity inEnt)
	{
		if (!inEnt["angle"].Equals(""))
		{
			inEnt["angles"] = "0 " + inEnt["angle"] + " 0";
			inEnt.Remove("angle");
		}
		if (inEnt.attributeIs("classname", "func_wall"))
		{
			inEnt["classname"] = "func_brush";
			if (!inEnt["targetname"].Equals(""))
			{
				// Really this should depend on spawnflag 2 or 4
				inEnt["solidity"] = "0"; // TODO: Make sure the attribute is actually "solidity"
			}
			else
			{
				// 2 I believe is "Start enabled" and 4 is "toggleable", or the other way around. Not sure. Could use an OR.
				inEnt["solidity"] = "2";
			}
		}
		else
		{
			if (inEnt.attributeIs("classname", "info_player_start"))
			{
				Vector3D origin = inEnt.Origin;
				inEnt["origin"] = origin.X + " " + origin.Y + " " + (origin.Z + 18);
			}
			else
			{
				if (inEnt.attributeIs("classname", "info_player_deathmatch"))
				{
					Vector3D origin = inEnt.Origin;
					inEnt["origin"] = origin.X + " " + origin.Y + " " + (origin.Z + 18);
				}
				else
				{
					if (inEnt.attributeIs("classname", "light"))
					{
						string color = inEnt["_color"];
						string intensity = inEnt["light"];
						string[] nums = color.Split(' ');
						double[] lightNumbers = new double[4];
						for (int j = 0; j < 3 && j < nums.Length; j++)
						{
							try
							{
								lightNumbers[j] = Double.Parse(nums[j]);
								lightNumbers[j] *= 255; // Quake 2's numbers are from 0 to 1, Nightfire are from 0 to 255
							}
							catch (System.FormatException)
							{
								;
							}
						}
						try
						{
							lightNumbers[s] = System.Double.Parse(intensity) / 2; // Quake 2's light intensity is waaaaaay too bright
						}
						catch (System.FormatException)
						{
							;
						}
						inEnt.Remove("_color");
						inEnt.Remove("light");
						inEnt["_light"] = lightNumbers[r] + " " + lightNumbers[g] + " " + lightNumbers[b] + " " + lightNumbers[s];
					}
					else
					{
						if (inEnt.attributeIs("classname", "misc_teleporter"))
						{
							Vector3D origin = inEnt.Origin;
							Vector3D mins = new Vector3D(origin.X - 24, origin.Y - 24, origin.Z - 24);
							Vector3D maxs = new Vector3D(origin.X + 24, origin.Y + 24, origin.Z + 48);
							inEnt.Brushes.Add(MAPBrush.createBrush(mins, maxs, "tools/toolstrigger"));
							inEnt.Remove("origin");
							inEnt["classname"] = "trigger_teleport";
						}
						else
						{
							if (inEnt.attributeIs("classname", "misc_teleporter_dest"))
							{
								inEnt["classname"] = "info_target";
							}
						}
					}
				}
			}
		}
		return inEnt;
	}
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:95,代码来源:VMFWriter.cs

示例4: parseMultimanager

	// Multimanagers are also a special case. There are none in Source. Instead, I
	// need to add EVERY targetted entity in a multimanager to the original trigger
	// entity as an output with the specified delay. Things get even more complicated
	// when a multi_manager fires another multi_manager. In this case, this method will
	// recurse on itself until all the complexity is worked out.
	// One potential problem is if two multi_managers continuously call each other, this
	// method will recurse infinitely until there is a stack overflow. This might happen
	// when there is some sort of cycle going on in the map and multi_managers call each
	// other recursively to run the cycle with a delay. I solve this with an atrificial
	// limit of 8 multimanager recursions.
	// TODO: It would be better to detect this problem when it happens.
	// TODO: Instead of adding more attributes, parse into connections.
	private Entity parseMultimanager(Entity inEnt)
	{
		mmStackLength++;
		Entity dummy = new Entity(inEnt);
		dummy.Remove("classname");
		dummy.Remove("origin");
		dummy.Remove("angles");
		dummy.Remove("targetname");
		List<string> delete = new List<string>();
		foreach(string st in dummy.Attributes.Keys) {
			string target = st;
			double delay = 0.0;
			try {
				delay = Double.Parse(dummy[st]);
			} catch {
			}
			for (int j = target.Length - 1; j >= 0; j--)
			{
				if (target[j] == '#')
				{
					target = target.Substring(0, (j) - (0));
					//dummy.renameAttribute(st, target);
					break;
				}
			}
			Entity[] targets = getTargets(target);
			delete.Add(st);
			for (int j = 0; j < targets.Length; j++)
			{
				if (inEnt.attributeIs("classname", "multi_kill_manager"))
				{
					if (targets.Length > 1)
					{
						dummy.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>("condition", target + j, "Kill", "", delay, -1, "", new Tuple<string>("")));
					}
					else
					{
						dummy.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>("condition", target, "Kill", "", delay, -1, "", new Tuple<string>("")));
					}
				}
				else
				{
					if (targets[j].attributeIs("classname", "multi_manager") || targets[j].attributeIs("classname", "multi_kill_manager"))
					{
						if (mmStackLength <= Settings.MMStackSize)
						{
							Entity mm = parseMultimanager(targets[j]);
							foreach (Tuple<string, string, string, string, double, int, string, Tuple<string>> connection in mm.Connections) {
								dummy.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>(connection.Item1, connection.Item2, connection.Item3, connection.Item4, connection.Item5 + delay, connection.Item6, connection.Item7, connection.Rest));
							}
						}
						else
						{
							DecompilerThread.OnMessage(this, "WARNING: Multimanager stack overflow on entity " + inEnt["targetname"] + " calling " + targets[j]["targetname"] + "!");
							DecompilerThread.OnMessage(this, "This is probably because of multi_managers repeatedly calling eachother. You can increase multimanager stack size in debug options.");
						}
					}
					else
					{
						if (targets.Length > 1)
						{
							//for(int k = 0; k < targets.Length; k++) {
								string outputAction = targets[j].onFire();
								if (inEnt.attributeIs("triggerstate", "0"))
								{
									outputAction = targets[j].onDisable();
								}
								else
								{
									if (inEnt.attributeIs("triggerstate", "1"))
									{
										outputAction = targets[j].onEnable();
									}
								}
								dummy.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>("condition", target+j, outputAction, "", delay, -1, "", new Tuple<string>("")));
							//}
						}
						else if(targets.Length == 1) {
							string outputAction = targets[0].onFire();
							if (inEnt.attributeIs("triggerstate", "0"))
							{
								outputAction = targets[0].onDisable();
							}
							else
							{
								if (inEnt.attributeIs("triggerstate", "1"))
								{
									outputAction = targets[0].onEnable();
//.........这里部分代码省略.........
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:101,代码来源:VMFWriter.cs

示例5: parseEntityIO

	// Turn a triggering entity (like a func_button or trigger_multiple) into a Source
	// engine trigger using entity I/O. There's a few complications to this: There's
	// no generic output which always acts like the triggers in other engines, and there's
	// no "Fire" input. I try to figure out which ones are best based on their classnames
	// but it's not 100% foolproof, and I have to add a case for every specific class.
	public virtual Entity parseEntityIO(Entity inEnt) {
		if (!(inEnt["target"]=="")) {
			double delay = 0.0;
			try {
				delay = Double.Parse(inEnt["delay"]);
			} catch (System.FormatException) { ; }
			if (!inEnt["target"].Equals("")) {
				Entity[] targets = getTargets(inEnt["target"]);
				for (int i = 0; i < targets.Length; i++) {
					if (targets[i].attributeIs("classname", "multi_manager") || targets[i].attributeIs("classname", "multi_kill_manager")) {
						Entity mm = parseMultimanager(targets[i]);
						//for (int j = 0; j < mm.Attributes.Count; j++) {
						foreach (Tuple<string, string, string, string, double, int, string, Tuple<string>> connection in mm.Connections) {
							if (inEnt.attributeIs("classname", "logic_relay") && inEnt.Attributes.ContainsKey("delay")) {
								inEnt.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>("OnTrigger", connection.Item2, connection.Item3, connection.Item4, connection.Item5 + delay, connection.Item6, "", new Tuple<string>("")));
							} else {
								inEnt.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>(inEnt.fireAction(), connection.Item2, connection.Item3, connection.Item4, connection.Item5, connection.Item6, "", new Tuple<string>("")));
							}
						}
					} else {
						string outputAction = targets[i].onFire();
						if (inEnt.attributeIs("triggerstate", "0")) {
							outputAction = targets[i].onDisable();
						} else {
							if (inEnt.attributeIs("triggerstate", "1")) {
								outputAction = targets[i].onEnable();
							}
						}
						inEnt.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>(inEnt.fireAction(), targets[i]["targetname"], outputAction, "", delay, -1, "", new Tuple<string>("")));
					}
				}
			}
			if (!inEnt["killtarget"].Equals(""))
			{
				inEnt.Connections.Add(new Tuple<string, string, string, string, double, int, string, Tuple<string>>(inEnt.fireAction(), inEnt["killtarget"], "Kill", "", delay, -1, "", new Tuple<string>("")));
			}
			inEnt.Remove("target");
			inEnt.Remove("killtarget");
			inEnt.Remove("triggerstate");
			inEnt.Remove("delay");
		}
		return inEnt;
	}
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:48,代码来源:VMFWriter.cs

示例6: entityToByteArray

	// -entityToByteArray()
	// Converts the entity and its brushes into byte arrays rather than Strings,
	// which can then be written to a file much faster. Concatenating Strings is
	// a costly operation, especially when hundreds of thousands of Strings are
	// in play. This is one of two parts to writing a file quickly. The second
	// part is to call the FileOutputStream.write() method only once, with a
	// gigantic array, rather than several times with many small arrays. File I/O
	// from a hard drive is another costly operation, best done by handling
	// massive amounts of data in one go, rather than tiny amounts of data thousands
	// of times.
	private byte[] entityToByteArray(Entity inEnt) {
		byte[] output;
		Vector3D origin = Vector3D.ZERO;
		if (inEnt.BrushBased) {
			inEnt.Remove("model");
		}
		if (inEnt.Brushes.Count > 0) {
			origin = inEnt.Origin;
		}
		string temp = "// entity "+currentEntity+(char)0x0A+"{"+(char)0x0A;
		int len = temp.Length + 2; // Closing brace and a newline
		// Get the lengths of all attributes together
		foreach (string key in inEnt.Attributes.Keys) {
			len += key.Length + inEnt.Attributes[key].Length + 6; // Four quotes, a space and a newline
		}
		output = new byte[len];
		int offset = 0;
		for(int i=0;i<temp.Length;i++) {
			output[offset++] = (byte)temp[i];
		}
		foreach (string key in inEnt.Attributes.Keys) {
			// For each attribute
			output[offset++] = (byte)'\"'; // 1
			for (int j = 0; j < key.Length; j++) {
				// Then for each byte in the attribute
				output[j + offset] = (byte) key[j]; // add it to the output array
			}
			offset += key.Length;
			output[offset++] = (byte)'\"'; // 2
			output[offset++] = (byte)' '; // 3
			output[offset++] = (byte)'\"'; // 4
			for (int j = 0; j < inEnt.Attributes[key].Length; j++) {
				// Then for each byte in the attribute
				output[j + offset] = (byte) inEnt.Attributes[key][j]; // add it to the output array
			}
			offset += inEnt.Attributes[key].Length;
			output[offset++] = (byte)'\"'; // 5
			output[offset++] = (byte)0x0D; // 6
		}
		int brushArraySize = 0;
		byte[][] brushes = new byte[inEnt.Brushes.Count][];
		for (int j = 0; j < inEnt.Brushes.Count; j++) {
			// For each brush in the entity
			// models with origin brushes need to be offset into their in-use position
			inEnt.Brushes[j].translate(origin);
			brushes[j] = brushToByteArray(inEnt.Brushes[j], j);
			brushArraySize += brushes[j].Length;
		}
		int brushoffset = 0;
		byte[] brushArray = new byte[brushArraySize];
		for (int j = 0; j < inEnt.Brushes.Count; j++) {
			// For each brush in the entity
			for (int k = 0; k < brushes[j].Length; k++) {
				brushArray[brushoffset + k] = brushes[j][k];
			}
			brushoffset += brushes[j].Length;
		}
		if (brushArray.Length != 0) {
			len += brushArray.Length;
			byte[] newOut = new byte[len];
			for (int j = 0; j < output.Length; j++) {
				newOut[j] = output[j];
			}
			for (int j = 0; j < brushArray.Length; j++) {
				newOut[j + output.Length - 2] = brushArray[j];
			}
			offset += brushArray.Length;
			output = newOut;
		}
		output[offset++] = (byte)'}';
		output[offset++] = (byte)0x0A;
		return output;
	}
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:83,代码来源:DoomEditMapWriter.cs

示例7: ent42ToEntRad

	// TODO: Polish these up.
	public virtual Entity ent42ToEntRad(Entity inEnt) {
		if (inEnt["classname"].Equals("func_door_rotating", StringComparison.InvariantCultureIgnoreCase)) {
			inEnt["classname"] = "func_rotatingdoor";
		} else {
			if (inEnt["classname"].Equals("worldspawn", StringComparison.InvariantCultureIgnoreCase)) {
				inEnt.Remove("mapversion");
			}
		}
		return inEnt;
	}
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:11,代码来源:MOHRadiantMAPWriter.cs

示例8: entityToByteArray

	// -entityToByteArray()
	// Converts the entity and its brushes into byte arrays rather than Strings,
	// which can then be written to a file much faster. Concatenating Strings is
	// a costly operation, especially when hundreds of thousands of Strings are
	// in play. This is one of two parts to writing a file quickly. The second
	// part is to call the FileOutputStream.write() method only once, with a
	// gigantic array, rather than several times with many small arrays. File I/O
	// from a hard drive is another costly operation, best done by handling
	// massive amounts of data in one go, rather than tiny amounts of data thousands
	// of times.
	private byte[] entityToByteArray(Entity inputData, int num) {
		byte[] outputData;
		Vector3D origin;
		if (inputData.BrushBased) {
			origin = inputData.Origin;
			inputData.Remove("origin");
			inputData.Remove("model");
			if (origin[0] != 0 || origin[1] != 0 || origin[2] != 0)
			{
				// If this entity uses the "origin" attribute
				MAPBrush newOriginBrush = MAPBrush.createBrush(new Vector3D(- Settings.originBrushSize, - Settings.originBrushSize, - Settings.originBrushSize), new Vector3D(Settings.originBrushSize, Settings.originBrushSize, Settings.originBrushSize), "special/origin");
				inputData.Brushes.Add(newOriginBrush);
			}
		} else {
			origin = Vector3D.ZERO;
		}
		string temp = "";
		if(!inputData["classname"].Equals("worldspawn", StringComparison.InvariantCultureIgnoreCase)) {
			temp += "// entity "+num+(char)0x0D+(char)0x0A;
		}
		temp += "{";
		int len = temp.Length+5;
		// Get the lengths of all attributes together
		foreach (string key in inputData.Attributes.Keys) {
			len += key.Length + inputData[key].Length + 7; // Four quotes, a space and a newline
		}
		outputData = new byte[len];
		int offset = 0;
		for (int i = 0; i < temp.Length; i++) {
			outputData[offset++] = (byte)temp[i];
		}
		outputData[offset++] = (byte)0x0D;
		outputData[offset++] = (byte)0x0A;
		foreach (string key in inputData.Attributes.Keys) {
			// For each attribute
			outputData[offset++] = (byte)'\"'; // 1
			for (int j = 0; j < key.Length; j++) {
				// Then for each byte in the attribute
				outputData[offset++] = (byte) key[j]; // add it to the output array
			}
			outputData[offset++] = (byte)'\"'; // 2
			outputData[offset++] = (byte)' '; // 3
			outputData[offset++] = (byte)'\"'; // 4
			for (int j = 0; j < inputData.Attributes[key].Length; j++) {
				// Then for each byte in the attribute
				outputData[offset++] = (byte) inputData.Attributes[key][j]; // add it to the output array
			}
			outputData[offset++] = (byte)'\"'; // 5
			outputData[offset++] = (byte)0x0D; // 6
			outputData[offset++] = (byte)0x0A; // 7
		}
		int brushArraySize = 0;
		byte[][] brushes = new byte[inputData.Brushes.Count][];
		for (int j = 0; j < inputData.Brushes.Count; j++)
		{
			brushes[j] = brushToByteArray(inputData.Brushes[j], j);
			brushArraySize += brushes[j].Length;
		}
		int brushoffset = 0;
		byte[] brushArray = new byte[brushArraySize];
		for (int j = 0; j < inputData.Brushes.Count; j++) {
			// For each brush in the entity
			for (int k = 0; k < brushes[j].Length; k++)
			{
				brushArray[brushoffset + k] = brushes[j][k];
			}
			brushoffset += brushes[j].Length;
		}
		if (brushArray.Length != 0)
		{
			len += brushArray.Length;
			byte[] newOut = new byte[len];
			for (int j = 0; j < outputData.Length; j++)
			{
				newOut[j] = outputData[j];
			}
			for (int j = 0; j < brushArray.Length; j++)
			{
				newOut[j + outputData.Length - 3] = brushArray[j];
			}
			offset += brushArray.Length;
			outputData = newOut;
		}
		outputData[offset++] = (byte)'}';
		outputData[offset++] = (byte)0x0D;
		outputData[offset++] = (byte)0x0A;
		return outputData;
	}
开发者ID:Avatarchik,项目名称:bsp-decompiler-1,代码行数:98,代码来源:MOHRadiantMAPWriter.cs


注:本文中的Entity.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。