It’s sometimes useful to customize Unity’s Project view, for example to extend the context menu to create a custom ScriptObject asset, or to enable double-clicking to open a custom file type.

Extending the Project View Context Menu

Menu items in the Assets menu are also added to the Project view’s right-click context menu. Use the MenuItem attribute and add “Assets/” to the front of the menu item. The example below uses the Unity Community’s ScriptableObjectUtility script to create an asset of the type ‘MyScriptableObject’.

using UnityEngine;
using UnityEditor;

public static class MyMenuItems {
     
    [MenuItem("Assets/Create/My ScriptableObject")]
    public static void CreateMyScriptableObject() {
        ScriptableObjectUtility.CreateAsset<MyScriptableObject>();
    }
}

 
Opening New File Types on Double-Click

The code below opens an external application when you double-click a file. This is a bit of a hack, since Unity will log a warning that Unity itself can’t open the file. However, the class will open it.

We use InitializeOnLoad to hook into the event EditorApplication.projectWindowItemOnGUI. In the event handler, we check for a double-click mouse event. Then we check if the current selection is an Excel file. If so, we run Excel.

For simplicity, we only check the extension .xls in this example. Excel actually has many different formats, such as .xlsx. In practice, you’d want to act on those, too. Also, unless excel.exe is in your path, you’ll need to provide the full path to the program.

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class MyClass {

    static MyClass() {
        EditorApplication.projectWindowItemOnGUI += OnProjectWindowItemOnGUI;
    }

    private static void OnProjectWindowItemOnGUI(string guid, Rect selectionRect) {
        bool isDoubleClick = (Event.current.type == EventType.MouseDown) && 
            (Event.current.clickCount == 2) && 
            selectionRect.Contains(Event.current.mousePosition);
        bool isMyFileType = (AssetDatabase.GetAssetPath(Selection.activeObject).EndsWith(".xls", System.StringComparison.OrdinalIgnoreCase)))
        if (isDoubleClick && isMyFileType) {
            OpenInExcel();
        }
    }

    private static void OpenInExcel() {
        string fileName = "excel.exe";
        string arguments = "\"" + Path.Combine(Directory.GetCurrentDirectory(), AssetDatabase.GetAssetPath(Selection.activeObject)) + "\"";
        System.Diagnostics.Process.Start(fileName, arguments);
    }

}