Unity编辑器扩展Texture显示选择框
生活随笔
收集整理的这篇文章主要介绍了
Unity编辑器扩展Texture显示选择框
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
学习NGUI插件的时候,突然间有一个问题为什么它这些属性可以通过弹出窗口来选中呢? 而我自己写的组件只能使用手动拖放的方式=.=.
Unity开发了组件Inspector视图扩展API,如果我们要写插件方便别人来使用,使用编辑器扩展API让我们的组件显示的更华丽,使用方便
Texture弹出选择框选中图片赋值:
1个组件对应1个Edit扩展器,继承Editor必须让入Editor文件夹下
MyComponent:
using UnityEngine; using System.Collections;public class MyComponent : MonoBehaviour {//不让字段显示在Inspector视图上面 [SerializeField]private Rect rectValue;[SerializeField]private Texture texture;public Texture Texture{get { return texture; }set { texture = value; }}public Rect RectValue{get { return rectValue; }set { rectValue = value; }} }MyComponentEdit编辑器:
using UnityEngine; using System.Collections; using UnityEditor;[CustomEditor(typeof(MyComponent))] public class MyComponentEdit : Editor {public override void OnInspectorGUI() {MyComponent edit = (MyComponent)target;edit.RectValue = EditorGUILayout.RectField("窗口坐标", edit.RectValue); //将贴图属性,以选择框形式显示在Inspector视图上面,方便我们选择贴图edit.Texture = EditorGUILayout.ObjectField("增加一个贴图", edit.Texture, typeof(Texture), true) as Texture;} }
本文固定链接: http://www.xuanyusong.com/archives/2202
转载请注明: 雨松MOMO 2013年04月11日 于 雨松MOMO程序研究院 发表
转载于:https://www.cnblogs.com/plateFace/p/4282729.html
总结
以上是生活随笔为你收集整理的Unity编辑器扩展Texture显示选择框的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 网络爬虫基本原理(一)
- 下一篇: 编程实现WCF服务