Unity Community |
I'm wired to the world... that's how I... know... everything...
I'm having issues running the .Count function.
Running:
Debug.Log(tHash.Count);
Returns:
BCE0019: 'Count' is not a member of '(System.Collections.Hashtable)'.
Thanky!
All this to scrape off 1mb from the final file size?
Hi
I am building an application where i want to load data thro XML in the assets folder. When i build an standalone application, I am not getting the xml in the build. Its working fine in Editor. Any Suggestions?
it won't go through if you put it into the asset folder. those files used end in the assembly and would be used through textassets, those not used never get into the build.
you could use the Resources folder, or copy it along manually on builds while keeping it outsides the assets folder
Thanks dreamora
I am attempting to utilize this XML Parser.
I have a script to instantiate the XML Parser:
Code:
I made the minor adjustment to the parser:
Code:
And as a result I am getting a very non descriptive compile time error:
Any Suggestions? I am at a loss with this very useless error.Internal compiler error. See the console log for more information. output was:BCE0011: An error occurred during the execution of the step 'Boo.Lang.Compiler.Steps.EmitAssembly': 'Cannot cast from source type to destination type.'.
Last edited by Lordships; 02-14-2011 at 11:18 AM.
I just did a quick conversion of Tom's XMLParser to C#. I thought I saw someone else mention they did but I didn't see it. Either way, here it is.
*fair warning: this has no compilation warnings/errors in Unity, but I haven't run it because it is specific to Tom's XML schema. I repeat, this is untested (from the C# perspective.) I just wanted to give back to the Unity community that's given so much.
Code:
using UnityEngine; using System.Collections; class XMLParser { XMLParser() { } // ----- // Public Functions // ----- { // Initialize the system data array ArrayList tSystemData = new ArrayList(); // Look for and remove the XML header tag aXMLString = RemoveXMLHeaderTag(aXMLString); // Pull the configuration data // Look for and remove the wrapping system tag aXMLString = RemoveSystemTag(aXMLString); // Process all body tags while (tNextBody != null) { // Add the body to the system data array // Strip the current body tag aXMLString = RemoveBodyTag(aXMLString); // Look for the next body tag tNextBody = GetElementAttributes(aXMLString, "body"); } // Return the system data array as a builtin array } // ----- // Private Functions // ----- { // Look for the next element with the provided name int tElementStart = aXMLString.IndexOf("<" + aElementName + " "); int tElementEnd = aXMLString.IndexOf(">"); if ((tElementStart > -1) && (tElementEnd > tElementStart)) { // Initialize the attributes hashtable // Pull the attribute string of the element tag int tStripLength = tElementEnd - tStripStart; string tAttributeString = aXMLString.Substring(tStripStart, tStripLength); // Strip any leading/trailing space characters tAttributeString = tAttributeString.Trim(); // Split into name/value chunks, and walk each chunk string[] tChunks = tAttributeString.Split(" "[0]); // Split the chunk into separate name and value strings if (tChunkString != "/") { string[] tSubStrings = tChunkString.Split("="[0]); // Store the name/value (stripping the leading/trailing "s) pair information // in the attributes hashtable } } // Return the attributes hashtable return tAttributes; } else { // Return null return null; } } private string RemoveBodyTag(string aXMLString) { // Look for a body tag int tBodyStart = aXMLString.IndexOf("<body "); int tBodyEnd = aXMLString.IndexOf("/>"); if ((tBodyStart > -1) && (tBodyEnd > tBodyStart)) { // Strip the body tag from the string int tStripStart = tBodyEnd + 2; aXMLString = aXMLString.Substring(tStripStart); } // Return the trimmed XML string return aXMLString; } private string RemoveSystemTag(string aXMLString) { // Look for the system tag int tSystemStart = aXMLString.IndexOf(">"); int tSystemEnd = aXMLString.IndexOf("</system>"); if ((tSystemStart > -1) && (tSystemEnd > tSystemStart)) { // Strip the system start/end elements int tStripStart = tSystemStart + 1; int tStripLength = tSystemEnd - tStripStart; aXMLString = aXMLString.Substring(tStripStart, tStripLength); } // Return the trimmed XML string return aXMLString; } private string RemoveXMLHeaderTag(string aXMLString) { // Look for the XML header tag int tHeaderStart = aXMLString.IndexOf("<?xml"); int tHeaderEnd = aXMLString.IndexOf("?>"); if ((tHeaderStart > -1) && (tHeaderEnd > tHeaderStart)) { // Strip the XML header tag from the string int tStripStart = tHeaderEnd + 2; aXMLString = aXMLString.Substring(tStripStart); } // Return the trimmed XML string return aXMLString; } } internal class XMLTag { public ArrayList Children = new ArrayList(); public string Name; public Object Value; XMLTag(string aName, Object aValue) { Name = aName; Value = aValue; } }
Is there any way to generate an xml file from Unity. Just want to log some x,y,z positions and then plot them?
Thank you. So no javascript solution?
There probably is one, but I don't know of one offhand. If all you want to do is plot Vector3s it's actually probably better to "roll your own" method for converting them to CSV (comma separated values) which can be read by any graphing software. For a few Vector3's your output would be
1.100000,1.200000,1.300000
2.100000,2.200000,1.400000
etc.
Commas separate the columns and a return character separates the rows.
My idea is: Everytime a user i.e. clicks a button in a gui, this information is sent to a file(text/xml) for then later to be able do statistics on the values sent from unity to the file. Think of it as a logging tool, where I want to log all user behaviour in-game, and then afterwards present/plot 'how the user moved around' 'what buttons he clicked' and so fort.
Any pointers are welcomed!![]()
It's an interesting idea... the amount of effort it would take largely depends on the amount and diversity of information you want to save. From what you have said it seems like this will probably be a web-based application (given that you are tracking the user data, presumably they need to be online for that to be effective). If it is indeed meant to be a web-application you will have to find some way of saving the information to your server because you wont directly be able to save the .xml file. My suggestion would be to send the data to a MySQL database on your server. In this format it would make it very easy to do graphing and other data-analysis. You can send the data to your server using Unity's WWW class as POST data... in that case you will need to have some server-side solution (like some simple PHP scripts) for entering the info into the database.My idea is: Everytime a user i.e. clicks a button in a gui, this information is sent to a file(text/xml) for then later to be able do statistics on the values sent from unity to the file. Think of it as a logging tool, where I want to log all user behaviour in-game, and then afterwards present/plot 'how the user moved around' 'what buttons he clicked' and so fort.
Any pointers are welcomed!
It's of course a lot easier if this is a desktop application because you will be able to read/write files.
Last edited by Antitheory; 03-09-2011 at 10:52 AM.
It is supposed to be on a desktop!Its a project I run on uni with a touchscreen. The data collection of the users is to be translated with respect to usability, and user profiling.
Everytime a user clicks a button, this button will be tagged, so the info sent will be specific for that object. This will later be translated from xml through NumPy/SciPY. The user positions while interacting will be logged to show visual search parameters for the specific user.
So again. In JS on a desktop from a running application to a locally placed XML file.
I don't have experience serializing data to XML in Unityscript/Javascript... but I can only assume that it has come up before. You can mix C# and JS in your projects so if you wanted your serializing class to be in C#, while the rest of the project is in JS that should work fine. If you decide to do that then the two links I posted earlier will be very helpful.It is supposed to be on a desktop!Its a project I run on uni with a touchscreen. The data collection of the users is to be translated with respect to usability, and user profiling.
Everytime a user clicks a button, this button will be tagged, so the info sent will be specific for that object. This will later be translated from xml through NumPy/SciPY. The user positions while interacting will be logged to show visual search parameters for the specific user.
So again. In JS on a desktop from a running application to a locally placed XML file.
Ok, thanx I will look into it as soon as possible.
Interesting, I too am looking to find a way to impliment XMLs in unity. I've very surprised the engine doesn't support them Out-of-The-Box
I'm probably in way over my head at the moment, (that happens to me ALOT with things like this) since i know very little about writing code for parsers, but anyways, I've already started work on a model that i intend to put into unity at some stage (i'll probably put it in the island demo for starters) anyways, i've already written a basic, rough XML file for it, The type of game this model would usually be in is an RTS. I've had some experience modding RTS games that use XMLs extensively for most data landling (especially where ingame units are concerned), I followed the structure of XMLs from two games I have as an example when writing this one. I know it's nowhere near finished, but if you guys want to look over what i've written thus far, and tell me what you think, i'll post the code i've got.![]()
Nothing is true. Everything is permitted.
Games in pipeline:
"Target Sighted" FPS Archery game - Pre Alpha/Planning stage.
War of The Worlds re-make, Title undecided. Remake of the 1998 RTS game. Pre-Alpha/Planning stage.
There's a box now?
Anyhow it actually DOES support them out-of-the-box so to speak with the System.Xml namespace if you are using C#. It doesn't have it's own methods for converting XML into GameObjects because something like that would have be to specifically tailored to the game you are making.
If you have already started building XML files which represents units for an RTS game for example, that's great.... you can use them to populate data inside your game. However it is more useful I think to make the Class structure of your units in the game first, and then think about how you are going to serialize them (aka: convert them to xml) and vice-versa.
Well, thanks for the tidbit of adviceI do know one or two people who are apparently good with coding, so i suppose i could ask them to give me a hand when the time comes (I need to figure out Unity first), well, in case anyone is interested (or has ideas), here's the xml code for a Trireme I'm making in max.
Code:
<Units> <Unit Name="Trireme"> <TextID>TEXT_TRIREME</TextID> <TextTooltipID>TEXT_TOOLTIP_TRIREME</TextTooltipID> <Icon>Assets/Textures/UI/Icons/Trireme_256x256</Icon> <LOS>60</LOS> <Cost ResourceType="Wood">2000</Cost> <Cost ResourceType="Metal">500</Cost> <Salvage ResourceType="Wood">1000</Salvage> <MaxSpeedKmph>9.0</MaxSpeedKmph> <MaxSpeedKmph>13.9</MaxSpeedKmph> <ArmorType></ArmorType> <Unittype>Unit</Unittype> <Unittype>Ship</Unittype> <Unittype>Military</Unittype> <UnitAIType>Combative</UnitAIType> <Unittype>Targetable</Unittype> <Unittype>LogicalTypeIsValidRamAttackTarget</Unittype> <MovementType>Water</MovementType> <ModelName>Assets/Models/Ships/Trireme.fbx</ModelName> <InitialHitPionts>15000</InitialHitPionts> <MaxHitPionts>20000</MaxHitPionts> <Flag>Walkable</Flag> <Flag>Burnable</Flag> <Flag>Selectable</Flag> <Flag>CollidesWithProjectiles</Flag> <Flag>HideInFogOfWar</Flag> <Flag>ShowOnMiniMap</Flag> <Action Name="RamAttack"> <Parameter Name="RequiresTarget" Value="True"></Parameter> <Parameter Name="Damage" Type="Crush" Value="10000"></Parameter> <Parameter Name="Target" Type="IsValidRamAttackTarget"></Parameter> <Parameter Name="MaxRange" Value="0.1"></Parameter> <Parameter Name="MaximumSpeedMultiplier" Value="2.5"></Parameter> </Action> </Unit> </Units>
Like i said in my last post, this is a WIP xml, and is very rough, will most likely go through much refinement before it's usable, I just thought i'd throw an xml together and get a basic idea of what i want units in a game to have/be able to do. It's structured in a very similar way to the xml files that Age of Mythology uses. I haven't even written the string file yet, or even finished the model, or even started any game.![]()
Nothing is true. Everything is permitted.
Games in pipeline:
"Target Sighted" FPS Archery game - Pre Alpha/Planning stage.
War of The Worlds re-make, Title undecided. Remake of the 1998 RTS game. Pre-Alpha/Planning stage.