Log in or register to post comments

Saving the Image Target names as xml documents

August 8, 2012 - 9:44am #1

Hi :

I want to save the image target's name onto an xml file after being recognize or tracked by the devices camera ( this being save into the devices memory so i can access it later or send the file to a server )

Saving the Image Target names as xml documents

August 9, 2012 - 10:22am #8

Thank you David i wrote this code and it worked on my computer i wil test it on my phone see where it goes and after ill add the Datapath but for now it works thank you

 

import System;

import System.IO;

 

var fileName = "chips.txt";

 

class MyCoolObject extends MonoBehaviour {

    var myCoolInt : int;

    var myCoolFloat : float;

}

 

function Start() {

 

if (File.Exists(fileName)) {

 

Debug.Log(fileName+"already exists.");

return;

 

}

 

 

var sr = File.CreateText(fileName);

 

sr.WriteLine("Chips");

 

sr.Close();

 

 

}

 

Saving the Image Target names as xml documents

August 9, 2012 - 10:20am #7

wrong post haha

Saving the Image Target names as xml documents

August 8, 2012 - 5:44pm #6

Is there any way you could show me an example? .....

 

tnanks for everything 

Saving the Image Target names as xml documents

August 8, 2012 - 5:20pm #5

You can, though if you anticipate a lot of read / writes to the file, it would probably be a good idea to implement this in another script which inherits from MonoBehaviour and have it perform these operations within its update method - e.g. it would receive the trackable name and status from the event handler and then peform the file operation within its own update callback. That way the event handler isn't blocked w/ the file operation.

Saving the Image Target names as xml documents

August 8, 2012 - 5:05pm #4

ok sorry fot the hassle but will this be writtne inside the DefaultTrackerEventHandler?

Saving the Image Target names as xml documents

August 8, 2012 - 3:25pm #3

I'd recommend using Application.persistentDataPath+"/" as the base of your path. That will resolve to the appropriate directory across device contexts.

http://docs.unity3d.com/Documentation/ScriptReference/Application-persistentDataPath.html

Saving the Image Target names as xml documents

August 8, 2012 - 1:17pm #2

You can obtain the TrackableName by referencing its TrackableBehaviour. See the DefaultTrackableEventHandler script for an example.

Here are some examples of how to read and write files using System.IO - http://forum.unity3d.com/threads/8864-How-to-write-a-file

 

Log in or register to post comments