- Home /
Getting UART to work in 3.5
Hello. I'm trying to get uart to work in unity 3.5. There seems to be a problem importing Plugins. As it requires Unity3D 3.1, I'm pretty stuck. there is nothing that help document how it works, but basically, the problem is when loading plugins... here is the script :
using UnityEngine;
using System;
using System.IO;
using System.Runtime.InteropServices;
public class Plugins : MonoBehaviour {
public string[] PluginNames = {"VideoWrapper","TrackerWrapper"};
// Use this for initialization
void Awake () {
AddToPATH("", true);
for (int i=0; i<PluginNames.Length; i++)
AddToPATH(PluginNames[i], true);
}
void AddToPATH(String subpath, bool useProjectDir)
{
//.NET 1.1 has no string.Contains method or System.Environment class
#if !UNITY_IPHONE
string cwd = ApplicationDataPath();
Debug.Log("[CWD]"+cwd);
string dataDirName = "Plugins";
String dataDirectory = Path.Combine(cwd,dataDirName);
string separator;
string environVar;
if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
{
environVar = "PATH";
separator = ";";
}
else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
{
environVar = "DYLD_LIBRARY_PATH";
separator = ":";
}
else
{
Debug.Log("Not using native platform app");
return;
}
string oldPath = System.Environment.GetEnvironmentVariable(environVar);
Debug.Log("[Old Path]"+oldPath);
String pluginPath;
if (useProjectDir)
pluginPath = Path.Combine(dataDirectory,subpath);
else
pluginPath = subpath;
if(oldPath == null || !oldPath.Contains(pluginPath))
{
string newPath = oldPath + separator + pluginPath +"/";
Debug.Log("[New Path]"+newPath);
System.Environment.SetEnvironmentVariable(environVar,newPath);
System.Environment.SetEnvironmentVariable("PATH",newPath);
}else{
Debug.Log("Path already contains plugin dir");
}
#endif
}
public static string ApplicationDataPath()
{
#if UNITY_IPHONE
// Application.dataPath returns something like "/var/mobile/Applications/30B51836-D2DD-43AA-BCB4-9D4DADFED6A2/Data"
// Unity 1.6 dataPath returns something like "/var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data"
// Strip the "Data" part and add "Documents" instead
string path = Application.dataPath.Substring(0,Application.dataPath.Length-5);
if (path.Substring(path.Length-4) == ".app") //Unity 1.6
path = path.Substring(0, path.LastIndexOf('/'));
return path + "/Documents";
#else
return Application.dataPath;
#endif
}
public static string CreateFileFromAsset(string filename)
{
TextAsset textAsset = (TextAsset)UnityEngine.Resources.Load(filename);
string filepath = ApplicationDataPath() + "/" + filename;
BinaryWriter binWriter = new BinaryWriter(File.Open(filepath, FileMode.Create));
binWriter.Write(textAsset.bytes);
binWriter.Close();
return filepath;
}
}
Thanks for viewing... Any other AR based plugins. for desktop PC are welcome... this however is the only one I can find...
if you run this in unity- it crashes the whole app (unity that is), producing no error messages...
Hi naf456 i was resarching for any AR plugin for unity desktop aplication since 2 weeks. but it seems the only one is UART. all the other works for andoid or iOS platforms.
I m about to start working with UART to make a desktop application (unity 3.4) so if i have any information i will share it.
Answer by cap10subtext · Mar 20, 2012 at 10:08 PM
Are you able to get the plugins working in the editor? You need to add a folder to the Assets directory called Plugins and then add the UART files, add .cs files to the gameobjects in the scene and it seems to work just fine for me (using the Intersense 900 tracker). Only problem I'm having right now is getting VRPN to work properly when it's compiled in a OS X standalone application. Adding the plugin folder to the App contents directory begins to work but then VRPN fails to detect the tracker... Pretty sure it's not communicating with the libisense.dylib.
Hope this helps.
Your answer
Follow this Question
Related Questions
help me Create game AR 0 Answers
C# static class not in Plugins folder 1 Answer
Updating a texture from a plugin for Unity 3.5 and later 3 Answers
How can I access unity android res folder from jar? 1 Answer
Plugins don't play nicely 2 Answers