Unity Community

Register or Sign In:

+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 41 to 60 of 69
  1. Administrator
    Location
    Blackpool, United Kingdom
    Posts
    8,593
    Welcome to the forum, tikod!

    You can fix the existing script by changing the line with the error to this:-
    Code:  
    1. return tSystemData.ToBuiltin(Hashtable) as Hashtable[];
    I'm wired to the world... that's how I... know... everything...


  2. Posts
    176

    Does .Count Work?

    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!


  3. Location
    Halifax, Canada
    Posts
    549
    All this to scrape off 1mb from the final file size?


  4. Posts
    44
    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?


  5. Location
    Zürich, Switzerland
    Posts
    25,088
    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


  6. Posts
    44
    Thanks dreamora


  7. Posts
    1

    Non Descriptive Compile Time Error

    I am attempting to utilize this XML Parser.

    I have a script to instantiate the XML Parser:

    Code:  
    1. var tWWW = new WWW("XML/xmlDataFiles.xml");
    2. yield tWWW;
    3. if (tWWW.error != null) {
    4.   // error, do something
    5. } else {
    6.     var tXMLParser : XMLParser = new XMLParser();
    7.     var tSimulationData : Hashtable[] = tXMLParser.ParseString(tWWW.data);
    8. }

    I made the minor adjustment to the parser:

    Code:  
    1. // Return the system data array as a builtin array
    2.         return tSystemData.ToBuiltin(Hashtable) as Hashtable[];

    And as a result I am getting a very non descriptive compile time 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.'.
    Any Suggestions? I am at a loss with this very useless error.
    Last edited by Lordships; 02-14-2011 at 11:18 AM.


  8. Posts
    3
    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:  
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. class XMLParser
    5. {
    6.     XMLParser() { }
    7.  
    8.     // -----
    9.     // Public Functions
    10.     // -----
    11.    
    12.     Hashtable[] ParseString(string aXMLString)
    13.     {
    14.         // Initialize the system data array
    15.         ArrayList tSystemData = new ArrayList();
    16.        
    17.         // Look for and remove the XML header tag
    18.         aXMLString = RemoveXMLHeaderTag(aXMLString);
    19.        
    20.         // Pull the configuration data
    21.         Hashtable tConfigData = GetElementAttributes(aXMLString, "system");
    22.         tSystemData.Add(tConfigData);
    23.        
    24.         // Look for and remove the wrapping system tag
    25.         aXMLString = RemoveSystemTag(aXMLString);
    26.        
    27.         // Process all body tags
    28.         Hashtable tNextBody = GetElementAttributes(aXMLString, "body");
    29.         while (tNextBody != null) {
    30.             // Add the body to the system data array
    31.             tSystemData.Add(tNextBody);
    32.            
    33.             // Strip the current body tag
    34.             aXMLString = RemoveBodyTag(aXMLString);
    35.            
    36.             // Look for the next body tag
    37.             tNextBody = GetElementAttributes(aXMLString, "body");
    38.         }
    39.        
    40.         // Return the system data array as a builtin array
    41.         return tSystemData.ToArray(typeof(Hashtable)) as Hashtable[];
    42.     }
    43.    
    44.    
    45.     // -----
    46.     // Private Functions
    47.     // -----
    48.    
    49.     private Hashtable GetElementAttributes(string aXMLString, string aElementName)
    50.     {
    51.         // Look for the next element with the provided name
    52.         int tElementStart = aXMLString.IndexOf("<" + aElementName + " ");
    53.         int tElementEnd = aXMLString.IndexOf(">");
    54.         if ((tElementStart > -1) && (tElementEnd > tElementStart)) {
    55.             // Initialize the attributes hashtable
    56.             Hashtable tAttributes = new Hashtable();
    57.            
    58.             // Pull the attribute string of the element tag
    59.             int tStripStart = tElementStart + 2 + aElementName.Length;
    60.             int tStripLength = tElementEnd - tStripStart;
    61.             string tAttributeString = aXMLString.Substring(tStripStart, tStripLength);
    62.            
    63.             // Strip any leading/trailing space characters
    64.             tAttributeString = tAttributeString.Trim();
    65.            
    66.             // Split into name/value chunks, and walk each chunk
    67.             string[] tChunks = tAttributeString.Split(" "[0]);
    68.             for (int i = 0; i < tChunks.Length; i++) {
    69.                 // Split the chunk into separate name and value strings
    70.                 string tChunkString = tChunks[i].ToString();
    71.                 if (tChunkString != "/") {
    72.                     string[] tSubStrings = tChunkString.Split("="[0]);
    73.                     string tNameString = tSubStrings[0].ToString();
    74.                     string tValueString = tSubStrings[1].ToString();
    75.                
    76.                     // Store the name/value (stripping the leading/trailing "s) pair information
    77.                     // in the attributes hashtable
    78.                     tAttributes[tNameString] = tValueString.Substring(1, (tValueString.Length - 2));
    79.                 }
    80.             }
    81.            
    82.             // Return the attributes hashtable
    83.             return tAttributes;
    84.         } else {
    85.  
    86.             // Return null
    87.             return null;
    88.         }
    89.     }
    90.    
    91.     private string RemoveBodyTag(string aXMLString)
    92.     {
    93.         // Look for a body tag
    94.         int tBodyStart = aXMLString.IndexOf("<body ");
    95.         int tBodyEnd = aXMLString.IndexOf("/>");
    96.         if ((tBodyStart > -1) && (tBodyEnd > tBodyStart)) {
    97.             // Strip the body tag from the string
    98.             int tStripStart = tBodyEnd + 2;
    99.             aXMLString = aXMLString.Substring(tStripStart);
    100.         }
    101.        
    102.         // Return the trimmed XML string
    103.         return aXMLString;
    104.        
    105.     }
    106.    
    107.     private string RemoveSystemTag(string aXMLString)
    108.     {
    109.         // Look for the system tag
    110.         int tSystemStart = aXMLString.IndexOf(">");
    111.         int tSystemEnd = aXMLString.IndexOf("</system>");
    112.         if ((tSystemStart > -1) && (tSystemEnd > tSystemStart)) {
    113.             // Strip the system start/end elements
    114.             int tStripStart = tSystemStart + 1;
    115.             int tStripLength = tSystemEnd - tStripStart;
    116.             aXMLString = aXMLString.Substring(tStripStart, tStripLength);
    117.         }
    118.  
    119.         // Return the trimmed XML string
    120.         return aXMLString;
    121.     }
    122.    
    123.     private string RemoveXMLHeaderTag(string aXMLString)
    124.     {
    125.         // Look for the XML header tag
    126.         int tHeaderStart = aXMLString.IndexOf("<?xml");
    127.         int tHeaderEnd = aXMLString.IndexOf("?>");
    128.         if ((tHeaderStart > -1) && (tHeaderEnd > tHeaderStart)) {
    129.             // Strip the XML header tag from the string
    130.             int tStripStart = tHeaderEnd + 2;
    131.             aXMLString = aXMLString.Substring(tStripStart);
    132.         }
    133.        
    134.         // Return the trimmed XML string
    135.         return aXMLString;
    136.     }
    137. }
    138.  
    139. internal class XMLTag
    140. {
    141.    public ArrayList Children = new ArrayList();
    142.    public string Name;
    143.    public Object Value;
    144.    
    145.    XMLTag(string aName, Object aValue)
    146.    {
    147.       Name = aName;
    148.       Value = aValue;
    149.    }
    150.  
    151. }


  9. Location
    Denmark
    Posts
    105
    Is there any way to generate an xml file from Unity. Just want to log some x,y,z positions and then plot them?


  10. Location
    Halifax, Canada
    Posts
    549
    Quote Originally Posted by Krodil View Post
    Is there any way to generate an xml file from Unity. Just want to log some x,y,z positions and then plot them?
    For starters

    For later


  11. Location
    Denmark
    Posts
    105
    Thank you. So no javascript solution?


  12. Location
    Halifax, Canada
    Posts
    549
    Quote Originally Posted by Krodil View Post
    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.


  13. Location
    Denmark
    Posts
    105
    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!


  14. Location
    Halifax, Canada
    Posts
    549
    Quote Originally Posted by Krodil View Post
    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.

    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.


  15. Location
    Denmark
    Posts
    105
    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.


  16. Location
    Halifax, Canada
    Posts
    549
    Quote Originally Posted by Krodil View Post
    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.


  17. Location
    Denmark
    Posts
    105
    Ok, thanx I will look into it as soon as possible.


  18. Location
    UK
    Posts
    29
    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.


  19. Location
    Halifax, Canada
    Posts
    549
    Quote Originally Posted by Anthony View Post
    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
    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.


  20. Location
    UK
    Posts
    29
    Well, thanks for the tidbit of advice I 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:  
    1. <Units>
    2.     <Unit Name="Trireme">
    3.         <TextID>TEXT_TRIREME</TextID>
    4.         <TextTooltipID>TEXT_TOOLTIP_TRIREME</TextTooltipID>
    5.         <Icon>Assets/Textures/UI/Icons/Trireme_256x256</Icon>
    6.         <LOS>60</LOS>
    7.         <Cost ResourceType="Wood">2000</Cost>
    8.         <Cost ResourceType="Metal">500</Cost>
    9.         <Salvage ResourceType="Wood">1000</Salvage>
    10.         <MaxSpeedKmph>9.0</MaxSpeedKmph>
    11.         <MaxSpeedKmph>13.9</MaxSpeedKmph>
    12.         <ArmorType></ArmorType>
    13.         <Unittype>Unit</Unittype>
    14.         <Unittype>Ship</Unittype>
    15.         <Unittype>Military</Unittype>
    16.         <UnitAIType>Combative</UnitAIType>
    17.         <Unittype>Targetable</Unittype>
    18.         <Unittype>LogicalTypeIsValidRamAttackTarget</Unittype>
    19.         <MovementType>Water</MovementType>
    20.         <ModelName>Assets/Models/Ships/Trireme.fbx</ModelName>
    21.         <InitialHitPionts>15000</InitialHitPionts>
    22.         <MaxHitPionts>20000</MaxHitPionts>
    23.         <Flag>Walkable</Flag>
    24.         <Flag>Burnable</Flag>
    25.         <Flag>Selectable</Flag>
    26.         <Flag>CollidesWithProjectiles</Flag>
    27.         <Flag>HideInFogOfWar</Flag>
    28.         <Flag>ShowOnMiniMap</Flag>
    29.         <Action Name="RamAttack">
    30.             <Parameter Name="RequiresTarget" Value="True"></Parameter>
    31.             <Parameter Name="Damage" Type="Crush" Value="10000"></Parameter>
    32.             <Parameter Name="Target" Type="IsValidRamAttackTarget"></Parameter>
    33.             <Parameter Name="MaxRange" Value="0.1"></Parameter>
    34.             <Parameter Name="MaximumSpeedMultiplier" Value="2.5"></Parameter>
    35.         </Action>
    36.     </Unit>    
    37. </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.