unity中Inspector属性面板的扩展二

紧接着上一节

1.在属性面板中扩展进度值滑动条

   其中ChangeInspector脚本中:public float slideValue = 0.8f;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeInspector : MonoBehaviour {
    private Texture texture;
    // private私有的,受保护,不会在属性面板中出现
    private Rect rectValue;
    private string remark;//备注
    public float slideValue = 0.8f;
    public Texture Texture
    {
        get
        {
            return texture;
        }

        set
        {
            texture = value;
        }
    }

    public Rect RectValue
    {
        get
        {
            return rectValue;
        }

        set
        {
            rectValue = value;
        }
    }

    public string Remark
    {
        get
        {
            return remark;
        }

        set
        {
            remark = value;
        }
    }
}

InspectorEditor脚本中添加;

inspectorObj.slideValue = EditorGUILayout.Slider("进度值", inspectorObj.slideValue,0f,1f); //绘制滑动条

面板结果:

2.添加复选框

ChangeInspector脚本中添加:

public bool isOpen = true;//开启

InspectorEditor脚本中添加;

 inspectorObj.isOpen= EditorGUILayout.Toggle("开启", inspectorObj.isOpen);

结果:

3.如何在属性面板添加下拉列表

首先新建C#脚本,命名为ToolType

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Tool
{ 
    public enum EDirType
    {
        up,
        down,
        left,
        right
    }
public class ToolType : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}
}

ChangeInspector脚本内容:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Tool;


public class ChangeInspector : MonoBehaviour {
    private Texture texture;
    // private私有的,受保护,不会在属性面板中出现
    private Rect rectValue;
    private string remark;//备注
    public float slideValue = 0.8f;//进度值
    [HideInInspector]
    public bool isOpen = true;//开启
    public EDirType theType = EDirType.up; //下拉列表
    public Texture Texture
    {
        get
        {
            return texture;
        }

        set
        {
            texture = value;
        }
    }

    public Rect RectValue
    {
        get
        {
            return rectValue;
        }

        set
        {
            rectValue = value;
        }
    }

    public string Remark
    {
        get
        {
            return remark;
        }

        set
        {
            remark = value;
        }
    }
}

InspectorEditor脚本内容:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Tool;


[CustomEditor(typeof(ChangeInspector))]
public class InspectorEditor : Editor {
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        ChangeInspector inspectorObj = (ChangeInspector)target;
        //绘制贴图槽
        inspectorObj.Texture = EditorGUILayout.ObjectField("选择贴图",inspectorObj.Texture,typeof(Texture),true)as Texture;
        inspectorObj.RectValue = EditorGUILayout.RectField("窗口坐标",inspectorObj.RectValue);
        inspectorObj.Remark = EditorGUILayout.TextField("备注", inspectorObj.Remark);
        //绘制滑动条
        inspectorObj.slideValue = EditorGUILayout.Slider("进度值", inspectorObj.slideValue,0f,1f);
        //复选框
        inspectorObj.isOpen= EditorGUILayout.Toggle("开启", inspectorObj.isOpen);
        inspectorObj.theType= (EDirType)EditorGUILayout.EnumPopup("方向", inspectorObj.theType);


    }
}
结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值