I'm trying to run a function in C# from UnityScript. My UnityScript file has:
GetComponent("C#File").C#FunctionName();
But in the editor it's telling me that the function isn't a member of UnityEngine.Component.
Try
GetComponent<"C#File">().C#FunctionName();
You need to put the "to be accessed" script in one of the folders thats compiled earlier.
That does not only mean the editor folder, but also Plugins, Standard Assets and Pro Assets
That way scripts of the other languages are able to work with it.
The only alternative is not to access it directly at all and use SendMessage instead
The least amount of trouble and headache is present if you just focus on one language instead of mixing 2+ languages
Related
I'm working on an online video game project using Unity3D for the clients, and C# servers.
I'm trying to use some code eval for a specific feature, but I can't get it to work.
I went with Mono, because it seemed to be one of the lightest and one of the simplest. I installed Mono and got the "Mono.CSharp.dll" for .Net 4.6 from "Mono\lib\mono\4.6-api". (Both Unity and my servers are configured to use this version of .Net). I dropped it in the Unity assets, and referenced it on my servers.
But I have errors on both Unity and the servers. In Unity there is :
Loading script assembly "Assets/Scripts/Common/References/Mono.CSharp.dll" failed!
And there is an exception on the servers (my IDE is in French so I can't really copy/paste it), but it basically tells me it can't use Reference Assemblies for build, but only for reflection.
To describe the feature I want to create (because you'll maybe have a better solution), I want to be able to create spells from an external tool. Spells are made of SpellEffects. Let's say there is a SpellEffect called DealDamage, constructor takes an int (for the damage amount). I want to be able to write "DealDamage(50)" on my external tool, then take the string, and build a new DealDamage(50) from it.
I know I could find a way to interpret some code by myself, but it would be a lot more work for a far less flexible system.
It was really hard to find any help online for this problem, so as a last hope I'm turning to you.
I'm not exactly sure why you're trying to import Mono into Unity. It's already included in the installation package. If you want to make a modular spell builder, just create a regular application with your preferred language, in your preferred IDE, and save all of your spells as a JSON or XML file, and then import those into Unity. On the Unity side, just build a class to parse the files.
To get you started, take a look at the JSON.Net library. You can serialize your files into C# classes with it.
I'm trying to work on an environment that its main function is to adopt Visual Programming to create NetLogo code (similar to Google's Blockly).
Right now, I'm using Unity3D to do the job and wondering if it's possible to access NetLogo from it. The objective is to send the generated code directly into the Code Tab, opening a blank project already with the code in the tab (without the user copying and pasting it there).
What I know up until now is that I can open NetLogo from Unity with a function called Process.Start, which takes 2 arguments: the first is the name of the target program to be executed ("NetLogo.exe"), the second one is a list of arguments that can be passed to the targeted program, which solely depends on each program, as found here and here. However, I didn't understand much about these arguments, which is why I recurred to ask.
Do I need to also work on a Java/Scala environment to do this for me with the Extensions API, or can I use these arguments in Process.Start to do it?
Thanks in advance.
You could create a fully formed .nlogo file (it's basically a text file with a specific format), and then launch NetLogo using your Process.start command with that filename as an argument so that NetLogo will open that specific file.
You could even create a .nlogo file as a template (with whatever interface items you want), and then use string search/replace to substitute in the code that you want in the code tab.
Alternatively, fancier things are possible with the Controlling API , but I don't know much about calling JVM code from within Unity, and I suspect that will be a bigger headache than you want... unless you really need a more tight-knit connection to NetLogo, or unless the performance overhead of starting a new NetLogo process each time is unacceptable.
I am hoping that someone might be able to help me out here. I am relatively new to C# and am trying to execute some Python code I wrote from within a C# winform app.
What I would like to do is input a name from a text box within the winform and have it process through the python scripts and return a result in another textbox on the winform.
I have found several good examples of how to execute a single script within C#, but I am having some trouble understanding how I can reference multiple scripts.
As an example, I have one python script that references two other scripts within code
from FindTelephone import *
from FindAddress import *
def createPerson(name)
telephone = FindTelephone(name)
address = FindAddress(name)
....
Is there a way to have C# point to a reference of my other python scripts before running my main script?
Thanks in advance for the help.
Marshall
Like in these posts?:
Call Python function from c# (.NET),
run a python script from c#?
Or
You might want to look into pythonnet.
Or
If you want an easyer way of doing this then I recommend using Iron Python in place of normal Python. IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. Means that it is much easyer to use with C# and Windows Forms and looks almost just like normal Python.
Or
For in case you are using Visual Studio, VS has some Python tools that might help you in your quest. Link. You can find more documentation Here This last link is provided by Jedediah from comments so vote his comment up if you liked this last link.
Other handy link: Integrating Python With Other Languages
I have developed an application which can create Xml files from Xml schema with some user defined rules for generating value for each node.
I want to give my user the ability to write scripts for generating value for each node and in this scripts user should be able to refer to generated value of other nodes .
a simple script will be something like :
returtn (#node1.value + 10) ;
I don't know what will be the value of #node1.value because the file generation process hasn't started yet.
so what is the solution do I have to replace it every time with the generated value and then run the script or is there a better way to do something like this ?
may be I have to run this script thousand of times to generate value for created instances so which scripting language is the fastest one for me to use ?
thanks
You can look at IronPython.
If you are looking for a script language with a sysntax similar to C#, then you can look at CS-Script.
Have you looked at using C# as your scripting language?
http://www.csscript.net/
Use locks :-). If someone invokes get_method of the property that isn't set just lock the caller until value is set.
PowerShell embeds well into a C# application, here's how from the PowerShell Team Blog
Alright, so I'm working on programming my own installer in C#, and what I'd like to do is something along the lines of put the files in the .exe, so I can do
File.Copy(file, filedir);
Or, if this isn't possible, is there another way of doing what I am attempting to do?
I wouldn't code my own installer, but if you truely want to embed files into your assembly you could use strongly typed resources. In the properties dialog of your project open up the "Resources" tab and then add your file. You'll then be able to get the file using:
ProjectNamespace.Properties.Resources.MyFile
Then you'll be able to write the embedded resource to disk using:
System.IO.File.WriteAllBytes(#"C:\MyFile.bin", ProjectNamespace.Properties.Resources.MyFile);
Honestly, I would suggest you NOT create your own installer. There are many many issues with creating installers. Even the big installer makers don't make their own actual installers anymore, they just create custom MSI packages.
Use Mirosoft Installer (MSI). It's the right thing to do. Make your own custom front-end for it, but don't recreate the already very complex wheel that exists.
UPDATE: If you're just doing this for learning, then I would shy away from thinking of it as "an installer". You might be tempted to take your "research" and use it someday, and frankly, that's how we end up with so many problems when new versions of Windows come out. People create their own wheels with assumptions that aren't valid.
What you're really trying to do is called "packaging", and you really have to become intimately familiar with the Executable PE format, because you're talking about changing the structure of the PE image on disk.
You can simulate it, to a point, with putting files in resources, but that's not really what installers, or self-extractors do.
Here's a link to Self-Extractor tutorial, but it's not in C#.
I don't know enough about the .NET PE requirements to know if you can do this in with a managed code executable or not.
UPDATE2: This is probably more of what you're looking for, it embeds files in the resource, but as I said, it's not really the way professional installers or self-extractors do it. I think there are various limitations on what you can embed as resources. But here's the like to a Self-Extractor Demo written in C#.
I'm guessing here, but if you are trying to store resources in your application before compilation, you can in the Project Explorer, right click a file you would like to add, chose properties and change the type to Embedded Resource.
You can then access the embedded resources later by using the instructions from this KB:
http://support.microsoft.com/kb/319292
in case you simply want to store multiple files in a single file storage (and extract files from there, interact etc.) you might also want to check out NFileStorage, a .net file storage. written in 100% .NET C# with all sources included. It also comes with a command line interpreter that allows interaction from the command line.