• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Michael Santer
      Hi!
      We're currently two programmers and a game designer working on a turn-based tactics fantasy board game. For reference you can search for images of "Tactics Arena Online", a fairly dated game that used to have a lot of depth and complexity.
      Our goal is to use the same combat concepts, but giving it a much needed modern touch as well as a whole new set of heroes to choose from with additional abilities. The game is a mix of isometric and 3D and we plan to release the game on Steam and hopefully Android & iOS as well.
      We are looking for someone to work with us pro-bono (just like we're doing) as a 3D character artist. The skills needed are creativity, a hard working attitude and an ability to make minor animations (things like idle, walk, block and very rudimentary attack animations). A perk to have would be the ability to make some VFX. If the game makes it on steam and money starts coming in, you'd obviously be compensated for your hard work, but as it stands this is a hobby project to garnish your portfolio.
      A bit more about the game:
      This game will be an online multiplayer game where each user gets to pick up to 10 characters to place on his half of the board (this would be done before even entering matchmaking. Think runes in League of Legends for example). The user can place his 10 units of choice anywhere he likes on his half board. Some units can be used more than once. So if you want 4 knights and 2 mages or even if you want 10 clerics, you can do as you please. You can then save your setups for future use. The goal of the game is to wipe out the enemy team.
      Each character or Hero (except premium and abyss characters) start with 1 ability and they can ascend (either by playing a certain amount of matches with the character or by forcing the ascension with real money) to gain a new ability or passive. Acquiring a new character can be done by using in-game currency that you earn from playing matches or using real money with the exception of Abyss characters which can only be acquired by winning certain rare matches. The goal is to offer a freemium game with lots of customizable elements while making sure that no user can "buy power" with real money. We want everything that a paying user can get to be available to non-paying users who play the game a lot.
      Ultimately we want this to become a competitive game that people can enjoy and really get invested in. Each character is designed with options for counterplay in mind and synergy with other heroes.
       
      We sincerely believe in what this game can become and we home to find someone just as passionate as we are to get involved in this project!
    • By CrazyApplesStudio
         Hello , i would like to showcase my first game project, a simple endless casual arcade game called Apples Mania : Apple Catcher. The game has simple goal , scoring as high as possible by collecting falling apples while the difficulty gradually increases. Different apples are worth different amount of points and there are also 2 power-ups to help you in your challenge.
        The game took me about 2 months to complete and polish and i made everything except for the music tracks and some of the sound files. Made in unity and blender3d.
        Would appreciate any kind of feedback.
      Google Play Link
       
        A trailer showing basic game-play:
       
    • By Paszq
      Troglodytes are a playable races in Arpago - they usually don't talk much and most of them lives near water sources.
    • By Paszq
      a Fox in a dungeon :)
    • By Paszq
      Fox Folk is one of 3 playable races in Arpago.
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity [.net] .NET Scripting - Sharing Types/Objects

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let me try and get this into some understandable terms as my research is confusing me - it doesn't help being a relative newcomer in the .NET world either [grin] I've been trying to implement some scripting in a VB.NET application using the inbuilt .NET compiler. I've followed the stuff in this thread and on CodeProject and got a mini script compiler up and running ok. The problem I'm having now is that I want to expose some (not all) functionality from my host application to the scripting environment. Mainly, I have several custom data field objects that I'd like the scripts to be able to read. So my question is, how do I allow my scripting environment access to certain types from the host assembly and expose some objects to the script? It has something to do with Reflection, which is obvious. However, all my searching on the subject is coming up blank. Does anyone have any examples of what I'm trying to achieve? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Off the top of my head, have a separate assembly that contains all of the types you want the script to have access to and compile the script with a reference to that assembly. I haven't done much in the way of runtime compilation with .NET so I'm not sure if there would be any security risks associated with that (assuming that the types in your assembly are all considered 'safe').

Share this post


Link to post
Share on other sites
Ok, I've worked out how to get an assembly to reference another and the associated types, data et cetera. However, the problem is that the script has access to all of the types from the host, something that isn't a huge problem, but I'd rather not have it there. So the solution looks to me now as if I need to do as joanus suggested and have a 'proxy' assembly inbetween the host and the script assembly. I'll look into doing this for now, but would be grateful of any further insights you nice people can offer.

Thanks

EDIT:

A couple of useful resources I've found in searching this:

LiveCode.NET

AppDomains and Dynamic Loading

[Edited by - evolutional on September 21, 2004 5:27:19 AM]

Share this post


Link to post
Share on other sites
Forgive me if this is a waste of your time.

Recently, I've been working on a project to allow dynamically loaded "plugins" (read: assemblies) to be loaded for a business application.

The approach that was taken was to define a set of interfaces that specified the definition of: a) the framework that loaded the assemblied and b) the assemblies themselves.

Being a business environment, and given that the client wants something that works yesterday, what we did was make the framework implement an interface, and passed a reference of the framework to the plugin. The interface defined functions that gave the plugin access to properties of the framework.

Since this is a game development site, this may be totally inappropriate for your problem, but for us it worked a treat.

Let me know if you want further details.

Share this post


Link to post
Share on other sites
I'd love further details if you're willing to supply them, as I'm essentially learning scripting/plugins and how they work in .NET. The context of a particular problem domain doesn't really apply in this instance, so I'd like to see what you came up with.

