使用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

 

代码部分:

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. using UnityEngine.UI;
  5.  
  6. /// <summary>
  7. /// 根据快捷键创建UGUI控件
  8. /// 快捷键符号% Ctrl # Shift & Alt
  9. /// </summary>
  10. public class UGUIShortcutKey : Editor
  11. {
  12.  
  13. public const int UIlayer = 5; //UI
  14.  
  15. [MenuItem("Plateface/CreateUGUI Text #&L")]
  16. public static void CreateText()
  17. {
  18. if (Selection.gameObjects.Length > 0)
  19. {
  20. GameObject obj = Selection.gameObjects[0];
  21. GameObject text = new GameObject();
  22. RectTransform textRect = text.AddComponent<RectTransform>();
  23. Text textTx = text.AddComponent<Text>();
  24. text.transform.SetParent(obj.transform);
  25. text.name = "Text";
  26. text.layer = UIlayer;
  27. textTx.text = "plateface";
  28.  
  29. textRect.localScale = new Vector3(1, 1, 1);
  30. textRect.anchoredPosition = Vector2.zero;
  31. textRect.anchoredPosition3D = Vector3.zero;
  32.  
  33. RectTransformZero(textRect);
  34. }
  35.  
  36. }
  37.  
  38. [MenuItem("Plateface/CreateUGUI Button #&B")]
  39. public static void CreateButton()
  40. {
  41. if (Selection.gameObjects.Length > 0)
  42. {
  43. Debug.Log("创建按钮");
  44. GameObject obj = Selection.gameObjects[0];
  45. if (obj == null) return;
  46.  
  47. GameObject button = new GameObject();
  48. GameObject buttonTx = new GameObject();
  49.  
  50. RectTransform buttonRect = button.AddComponent<RectTransform>();
  51. RectTransform buttonTxRect = buttonTx.AddComponent<RectTransform>();
  52.  
  53. button.AddComponent<Image>();
  54. buttonTx.AddComponent<Text>();
  55.  
  56. button.transform.SetParent(obj.transform);
  57. buttonTx.transform.SetParent(button.transform);
  58. button.name = "Button";
  59. buttonTx.name = "Text";
  60.  
  61. button.layer = UIlayer;
  62. buttonTx.layer = UIlayer;
  63.  
  64. RectTransformZero(buttonRect);
  65. RectTransformZero(buttonTxRect);
  66.  
  67. }
  68. }
  69.  
  70. [MenuItem("Plateface/CreateUGUI Image #&S")]
  71. public static void CreateImage()
  72. {
  73. if (Selection.gameObjects.Length > 0)
  74. {
  75. Debug.Log("创建UGUI图片");
  76. GameObject obj = Selection.gameObjects[0];
  77. RectTransform selectionObjRect = Selection.gameObjects[0].GetComponent<RectTransform>();
  78.  
  79. GameObject image = new GameObject();
  80. RectTransform imageRect = image.AddComponent<RectTransform>();
  81. image.AddComponent<Image>();
  82. image.transform.SetParent(obj.transform);
  83. image.name = "Image";
  84. image.layer = 5;
  85.  
  86. RectTransformZero(imageRect);
  87. }
  88.  
  89. }
  90.  
  91. [MenuItem("Plateface/CreateUGUI InputField #&I")]
  92. public static void CreateInputField()
  93. {
  94. //创建UGUI标签
  95. GameObject obj = Selection.gameObjects[0];
  96.  
  97. GameObject inputField = new GameObject();
  98. RectTransform rectTransform = inputField.AddComponent<RectTransform>();
  99. Image image = inputField.AddComponent<Image>();
  100. image.sprite = Resources.Load<Sprite>("UnityPlugins/UGUIShortcutKeyTexture/background1");
  101. inputField.AddComponent<InputField>();
  102. rectTransform.localScale = new Vector3(1, 1, 1);
  103. inputField.layer = UIlayer;
  104.  
  105. inputField.transform.SetParent(obj.transform);
  106. inputField.name = "InputField";
  107.  
  108. GameObject placeholder = new GameObject();
  109. Text placeholderTx = placeholder.AddComponent<Text>();
  110. placeholder.transform.SetParent(inputField.transform);
  111. placeholder.name = "Placeholder";
  112. placeholder.layer = UIlayer;
  113. placeholderTx.color = Color.black;
  114.  
  115. GameObject text = new GameObject();
  116. Text textTx = text.AddComponent<Text>();
  117. text.transform.SetParent(inputField.transform);
  118. text.name = "Text";
  119. text.layer = UIlayer;
  120.  
  121. textTx.color = Color.black;
  122.  
  123. RectTransformZero(rectTransform);
  124.  
  125. }
  126.  
  127. public static void RectTransformZero(RectTransform rectTransform)
  128. {
  129. rectTransform.localScale = new Vector3(1, 1, 1);
  130. rectTransform.anchoredPosition = Vector2.zero;
  131. rectTransform.anchoredPosition3D = Vector3.zero;
  132. }
  133. }

 

插件下载地址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. Spring redirect直接返回项目根文件夹

    return "redirect:/";

  2. Android自定义控件(三)——有弹性的ListView

    上一次我们试验了有弹性的ScrollView.详情 这一次,我们来试验有弹性的ScrollView. 国际惯例,效果图: 主要代码: import android.content.Context; i ...

  3. .NET基础拾遗(4)委托和事件1

    一.委托初窥:一个拥有方法的对象 (1)本质:持有一个或多个方法的对象:委托和典型的对象不同,执行委托实际上是执行它所“持有”的方法. (2)如何使用委托? ①声明委托类型(delegate关键字) ...

  4. DataTable复制自身行

    在我们工作的过程中有可能要使用DataTable产生一些重复数据(在不重复读取数据库的情况下) 无废话,直接上代码 DataTable复制自身一行(目的产生重复数据),已测试通过可直接复制 /// & ...

  5. Tomcat项目部署方式

    一.静态部署 1.直接将web项目文件件拷贝到webapps 目录中      Tomcat的Webapps目录是Tomcat默认的应用目录,当服务器启动时,会加载所有这个目录下的应用.所以可以将JS ...

  6. 使用hibernate优化

    a. 在查询字符串中,应该总是使用jdbc的占位符?,或使用使用命名参数:,不要自查询中使用字符串值来代替非常量值.   b.  Flush会影响性能,频繁刷新影响性能,尽量减少不必要的刷新.   c ...

  7. struts2 result的type属性

    目前只使用过以下3种,都是直接跳转到另一个action  chain: 写法:<result name="success" type="chain"> ...

  8. Java中,&&与&;||与|的区别

    我们很多人在学习Java的时候,或者其他语言(如:C#,.Net等)都会遇到&和&&,|和||.然而,如果你没有真正理解他们的意思,这回给你的思路上带来很大的麻烦.在Java的 ...

  9. 页面每次加载时重新获取css文件

    <script> (function(){ var version=''; var xmlhttp; // code for IE7+, Firefox, Chrome, Opera, S ...

  10. Java Load Properties 文件,定义message信息

    初始化Properties对象,load properties文件: private static final Properties MESSAGERESOURCES = new Properties ...