Always check that the API you are using is not in the UnityEditor
namespace. If it's just an Editor plugin, you can wrap it around UNITY_EDITOR
.
#if UNITY_EDITOR
using UnityEditor;
#endif
But it's not an Editor plugin so that wound't work.
So which is the best strategy that I should apply to load my models at
run time, outside the editor?
There are really two ways to load files in Unity
1.AssetBundles(Recommended)
The best way is to use AssetBundles. Create a folder in the Assets folder and na e name is "StreamingAssets". Create AssetBundles then put the AssetBundles there. You can use Unity's WWW
API with Application.streamingAssetsPath
as the path to load it.
public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
public string result = "";
IEnumerator Example() {
if (filePath.Contains("://"))
{
WWW www = new WWW(filePath);
yield return www;
result = www.text;
} else
result = System.IO.File.ReadAllText(filePath);
}
2.Resources folder
Create a folder named "Resources" then put all your files there. You can then load it with the Resources API. This post has more information about this method. I do think you should avoid using this method but it's really worth to be mentioned.
TextAsset txtAsset = (TextAsset)Resources.Load("textfile", typeof(TextAsset));
string tileFile = txtAsset.text;