使用NGUI的时候还有xxx快捷键创建, spirte,label,button等等. 在UGUI里面的时候好像是没有快捷键的. 不知道以后多久才能有这个功能.  在家里闲无聊的时候写了一个脚本, 可以方便的创建UGUI组件(Button,Image,Text,InputFile等等)

快捷键列表如下:

Text Shift+Alt+L
Button Shift+Alt+B
Image Shift+Alt+S
InputField Shift+Alt+I

 

代码部分:

using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEngine.UI; /// <summary>
/// 根据快捷键创建UGUI控件
/// 快捷键符号% Ctrl # Shift & Alt
/// </summary>
public class UGUIShortcutKey : Editor
{ public const int UIlayer = 5; //UI [MenuItem("Plateface/CreateUGUI Text #&L")]
public static void CreateText()
{
if (Selection.gameObjects.Length > 0)
{
GameObject obj = Selection.gameObjects[0];
GameObject text = new GameObject();
RectTransform textRect = text.AddComponent<RectTransform>();
Text textTx = text.AddComponent<Text>();
text.transform.SetParent(obj.transform);
text.name = "Text";
text.layer = UIlayer;
textTx.text = "plateface"; textRect.localScale = new Vector3(1, 1, 1);
textRect.anchoredPosition = Vector2.zero;
textRect.anchoredPosition3D = Vector3.zero; RectTransformZero(textRect);
} } [MenuItem("Plateface/CreateUGUI Button #&B")]
public static void CreateButton()
{
if (Selection.gameObjects.Length > 0)
{
Debug.Log("创建按钮");
GameObject obj = Selection.gameObjects[0];
if (obj == null) return; GameObject button = new GameObject();
GameObject buttonTx = new GameObject(); RectTransform buttonRect = button.AddComponent<RectTransform>();
RectTransform buttonTxRect = buttonTx.AddComponent<RectTransform>(); button.AddComponent<Image>();
buttonTx.AddComponent<Text>(); button.transform.SetParent(obj.transform);
buttonTx.transform.SetParent(button.transform);
button.name = "Button";
buttonTx.name = "Text"; button.layer = UIlayer;
buttonTx.layer = UIlayer; RectTransformZero(buttonRect);
RectTransformZero(buttonTxRect); }
} [MenuItem("Plateface/CreateUGUI Image #&S")]
public static void CreateImage()
{
if (Selection.gameObjects.Length > 0)
{
Debug.Log("创建UGUI图片");
GameObject obj = Selection.gameObjects[0];
RectTransform selectionObjRect = Selection.gameObjects[0].GetComponent<RectTransform>(); GameObject image = new GameObject();
RectTransform imageRect = image.AddComponent<RectTransform>();
image.AddComponent<Image>();
image.transform.SetParent(obj.transform);
image.name = "Image";
image.layer = 5; RectTransformZero(imageRect);
} } [MenuItem("Plateface/CreateUGUI InputField #&I")]
public static void CreateInputField()
{
//创建UGUI标签
GameObject obj = Selection.gameObjects[0]; GameObject inputField = new GameObject();
RectTransform rectTransform = inputField.AddComponent<RectTransform>();
Image image = inputField.AddComponent<Image>();
image.sprite = Resources.Load<Sprite>("UnityPlugins/UGUIShortcutKeyTexture/background1");
inputField.AddComponent<InputField>();
rectTransform.localScale = new Vector3(1, 1, 1);
inputField.layer = UIlayer; inputField.transform.SetParent(obj.transform);
inputField.name = "InputField"; GameObject placeholder = new GameObject();
Text placeholderTx = placeholder.AddComponent<Text>();
placeholder.transform.SetParent(inputField.transform);
placeholder.name = "Placeholder";
placeholder.layer = UIlayer;
placeholderTx.color = Color.black; GameObject text = new GameObject();
Text textTx = text.AddComponent<Text>();
text.transform.SetParent(inputField.transform);
text.name = "Text";
text.layer = UIlayer; textTx.color = Color.black; RectTransformZero(rectTransform); } public static void RectTransformZero(RectTransform rectTransform)
{
rectTransform.localScale = new Vector3(1, 1, 1);
rectTransform.anchoredPosition = Vector2.zero;
rectTransform.anchoredPosition3D = Vector3.zero;
}
}

 

插件下载地址http://yunpan.cn/cHYb3wR7fqnUU  访问密码 a91c

