I’m trying to call a method, which is in a dll I’ve imported, from another class. Is there any way to do that? Thank you in advance!
To clarify myself: There is a class called “TTSManager”. In this class a dll was imported. There also is a class “TTSdotNET” and in THIS class I would like to call a method within a dll, but the method isn’t accessible. I hope somebody will help me.
P.S. I code in C#
“TTSManager”:
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
public class TTSManager : MonoBehaviour
{
[DllImport ("SpeakerLib")]
private static extern void SpeakToSpeaker(string tts);
[DllImport ("SpeakerLib")]
private static extern void SpeakToFile(string tts, string fileName, string fileFormat); [DllImport ("SpeakerLib")]
private static extern void ReleaseSpeaker();
private static TTSManager instance = null;
private TTSManager(){}
public static TTSManager getInstance
{
get
{
if(instance == null)
{
instance = new TTSManager();
}
return instance;
}
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
“TTSdotNET”:
public class TTSdotNet : MonoBehaviour
{
void Update ()
{
if (Input.GetKey(KeyCode.F10))
{
SpeakToSpeaker("hello world i feel uncomfortable.");
}
}
}
I tend to create a separate static class for the DLL imports. In addition to importing the functions I mostly also create wrapper methods for each DLL function call.
Example:
That way, any class can access the DLL and your problem is solved.