unity3d 导航栏 组件

//脚本不需要挂载, 所有方法都是静态方法

public MenuItem(string itemName);
public MenuItem(string itemName, bool isValidateFunction);
public MenuItem(string itemName, bool isValidateFunction, int priority);


    public static void Handles()
    {
        Object[] gos = Selection.objects;

        //Debug.Log("go " + gos);
        foreach (var go in gos)
        {

            string path = AssetDatabase.GetAssetPath(go);

            string extname = Path.GetExtension(path);
            string goname = Path.GetFileNameWithoutExtension(path);
            string pathname = Path.GetDirectoryName(path);
            File.Copy(path, newPath + goname + "_UI" + extname, true);
        }
    }


    [MenuItem("测试/测试", false, 101)]
    public static void MyTest()
    {
        Debug.LogError("dddddddddddddddd GGGGGGGGGGGGG");
    }

    // 1.在菜单栏添加按钮
    [MenuItem("测试/Mybutton", false, 101)]
    public static void OnClick()
    { 
        Debug.Log("按下button");
    }
    
    // 4.Selection 获取当前选中物体
    [MenuItem("测试/11__Mydelete", false, 11)]
    public static void SeletionTest()
    {
        //打印当前选中物体的个数
        Debug.LogError(Selection.objects.Length);
        //如果你删除了你选中的物体,可以点击此按钮恢复这些物体
        foreach (Object item in Selection.objects)
        {
            Debug.LogError("item", item);

            //可以撤销删除操作
            Undo.DestroyObjectImmediate(item);
        }
    }

    //5.为按键添加快捷键​
    // %ctrl   #shift  &alt
    // ctrl+shift+w
    [MenuItem("测试/MyButton/Debug %#w")]
    public static void MyButton1()
    {
        Debug.LogError("Debug ctrl+shift+w");
    }

猜你喜欢

转载自blog.csdn.net/jiuzhouhi/article/details/85102932
今日推荐