Group Group Group Group Group Group Group Group Group

Unity/C# Accessing Data Files to pass to a DLL/API

#1

Salutations!
In my Unity Project, i have added a “plugin” DLL.
This library requires data files to be fed in to it.

Can someone show me how to do this in Unity/C#?

I have seen it done in straight C# with this library, but there are some idiosyncrasies in Unity/C#,

ALSO: I there any precedent of this architecture working on mobile devices?

Thank you for considering my problem and let me know if you need more information!

Cheers!
Chief_Ed!

#2

@chief_ed
Hi there!

Have you added the DLL to the “Plugins” folder?
If so, is it a .NET library? What version of .NET was it compiled with?
To answer your second question: yes, it will probably work on mobile if it’s not platform specific.

If you can give some more details about the plugin/library and how the documentation says it should be used I can offer more help.

Cheers!
Eric

#3

Hi Eric,
I have created a “Plugins” folder and I added the DLLs there (for the sake of good file management, I am told). Unity recognizes the DLL, which is written in .NET version 2, I believe. The Inspector seems to recognize the library, and shows a screen displaying the platform options.

There is no documentation for what I want to do with it, but I do have a snipit of code explaining how to access the library in C# per say. I will include that below.

The library is for an old product called CLIPS (C Language Integrated Production System)
CLIPS requires files to feed it information to run.

I need help figuring out how to get Unity to route these files into Unity/C# so I can feed them to CLIPS…

Here is the code I was shown that works with C# stand-alone. As you can see, it uses the disk structure to feed the data file into C#. I need a different way to do this fr the Unity project:

using System;

namespace GetMarriedOrStaySingle_AsCSharpApp
{
   class Program
   {
       static void Main(string[] args)
       {
           CLIPSNet.Environment theEnv = new CLIPSNet.Environment();
           theEnv.Load(@"..\..\..\SocratesKnowledgeBase.clp");
           theEnv.Reset();
           theEnv.Run(-1);
       }
   }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can you help me?
-Chief_Ed
#4

@chief_ed
Sorry for the late reply,

If I understand correctly, what you’re looking for is a way to run that code on start-up like the Main method would do in a regular C# project?

Create a new C# script anywhere in your Assets folder (preferably in a Scripts folder) and name it CLIPSLoader. (see this tutorial if you’re confused: https://www.raywenderlich.com/127672/introduction-unity-scripting)

Open it up in your C# IDE and you’ll see a Start() and an Update() method.
Start() will run once when the GameObject the script is attached to is loaded in the scene, so that’s where you want to put your code.

For example:

void Start()
{
    CLIPSNet.Environment theEnv = new CLIPSNet.Environment();
    theEnv.Load(@"..\..\..\SocratesKnowledgeBase.clp");
    theEnv.Reset();
    theEnv.Run(-1);
}

You may need to add a reference to the CLIPS library by adding a using statement at the top.

Now add a new empty GameObject to the scene and drag the script on top of it (or select the GameObject and add it in the Inspector as a component).
Now run the scene and the code will be executed.

Be sure to check out our tutorials to find your away around the editor.

Hope this helps!
Cheers

#5

Hi Eric,
Thank you for taking the time to reply.

I do not think I was clear in my original message. I apologize for the confusion.

Here is the actual code in my C# script:

For illustration purposes, my C# script is as follows:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CLIPSNet;

namespace TakeAByteSolutions.LISP.Unity 
{
public class GetCLIPS : MonoBehaviour 
  {
    // Use this for initialization
    void Start () {        
//            Debug.Log("Getting Started");
        }

    // Try to open CLIPS from Unity
    void OnDisable()
    {
            Debug.Log ("Disabled toolbox..."); //OK, you got here.
        CLIPSNet.Environment theEnv = new CLIPSNet.Environment();
//        theEnv.Load("basics01POC.clp");
//        theEnv.Reset();
//        theEnv.Run(-1);

            Debug.Log("Step by step, row by row...");
 }
        void OnEnable()
        {
            Debug.Log ("Enabled toolbox...");
            //
        }
}
}

As you know, since this is in Unity, there isd no “Main” class. Also, for testing purposes,
I have this code attached to the “Disable” event of an object in the project called “Toolbox”.

What I now need is someone who has access to the CLIPS source code and can re-compile an asset that I need; the CLIPSLib.dll file.

Is this something you can do? If not my search continues!

Thank you for your attempts to help me. The effort is appreciated!

Cheers,
Chief-Ed

#6

Hi Ed,

I’m afraid I’m not familiar with CLIPS so I can’t help out there.
Good luck on your search!

Cheers!
Eric

closed #7

This topic was automatically closed after 166 days. New replies are no longer allowed.