Unity-批量添加命名空间

本文介绍了在Unity开发中如何快速、批量地为多个脚本添加合适的命名空间,提高代码组织和管理效率。通过使用Visual Studio的批量替换功能或者自定义脚本,可以实现对多个文件进行统一修改,确保项目代码结构清晰,便于维护。
摘要由CSDN通过智能技术生成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;

/// <summary>
/// 批量添加和修改代码命名空间工具(放在Editor文件夹)
/// </summary>
public class AutoAddNameSpaceEditor : ScriptableWizard
{
    public string folder = "Assets/";
    public string namespaceName;

    static float windowWidth = 500f;
    static float windowHeight = 500f;

    static AutoAddNameSpaceEditor editor;
    void OnEnable()
    {
        if (Selection.activeObject != null)
        {
            string dirPath = AssetDatabase.GetAssetOrScenePath(Selection.activeObject);
            if (File.Exists(dirPath))
            {
                dirPath = dirPath.Substring(0, dirPath.LastIndexOf("/"));
            }
            folder = dirPath;
        }
    }

    //%:Ctrl,#:Shift,&:Alt %#&z:Ctrl+Shift+Alt+A
    [MenuItem("编辑器扩展/Add Namespace", false, 10)]
    static void CreateWizard()
    {
        editor = ScriptableWizard.DisplayWizard<AutoAddNameSpaceEditor>("Add Namespace", "添加命名空间", "取消");
        editor.minSize = new Vector2(windowWidth, windowHeight);
    }

    /// <summary>
    /// 点击取消按钮时调用
    /// </summary>
    private void OnWizardOtherButton()
    {
        editor.Close();
    }

    /// <summary>
    /// 点击确定按钮时调用,这里的确定按钮就是"添加命名空间"
    /// </summary>
    public void OnWizardC
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值