Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kingklutz · Dec 17, 2013 at 01:20 AM · c#runtimexmlcompile

c# to compile xml string as code during runtime

Im looking for a way to compile a xml string as code during runtime. Below is the makeup of the xml. The delimiter inbetween the elements leaderless is what I am looking to run. The reason why we are doing this is because we want our game to be open to the player, to the point where he can write in his own code. I have looked at Microsoft.CSharp, but unity says CSharp does not exist in the namespace Microsoft. I dont see why unity`s own compiler in the console says that when VB and Mono say otherwise. I even tried Mono.CSharp, same error. I believe it has to do with missing system.dlls, but I`m not sure if that`s by design or if I need to find them. I am still using the free version of unity till I can afford Pro if my current version is an issue. Or if there is another way to compile the below xml string as code during runtime.

I have seen some forums saying Unity got rid of certain compiler support, and even a source dated a year ago saying Unity would be adding Mono compiler as a service, but I don`t know if that`s any reason why I haven`t seen a viable means to do what I need.

 <Behavior>
   <Peon>
     <Leaderless>
       @"
       #using System;
       #using System.Collections.Generic;
       #using UnityEngine;
       
       static public class SkyDroneLeaderless : MonoBehaviour
       {
           public string wow = ""Success!"";            
           
           static public void Success()
           {
               Debug.Log(wow);
           }
       }"
     </Leaderless>
   </Peon>
 </Behavior>
  
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 17, 2013 at 01:55 AM 0
Share

A few hints:

  • Since your class is a static class it doesn't make much sense to derive it from $$anonymous$$onoBehaviour.

  • The using statement doesn't have a "#" infront

  • A string is a string, no matter where you got it from, so X$$anonymous$$LString (in this context) makes not much sense like a file-string (when you read the string out of a file) or http-string (because you got it from a webrequest). X$$anonymous$$LString usually referes to a string containing X$$anonymous$$L so the term is confusing here and the whole X$$anonymous$$L thing is not relevant to the question.

  • If you plan to actually compile $$anonymous$$onoBehaviour classes prepare for a lot of trouble since Unity usually need to know about the classes beforehand. There are ways to dynamically load compiled assemblies but it's a bit tricky to get it work ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Dec 17, 2013 at 01:26 AM

Well, depending on the platform you want to build for, Unity has a different sets of the default libraries (especially for the webplayer). Also it depends on your Player settings which comparibility level you've choosen.

Finally you should check the MonoCompatibility page to see what classes and what members of those classes are supported at which comparibility level.

If you have a pure managed code library you can include it without any problems by simply putting the DLL into your Assets folder (plugins folder recommended). However if you don't have Unity pro or you build for the webplayer you can't use mixed mode or native DLLs.

I never really took a deep look at the mono compiler, But if it's written entirely in managed code you should be able to include it, if the libraries Unity provides aren't enough.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kingklutz · Dec 17, 2013 at 02:11 AM 0
Share

Id vote you up, but I lack the reputation. Anyways, looking at what you said helped put some of the things I was seeing into perspective earlier. Looking at the [$$anonymous$$onoCompatibility page][1] helped me see what someone meant by changing the .net setting with something else somewhat similar. $$anonymous$$ine was set to .net 2.0 subset, which does not handle $$anonymous$$icrosoft.Csharp, as the $$anonymous$$ono page shows it being in red. Setting it to .NET 2.0 in the player settings changed unitys console error to nothing.

Now to go from here, and see what`s next on the list of things I live to fix on the way to the end goal ;p

[1]: http://docs.unity3d.com/410/Documentation/ScriptReference/$$anonymous$$onoCompatibility.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reading data from xml. 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Read AND Write to XML at runtime 1 Answer

Questions about XML save/load 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges