//Loads an existing local file private void LoadFile(string fileExtension, string localFilename) { //Creates a new AssetLoader instance using (var assetLoader = new AssetLoader()) { //Checks if the URL is a ZIP file if (fileExtension == ".zip") { #if TRILIB_USE_ZIP var localFilePath = FileUtils.GetFileDirectory(localFilename); //Gets the first asset loadable by TriLib on the folder var assetPath = GetReadableAssetPath(localFilePath); if (assetPath == null) { Debug.LogError("No TriLib readable file could be found on the given directory"); return; } //Loads the found asset _loadedGameObject = assetLoader.LoadFromFile(assetPath); #else throw new Exception("Please enable TriLib ZIP loading"); #endif } else { //If the URL is not a ZIP file, loads the file inside the folder _loadedGameObject = assetLoader.LoadFromFile(localFilename); } //Move camera away to fit the loaded object in view CameraExtensions.FitToBounds(Camera.main, _loadedGameObject.transform, 3f); } }
//Loads an existing local file private void LoadFile(string fileExtension, string localFilename) { GameObject loadedGameObject; //Creates a new AssetLoader instance using (var assetLoader = new AssetLoader()) { //Checks if the url is a ZIP file if (fileExtension == ".zip") { #if TRILIB_USE_ZIP var localFilePath = FileUtils.GetFileDirectory(localFilename); //Gets the first asset loadable by TriLib on the folder var assetPath = GetReadableAssetPath(localFilePath); if (assetPath == null) { Debug.LogError("No TriLib readable file could be found on the given directory"); return; } //Loads the found asset loadedGameObject = assetLoader.LoadFromFile(assetPath); #else throw new Exception("Please enable TriLib ZIP loading"); #endif } else { //If the url is not a ZIP file, loads the file inside the folder loadedGameObject = assetLoader.LoadFromFile(localFilename); } OnFileDownloaded(loadedGameObject); } }
private void loadItem(FileData item) { RuntimePreviewGenerator.OrthographicMode = true; RuntimePreviewGenerator.PreviewDirection = new Vector3(-1, -1, -1); using (var assetLoader = new TriLib.AssetLoader()) { try { var assetLoaderOptions = TriLib.AssetLoaderOptions.CreateInstance(); var wrapperGameObject = gameObject; //assetLoaderOptions.AutoPlayAnimations = true; //Use this for PC //GameObject loaded = assetLoader.LoadFromFile("C:/Users/xuhzc/Downloads/objects/stand.OBJ", assetLoaderOptions); //This can be a .fbx file or a .obj file //Use this for Android GameObject loaded = assetLoader.LoadFromFile(item.filePath, assetLoaderOptions, wrapperGameObject); //This can be a .fbx file or a .obj file loadedGameObject = Instantiate(loaded); loadedGameObject.transform.position = new Vector3(10000f, 10000f, 10000f); loadedGameObject.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f); BoxCollider c = loadedGameObject.AddComponent <BoxCollider>(); Debug.Log("================box====================="); c.size = new Vector3(50, 50, 50); c.center = new Vector3(0, 25, 0); Destroy(loaded); } catch (Exception e) { Debug.LogError(e.ToString()); } } addItem(loadedGameObject); }