# How can I add a [MenuItem] to the context menu shown when right-clicking a specific asset type in the Unity Editor?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;

public class Test : Editor
{
private static void Init()
{

}
}


When I right click on the Assets I will see the "Testing" item defined above in the context menu.

But I want to see this "Testing" option only if I right click on a script file (.cs or .js)

For example if I have a script file at Assets > Test > Test.cs, only when I right mouse click on Test.cs should the context menu show the new Testing option.

How can I do this?

Short answer - you cant "hide context menu options".

But you can disable certain menuitems with "Validation" methods. This system adds new validation method to already existing context menu, this method must return bool, true == enabled, false == disabled. Also in MenuItem attribute you must pass true as second parameter to mark that method as validator, MenuItem path must be the same as original method.

For your example with scripts you must compare current selection object with MonoScript type which represents C# scripts in Unity.

[MenuItem("Assets/Do Something")]
private static void DoSomething() {
Debug.Log("You did something!");
}

`