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 andrei.vaduva.mavenhut · Oct 08, 2015 at 04:56 PM · editoreditor-scriptingdllextensions

Unity Editor script in DLL

Hi, I'm am trying to create a dll (or any script) that doesn't depend on the project's compilation.

We have a file that has some constants which need to be auto-generated by our build script. The file is in gitignore, so when you pull the project, the menu that the build script adds (with the option to generate the constants file) doesn't exist, because you are missing the file :)

So the project doesn't compile, because it requires a file to be generated, but the option that generates the file, doesn't exist because the project doesn't compile :)

Is there any way to add a menu item that doesn't depend on the project compilation ?

Thanks

Comment
Add comment
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

1 Reply

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

Answer by Statement · Oct 08, 2015 at 07:55 PM

Yes, here are some steps to do it with Visual Studio.

 // Create a new C#/Windows/Class Library project. Set the Framework to 3.5 
 // (I don't remember which versions are supported but 3.5 should do fine).
 // In solution explorer, add a reference to UnityEditor.dll and UnityEngine.dll
 // by right clicking "References/Add Reference..."
 // ... Which are found here: C:\Program Files\Unity\Editor\Data\Managed
 
 using UnityEditor;
 using UnityEngine;
 using System.IO;
 
 public static class GenerateConstants
 {
     [MenuItem("Assets/Generate Constants")]
     public static void GenerateConstantsFile()
     {
         string contents = "Some text etc";
         string filename = "autogenerated example.txt";
 
         string path = Path.Combine(Application.dataPath, filename);
         File.WriteAllText(path, contents);
         Debug.Log("Generated file at: " + path);
         AssetDatabase.Refresh();
     }
 }
 
 // Compile the dll file, and place it under Assets/Editor

You could do the same with MonoDevelop and it's pretty similar, although I don't feel like doing a step by step for it. Basically you just create a dll project, reference UnityEngine.dll and UnityEditor.dll. Code away. Compile. Place dll in Assets/Editor.

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 andrei.vaduva.mavenhut · Oct 08, 2015 at 09:16 PM 0
Share

I tried that before posting here. I had no results. It compiled, with no errors, but the menu didn't show up. I checked all the references, there where no external references (project related), everything needed was in the dll, but nothing showed up in the menu. If i ran the code without a dll, the menu worked, if the project compiled. I thought i did something wrong. I'll check the dll again, maybe i missed something. Thanks for the confirmation :)

avatar image andrei.vaduva.mavenhut · Oct 09, 2015 at 08:15 AM 0
Share

It worked. Thanks :) For others that are looking, it did not work to compile via "mcs" i had to create a mono develop project with .NET target 2.0 and add the assembiles for UnityEditor and UnityEngine. After that, you add your code, build and copy the dll and mdb into Assets/Editor.

avatar image Statement andrei.vaduva.mavenhut · Oct 09, 2015 at 10:22 AM 0
Share

Doesn't $$anonymous$$onoDevelop invoke mcs? I am not a $$anonymous$$onoDevelop/mcs expert at all but I thought $$anonymous$$D used mcs as its toolchain. Perhaps you can check the command line arguments in build log and compare it to those you used if you have a preference to use mcs for any reason.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Which is the easiest technique to produce deliverable editor scripts with closed source code? 2 Answers

How can we use httpwebrequest in editor 0 Answers

How to execute a script each time I add a certain prefab to the scene? 2 Answers

Editor script folder selection button. 0 Answers

Cant link PLUGIN.DLL with PLUGIN-EDITOR.DLL 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