UGUI 快捷键创建UGUI组件的更多相关文章

  1. Unity进阶技巧 - 动态创建UGUI

    前言 项目中有功能需要在代码中动态创建UGUI对象,但是在网上搜索了很久都没有找到类似的教程,最后终于在官方文档中找到了方法,趁着记忆犹新,写下动态创建UGUI的方法,供需要的朋友参考 你将学到什么? ...

  2. Unity添加自定义快捷键——UGUI快捷键

    在Editor下监听按键有以下几种方式: 自定义菜单栏功能: using UnityEngine; using UnityEditor; public static class MyMenuComma ...

  3. HTML5 UI框架Kendo UI Web教程:创建自定义组件(三)

    Kendo UI Web包 含数百个创建HTML5 web app的必备元素,包括UI组件.数据源.验证.一个MVVM框架.主题.模板等.在前面的2篇文章<HTML5 Web app开发工具Ke ...

  4. HTML5 UI框架Kendo UI Web中如何创建自定义组件(二)

    在前面的文章<HTML5 UI框架Kendo UI Web自定义组件(一)>中,对在Kendo UI Web中如何创建自定义组件作出了一些基础讲解,下面将继续前面的内容. 使用一个数据源 ...

  5. 动态创建angular组件实现popup弹窗

    承接上文,本文将从一个基本的angular启动项目开始搭建一个具有基本功能.较通用.低耦合.可扩展的popup弹窗(脸红),主要分为以下几步: 基本项目结构搭建 弹窗服务 弹窗的引用对象 准备作为模板 ...

  6. vue通过extend动态创建全局组件(插件)学习小记

    测试环境:nodejs+webpack,例子是看文章的,注释为自己的理解 创建一个toast.vue文件: <template> <div class="wrap" ...

  7. C#创建COM组件

    本文详细阐述如何用C#创建COM组件,并能用VC6.0等调用. 附:本文适用任何VS系列工具. 在用C#创建COM组件时,一定要记住以下几点: 1.所要导出的类必须为公有: 2.所有属性.方法也必须为 ...

  8. VS2010 C++ 创建COM组件

    1.项目中要使用到com组件,于是了解了一下com,并根据<C#高级编程>中关于com的介绍用vs创建了一下com,用于实验.以下均根据书中的demo做一遍,熟悉一下而已. 2.创建CoM ...

  9. C#创建COM组件供VB,PB,Delphi调用

    1  COM组件概述 COM是微软公司为了计算机工业的软件生产更加符合人类的行为方式开发的一种新的软件开发技术.在COM构架下,人们可以开发出各种各样的功能专一的组件,然后将它们按照需要组合起来,构成 ...

随机推荐

  1. Learning Lua Programming (3) iMac下搭建Lua脚本最好的编码环境(代码补全,编译运行)

    这篇文章参考自http://blog.sina.com.cn/s/blog_991afe570101rdgf.html,十分感谢原作者的伟大创造,本人亲测可行. 这篇文章记录一下如何在MAC系统环境下 ...

  2. [Javascript] lodash: memoize() to improve the profermence

    Link: https://lodash.com/docs#memoize Example: .service('UserPresenter', function(UserConstants){ va ...

  3. 解决Fetching android sdk component information加载过久问题

    安装完成后,如果直接启动,Android Studio会去获取 android sdk 组件信息,这个过程相当慢,还经常加载失败,导致Android Studio启动不起开.解决办法就是不去获取and ...

  4. linux提取指定行至指定位置

    grep查找ERROR,定位位置 awk打印到指定行数 sed打印到文本末尾 awk打印到文本末尾 方法一 #!/bin/csh -f if(-f errorlog.rpt) then rm -rf ...

  5. 配置错误--分析器错误消息: 无法识别的属性“targetFramework”。请注意属性名称区分大小写。

    在部署网站的时候,很容易遇到这个一样错误:分析器错误消息: 无法识别的属性“targetFramework”.请注意属性名称区分大小写.  错误如图: 错误原因: 部署网站时,使用的应用程序池版本不对 ...

  6. (转)jQuery插件开发模式

    要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台一样,得平台者得天下.苹果,微软,谷歌等巨头,都有各自的平台及生态圈 ...

  7. jquery悬停tab

    <style> *{ margin:0; padding:0;} body { font:12px/19px Arial, Helvetica, sans-serif; color:#66 ...

  8. SqlCommand和SqlDataAdapter有什么区别

    因为DataSet是离线的,所以SqlDataAdapter这个对象是连接DataSet和数据库的桥梁,所有对DataSet的操作(填充,更新等)都要通过他 ado.net数据访问有两种方式: 1.离 ...

  9. 关于WinForm/Web如何使用缓存Cach

    原文链接:http://www.cnblogs.com/zfanlong1314/archive/2013/03/28/2986403.html Cache 的绝对到期与滑动到期 绝对到期:设置绝对过 ...

  10. 洛谷 P3397 地毯

    P3397 地毯 题目背景 此题约为NOIP提高组Day2T1难度. 题目描述 在n*n的格子上有m个地毯. 给出这些地毯的信息,问每个点被多少个地毯覆盖. 输入输出格式 输入格式: 第一行,两个正整 ...