mercredi 30 septembre 2015

Use non monoBehaviour class in unity

I'm going through a bug or at least something i don't really get.

I'm trying to use sqlite database in my unity project.

Here is the error i get:

enter image description here

The DatabaseManager class is a MonoBehaviour class.

Here is what it looks like:

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);
}
}

The thing is that if i got it right, the fact that i put my scripts under the assets folder should be enough for them to work together and recognize classes in other files. Now the problem is simple i my DatabaseManager class does not recognize the SqliteDatabase class which is implemented in SqliteDatabase.cs

Have someone had this issue or did i miss something on how to reference a non MonoBehaviour script in a MonoBehaviour one ?

EDIT:

I used this tutorial : Here

Thanks !

Aucun commentaire:

Enregistrer un commentaire