Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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,134
    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?