我正在开发一个需要引用.txt文件的HoloLens项目.我将这些文件存储在Unity的"Resources"文件夹中,并让它们完美地运行(通过Unity运行时):
string basePath = Application.dataPath;
string metadataPath = String.Format(@"\Resources\...\metadata.txt", list);
// If metadata exists, set title and introduction strings.
if (File.Exists(basePath + metadataPath))
{
using (StreamReader sr = new StreamReader(new FileStream(basePath + metadataPath, FileMode.Open)))
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在为HoloLens部署构建程序时,我能够运行代码,但它不起作用.没有任何资源出现,当检查HoloLens Visual Studio解决方案(通过在Unity中选择构建创建)时,我甚至没有看到资源或资源文件夹.我想知道我做错了什么,或者是否有一种特殊的方式来处理这些资源.
还有图像和声音文件......
foreach (string str in im)
{
spriteList.Add(Resources.Load<Sprite>(str));
}
Run Code Online (Sandbox Code Playgroud)
字符串'str'有效; 它与Unity完全一致.然而,再次,它在通过HoloLens运行时没有加载任何东西.
我不能让Unity Assetbundles在iOS版本中工作.
在Unity中,我构建了assetsbundles:
using UnityEditor;
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.iOS);
}
}
Run Code Online (Sandbox Code Playgroud)
它们在Unity中运行良好.使用它们
AssetBundle bundleLoadRequest = AssetBundle.LoadFromFile("file://" + Application.dataPath + "/AssetBundles/iOS/" + myassetbundlename.ToString());
Run Code Online (Sandbox Code Playgroud)
和/或
WWW wwww = WWW.LoadFromCacheOrDownload("file://" + Application.dataPath + "/AssetBundles/iOS/" + myassetbundlename.ToString(), 4);
Run Code Online (Sandbox Code Playgroud)
(如果没有"file://"前缀,捆绑包将无法在Unity或Xcode中工作)
我将项目构建到Xcode并在Xcode中运行它并收到此错误:
无法打开存档文件:/ Users/user/Documents/Workspaces/unityproject/Assets/AssetBundles/iOS/lchairanimations
它可能与某种方式设置正确的路径有关,但由于我之后将assetbundle文件夹复制到Xcode项目,问题仍然存在.
这种代码通常可以在PHP中运行,但由于C#中的范围要严格得多,所以并非如此.我不知道如何编写这段代码而不重复自己.
static double Cube()
{
Console.Write("Enter the side length of the cube: ");
try
{
double x = Convert.ToDouble(Console.Read());
return Math.Pow(x, 3);
}
catch (FormatException)
{
Console.WriteLine("Invalid input, please enter a number.");
Cube();
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)
..后来在Main():
switch (choice)
{
case 0:
return;
case 1:
double final = Cube();
break;
default:
Console.WriteLine("Please enter 0 or 1.");
Main();
break;
}
Console.WriteLine("The volume is: {0}", Convert.ToString(final));
Run Code Online (Sandbox Code Playgroud)
该Cube()
方法工作正常,但在我看来它很混乱(return 1
最后让编译器开心).但是出现了一个错误,称当前上下文中不存在名称"final".它无法找到最终结果.因此,我所看到的唯一方法是将这个Console.WriteLine
语句放在double final = Cube()之后.
我也尝试double …