Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

simplest way to add an option to right click menu

Discussion in 'Extensions & OnGUI' started by SkullKing, Aug 9, 2016.

  1. SkullKing

    SkullKing

    Joined:
    May 31, 2012
    Posts:
    33
    Hello all,

    I never scripted anythig regarding the editor itself. so even though I am familiar with C# and read the documentation, I am not completely sure the best way to do what I intend:

    I use a lot of xmlFiles, and I want to add the option "create xml file" to the same right click menus that allow th euser to create a new C# file.

    What is the best way for me to do that? Is it viable to find the code for that menu, and only copy the code for the C# script and alter the file creating part?

    Thank you for your time.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,018
    You should read a little about menu items.

    I have written a blog post about it here.
    This post was also uploaded to the Unity learn site (https://unity3d.com/learn/tutorials/topics/interface-essentials/unity-editor-extensions-menu-items)

    In a nutshell:
    you create a (static) editor method and decorate it with the [MenuItem] attribute
    Inside this method, implement the logic you need for creating a new XML asset, etc.

    I have also created an open source project in the past for supporting new file templates. It actually provides the foundation for your scenario, you should check it out: https://bitbucket.org/liortal/code-templates

    Let me know if this helped :)
     
  3. SkullKing

    SkullKing

    Joined:
    May 31, 2012
    Posts:
    33
    Helped quite a bit, thanks. Specifically th epart that shows hot to adress the right click menus, instea dof the top bar.
     
  4. Jimbobbedyjobob

    Jimbobbedyjobob

    Joined:
    Nov 12, 2015
    Posts:
    5
    Hey,

    I am in an initial research phase for a pipeline/Asset management tool right now.

    Would this be a valid method for accessing an external database to update a flag item on an asset in my database?