相关疑难解决方法(0)

在Unity中使用资源文件夹

我正在开发一个需要引用.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运行时没有加载任何东西.

c# resources assets unity-game-engine hololens

12
推荐指数
1
解决办法
1万
查看次数

Unity:在创建新类实例时为空

我陷入了相当愚蠢的境地:我正在制作泛型类的新实例,但它返回"怪异"的null.

    Rule rule2 = new Rule(); // initiate the class
    Debug.Log(rule2); //1st debug
    rule2.RuleSetup(r: "CaughtEnough", li: 0); //setting up the parameters
    Debug.Log(rule2.rule); //2nd debug
Run Code Online (Sandbox Code Playgroud)

第一次调试给了我

    null
    UnityEngine.Debug:Log(Object)
Run Code Online (Sandbox Code Playgroud)

同时设置参数工作,第二次调试给我

   CaughtEnough
   UnityEngine.Debug:Log(Object)
Run Code Online (Sandbox Code Playgroud)

这应该是在适当的类实例中.

它给我带来的一个(只是到目前为止)问题是,如果我在这个规则类实例中调用

   Invoke(rule, 0f);
Run Code Online (Sandbox Code Playgroud)

它给了我NullReferenceException错误.但同时具有实际功能

   CaughtEnough();
Run Code Online (Sandbox Code Playgroud)

工作正常,如预期的那样.

任何想法可能是问题的根源以及如何克服它?

UPD还会按照要求发布Rule类的设置部分,尽管它很简单

public class Rule : MonoBehaviour {

public string rule;

public int leftInt;
public Dictionary<string, int> leftDict;
public float countdown;

public int outcome;

public CatchManager catchMan;
public Net net;

// Use this for initialization
void Start () {
    RuleSetup();   
}

public void …
Run Code Online (Sandbox Code Playgroud)

c# null unity-game-engine

7
推荐指数
1
解决办法
6413
查看次数

标签 统计

c# ×2

unity-game-engine ×2

assets ×1

hololens ×1

null ×1

resources ×1