I've also been reading Writing Plugin-based .NET applications which is useful. As I say, I'm a .NET n00b but looking to explore it a lot more in the future.

Share this post


Link to post
Share on other sites
Okay.

Our particular application is designed to be a framework from which we can load additional modules that are written post-deployment, and don't require us to constantly have to re-compile the framework application.

Interface-wise, the framework is a shell that loads tab pages (our plugins are written as user controls and are tab pages), and each tab page will process different input files.

Additionally, each assembly, while containing logic to load and process data files, also needed to manage a collection of settings.

In order to do this, we have three interfaces defined:


namespace TheApp
{
public interface Plugin
{
System.Windows.Forms.TabPage TabPage
{
get;
}
bool Init(TheApp.Framework f, string tabText, string configDir, string pluginName);
}


public interface Framework
{
System.Data.SqlClient.SqlConnection SqlCnn
{
get;
}

Control.MessageBar MessageBar
{
get;
}
}

public interface OptionInterface
{
bool Init(TheApp.Framework f, string configDir);
}
}


So these interfaces define the functionality of the framework, the plugin and the settings component of each interface.

The idea was to define an interface for the framework so that, if you look at the Init() function of the Plugin interface, we pass the framework in as a parameter, and then the Framework interface defines how and what we get access to (in our case, the SqlConnection and a MessageBar).

In order to load the plugin into the framework, all we do is (from the framework):

using System.Reflection;
using System.Runtime.Remoting;
using System.EnterpriseServices;
/*
....
*/
ObjectHandle h;
h = Activator.CreateInstanceFrom(p.m_filename, p.m_namespace + "." + p.m_class);
TheApp.Plugin i = (TheApp.Plugin)h.Unwrap();

i.Init(this, p.m_title, m_configPath, p.m_class);
tcMain.TabPages.Add(i.TabPage);


Other things that we do that aren't shown here including checking each loaded assembly to ensure that it uses the correct interface, retrieve information about the assembly, etc.

Since I'm coding this as a contractor, I need to be careful with what I post. If you would like to discuss this stuff further, feel free to send me an email.

Cheers,
Brendan.

Share this post


Link to post
Share on other sites
Evo, I haven't done much work using a .NET language as a scripting language, but perhaps it helps if you think about the problem in the reverse way. Perhaps the issue isn't that your scripts need to already be aware of your game entities. Perhaps, your game entities need to make themselves aware TO the scripts. So, once you create the object out of the script, then you call a Register() function on the object from the script that accepts a Game object as a parameter. And then anytime the script needs to call any functionality in the game, it calls a method or member of the Game object it was Register'd with. So, in pseudo-code, it might look like this


// Game myGame = new Game();
// GameObject zombie = new GameObjectFactory.CreateZombie();

Script myScript = ScriptManager.LoadFromFile("myScript.gsc");
myScript.Register(myGame, zombie);

....

myScript.Execute()




And then in the script itself you would have something like:


class MyScript : Script
{
private Game game = null;
private GameObject gameObject = null;

public MyScript()
{
// non-game specific load here
}

public void Register(Game game, GameObject gameObject)
{
this.game = game;
this.gameObject = gameObject;

// various other game-specific load here
}

public void Execute()
{
// use Game object to get data from or execute methods

// stuff like this
// Position myPosition = gameObject.Position;
// int score = this.game.Score;
// gameObject.Move(someX, someY);
}
}




This is just a thought though. It might work when approaching it from this different angle. If not, hopefully it might give you a different idea how to solve your problem. I hope this helps in some way! Good luck!

Share this post


Link to post
Share on other sites
Also, if you are loading up your scripts into an app domain, load them up into a different specialized app domain. First of all, if a script crashes for some reason, it won't bring down your entire app domain (and hence, application) with it. Second of all, for security reasons. Although others may not be writing their own scripts for your game to "mod" it, it is always a good idea to get in the habit of writing safe code. When you create the app domain to load your scripts into, make sure to give the app domain restricted priviledges. The last thing you want is some script kiddy to be able to write his own script, load it into your game, and have full access to the machine it is running on (and hence, access to every namespace in the bcl possibly).

Think of the new app domain as a black box that you can put the script objects in. For security reasons, the scripts themselves can't get out of the box and if they do break anything, it only breaks the box, not your application.

Just a thought though. Any time you are "loading" objects at runtime, it is a very good habit to get into loading them into a seperate app domain. Your application will be happy, and all the users of your application will be happy :).

Share this post


Link to post
Share on other sites
Thanks for your comments guys. I'm torn as to which apprach to adopt now, the script or the plugin method. The plugin method does actually seem a lot cleaner than the scripting, mainly because being a .NET n00b the whole application is a greater challenge than it would normally be as I'm learning the .NET framework as I'm going on.

Thanks for the idea Blowfish, however the problem seems to be registering my application types with the script interface. I've never done anything like this in .NET so it's all new territory. I'll keep playing, perhaps go with the plugin solution and take up the scripting idea later on when I feel more accustomed to .NET.

Oh and Blowfish - kudos for using a Zombie in your example [grin]

Share this post


Link to post
Share on other sites
This is how you can do it in C# so maybe it gives some glue how to do it in VB.

First create class libary (dll) wich containts all the functions and classes/types you want to expose for scripting.

Then

CompilerParameters pars = new CompilerParameters();

pars.ReferencedAssemblies.Add( "ClassLibTest.dll" );



I hope it helps any.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement