添加属性面板中的“选择贴图”和“窗口坐标”
1.新建C#脚本ChangeInspector
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeInspector : MonoBehaviour {
public Texture texture;
public Rect rectValue;
}
2.新建C#脚本InspectorEditor
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[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);
}
}
结果:
如要想要隐藏面板中的Texture和Rect Value 代码如下;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeInspector : MonoBehaviour {
[HideInInspector]//隐藏窗口
public Texture texture;
[HideInInspector]
public Rect rectValue;
}
隐藏后面板如下:
3.接下来添加一个文本输入框
ChangeInspector脚本中:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeInspector : MonoBehaviour {
[HideInInspector]//隐藏窗口
public Texture texture;
[HideInInspector]
public Rect rectValue;
[HideInInspector]
public string remark;//备注
}
InspectorEditor脚本中:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[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);
}
}
结果: