unity复制路径到windows黏贴版(vscode luaide lua pathcopy)

复制到黏贴版

在使用lua的时候需要获取物体时使用路径来查找,写一个小工具方便使用:
关键代码

GUIUtility.systemCopyBuffer = "test";

这里我使用的vscode 编辑器,用了luaide插件。做ui的时候需要用路径寻找物体,这里使用一个快捷键组成一个lua代码方便使用。
模板如下

--@RefType[luaIde#"+ typeName + "] \n    
self.objName = self: GetCom(path, typeName);

关键代码

 [MenuItem("GameObject/CopyPathToUIPanelCode %Q", false, 1)]
    public static void CopyCodePathToUIPanel()
    {
        GameObject obj = Selection.activeGameObject;
        string path = Path(obj);
        path = path.Substring(1);
        List<Type> types = new List<Type>();
        types.Add(typeof(UIWrapContent));
        types.Add(typeof(UIGrid));
        types.Add(typeof(UITable));
        types.Add(typeof(UIScrollView));
        types.Add(typeof(UIButton));
        types.Add(typeof(UIPopupList));
        types.Add(typeof(UITexture));
        types.Add(typeof(UISlider));
        types.Add(typeof(UICenterOnChild));
        types.Add(typeof(UICenterOnClick));
        types.Add(typeof(UILabel));
        types.Add(typeof(UISprite));

        string codeStr = "self: GetCom(\"{0}\", {1});";
        string typeStr = "";
        string prefix = "";
        foreach (var item in types)
        {
            Component test = obj.GetComponent(item);
            if(test != null)
            {
                typeStr = item.Name;
                prefix = "--@RefType[luaIde#"+ item.Name + "] \n    ";
                break;
            }
        }
        if(typeStr == "")
            codeStr = "self:GetCom(\"{0}\");";
        string codestr = string.Format(codeStr, path, "NGUIComponent."+typeStr);


        codestr = prefix + "self." + obj.name + " = " + codestr;

        Debug.Log(codestr);
        GUIUtility.systemCopyBuffer = codestr;
    }

lua代码的定义,这里的定义时为了统一维护

NGUIComponent = 
{
    UIPanel = "UIPanel",
    UIWidget = "UIWidget",
    UISprite = "UISprite",
    UIButton = "UIButton",
    UIPopupList = "UIPopupList",
    UILabel = "UILabel",
    UIGrid = "UIGrid",
    UIToggle = "UIToggle",
    UIWrapContent = "UIWrapContent",
    UIScrollView = "UIScrollView",
    UIScrollBar = "UIScrollBar",
    UITexture = "UITexture",
    UITable = "UITable",
    UISlider = 'UISlider',
    UICenterOnChild = "UICenterOnChild",
    UICenterOnClick = "UICenterOnClick",
    UIProgressBar = "UIProgressBar",
    UIEventListener = "UIEventListener",
    UIEventTrigger = "UIEventTrigger",
    UIInput = "UIInput",
    TweenAlpha = "TweenAlpha",

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值