- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
要对Editor进行编辑,unity要求对此进行操作的脚本必须放在Editor文件夹内,创建一个Editor文件夹和一个CustomEditor文件夹,创建一个LevelScript在CustomEditor内,编辑脚本如下:
UnityEngine;
using System.Collections;
public class LevelScript : MonoBehaviour
{
public int experience;
public int Level
{
get{ return experience / 750; }}//确保exprience只读
}
接着,在Editor文件夹下创建一个LevelScriptEditor,编辑脚本如下:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(LevelScript))]
public class LevelScriptEditor : Editor
{
public override void OnInspectorGUI()//重写OnInspectorGUI方法
{
LevelScript myTarget = (LevelScript)target;
myTarget.experience = EditorGUILayout.IntField("Experience", myTarget.experience);
EditorGUILayout.LabelField("Level", myTarget.Level.ToString());
}
}
|
|