zoukankan      html  css  js  c++  java
  • Unity编辑器扩展Texture显示选择框

    学习NGUI插件的时候,突然间有一个问题为什么它这些属性可以通过弹出窗口来选中呢? 而我自己写的组件只能使用手动拖放的方式=.=.

    Unity开发了组件Inspector视图扩展API,如果我们要写插件方便别人来使用,使用编辑器扩展API让我们的组件显示的更华丽,使用方便

    Texture弹出选择框选中图片赋值:

    1个组件对应1个Edit扩展器,继承Editor必须让入Editor文件夹下

    image

    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;
        }
    }

    image

    本文固定链接: http://www.xuanyusong.com/archives/2202

    转载请注明: 雨松MOMO 2013年04月11日 于 雨松MOMO程序研究院 发表

    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    DBG
    gdb Debugging Full Example
    Java Warmup
    Dtrace for Linux 2016
    分布式系统理论进阶
    Java theory and practice
    Dealing with InterruptedException
    JVM 虚拟化
    Intro to Filtering with Network Monitor 3.0
    spring 官方文档
  • 原文地址:https://www.cnblogs.com/plateFace/p/4282729.html
Copyright © 2011-2022 走看看