Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ziuber · Jul 05, 2016 at 02:45 AM · c#editor-scriptinggeneratorioextensions

Script generation.

Hi, I am thinking of writing an extension for unity Editor. I want to create a 'setup' window, which will do some work for me and setup any new project based on settings I choose. For example: I check 'google play', 'save files' and 'achievements' checkboxes and hit 'Setup' button. Now, based on these settings the script would generate necessary generic classes for me.

Now for the questions:

  1. How can I store code template files so my extention would read it? What type? Xml? Other? the extension needs to save those templates as .cs files

  2. How can I specify what to read? Reading from line X to line Y would be ok., but ideally I need something like this: look for a text "JFHDDI" (for example) -> read until you come across this "HFIDDN" -> then build a .cs file from what you have read.

  3. Can I edit .cs scripts with another script (not runtime of course)?

Although, I could store my code templates as xml files I still can't find solution to my second question.

Any help much appreciated.

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 _Yash_ · Jul 05, 2016 at 11:41 AM 0
Share

You can store all your templates in .txt files which you can read and manage easily, create saperate folder for each functionality you want to add and import whole folder inside project and rename files.
you can keep all the variable values (google play IDs and all) inside resources folder and read them at runtime.
Yes, you can edit files in editor, in fact script can also edit script itself.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Fire_Cube · Jul 05, 2016 at 12:01 PM

I did something of this kind, it first depend if you need to have 'arguments' of generation or not. I think the best way for what you say is to keep the classes in txt files (online or not), with eventually a file that contain a register of all files, and just use File.Copy(from, to); to generate the files. If you need arguments, it's getting harder, but you can develop a pseudo programming language for it, like when reading, if you go through a line that start with ~$: it mean it's a special code line, and you need to see what it mean eg:

 public class Foo
 {
 ~$:if(USE_CONSTRUCTOR)
 public Foo()
 {
 //stuff
 }
 ~$:endif
 }
 

Maybe try something like that. If you want, I can help you create a pseudo code like this, i think it's interesting ;)

good luck :)

Comment
Add comment · Show 3 · 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 Ziuber · Jul 06, 2016 at 02:23 AM 0
Share

Hmm. I suppose if I keep each functionality in a separate txt file and then read what I need and store it in string variables I could then use File.AppendAllText and create a script file out of what I gather... Ugh seems like a lot of tedious work but it's doable. Thanks for the hint!

avatar image Fire_Cube · Jul 06, 2016 at 08:30 AM 0
Share

Well, once the code to read the files and eventually modify them, it's easy. Do you really need to do file modification? If not, then just templates files are quite enough.

If you want I can do you a code for the syntax up there, since it's more an iteration of all lines than anything else.

avatar image Ziuber Fire_Cube · Jul 06, 2016 at 10:42 PM 0
Share

Thanks but I found a piece of code that searches for a block of text I want and copies it into a variable. I can build my script files from there. I just need to write the templates with modularity in $$anonymous$$d. I think that if I think this through I will be able to make this extension.

Here is the find: http://stackoverflow.com/questions/11195827/reading-block-of-text-file

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

168 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Undo.RecordObjects is not working on 2018.3??? 0 Answers

how to subdivide and smooth a cube in unity 1 Answer

How to add a component on a GameObject in Custom Inspector 1 Answer


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