【问题标题】:Use non monoBehaviour class in unity统一使用非 monoBehaviour 类
【发布时间】:2015-12-28 01:37:16
【问题描述】:

我遇到了一个错误,或者至少是我没有真正理解的东西。

我正在尝试在我的统一项目中使用 sqlite 数据库。

这是我得到的错误:

DatabaseManager 类是 MonoBehaviour 类。

这是它的样子:

using UnityEngine;
using System.Collections;

public class DatabaseManager : MonoBehaviour
{
SQLiteDatabase sqlDB;

void Awake() 
{
    string dbPath = System.IO.Path.Combine (Application.persistentDataPath, "game.db");
    var dbTemplatePath = System.IO.Path.Combine(Application.streamingAssetsPath, "default.db");

    if (!System.IO.File.Exists(dbPath)) {
        // game database does not exists, copy default db as template
        if (Application.platform == RuntimePlatform.Android)
        {
            // Must use WWW for streaming asset
            WWW reader = new WWW(dbTemplatePath);
            while ( !reader.isDone) {}
            System.IO.File.WriteAllBytes(dbPath, reader.bytes);
        } else {
            System.IO.File.Copy(dbTemplatePath, dbPath, true);
        }       
    }
    sqlDB = new SqliteDatabase(dbPath);
}
}

问题是,如果我做对了,我将脚本放在资产文件夹下这一事实应该足以让它们一起工作并识别其他文件中的类。现在问题很简单,我的 DatabaseManager 类无法识别在 SqliteDatabase.cs 中实现的 SqliteDatabase 类

有人遇到过这个问题,还是我错过了如何在 MonoBehaviour 脚本中引用非 MonoBehaviour 脚本?

编辑:

我用过这个教程:Here

谢谢!

【问题讨论】:

  • “DatabaseManager 类无法识别 SqliteDatabase.cs 中实现的 SqliteDatabase 类”,错误信息是什么?最简单的尝试可能是将 .net 2.0 更改为 3.5 in play 设置。

标签: c# sqlite unity3d unityscript


【解决方案1】:

您的代码中似乎有一个小的大写错误。

SQLiteDatabase sqlDB 替换为SqliteDatabase sqlDB

【讨论】:

  • 请解释您的答案,以便其他人觉得它有用。谢谢
  • 当然。 SQLiteDatabase 中的粗体字母不应该大写。
猜你喜欢
  • 1970-01-01
  • 2020-04-22
  • 2021-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
相关资源
最近更新 更多