1.通过Editor改变属性面板(Inspector)中属性的样式
定义了两个变量:attack equipment
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public int attack = 100;
public GameObject equipment;
}
通过Editor来更改样式
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor
{
Test test;
SerializedProperty attack;
void OnEnable()
{
test = serializedObject.targetObject as Test;
attack = serializedObject.FindProperty("attack");
}
public override void OnInspectorGUI()
{
//EditorGUILayout.IntSlider(attack, 0, 200, "攻击力");
int value = EditorGUILayout.IntSlider("攻击力", test.attack, 0, 200);
if(test.attack != value)
{
test.attack = value;
}
}
}
注意要点: Editor上面注明[CustomEditor(typeof(Test))] ,指定是哪个脚本的Editor类
更改样式:int value = EditorGUILayout.IntSlider(“攻击力”, test.attack, 0, 200);