1.首先定义一个须要控制数值的类,类中定义若干个变量ide
using UnityEngine;
using System.Collections;this
using UnityEngine; using System.Collections; // This is not an editor script. public class MyPlayer : MonoBehaviour { public int Jump; void Update () { // Update logic here... } }
2.建立Editor文件夹调试
3.建立Editor类,这里我取名为CatEditorblog
现附上代码下面说明游戏
using UnityEditor; using UnityEngine; [CustomEditor(typeof(RenControll))] [CanEditMultipleObjects] public class CatEditor : Editor { SerializedProperty _Jump; void OnEnable() { // Setup the SerializedProperties. _Jump = serializedObject.FindProperty("Jump"); } public override void OnInspectorGUI() { // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); EditorGUILayout.IntSlider(_Jump, 0, 100, new GUIContent("跳跃次数")); // Only show the armor progress bar if all the objects have the same armor value: if (!_Jump.hasMultipleDifferentValues) ProgressBar(_Jump.intValue / 100.0f, "Attack"); // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. serializedObject.ApplyModifiedProperties(); } // Custom GUILayout progress bar. void ProgressBar(float value, string label) { // Get a rect for the progress bar using the same margins as a textfield: Rect rect = GUILayoutUtility.GetRect(18, 18, "TextField"); EditorGUI.ProgressBar(rect, value, label); EditorGUILayout.Space(); } }
[CustomEditor(typeof(RenControll))]找到咱们游戏中用到的主体类.
_Jump = serializedObject.FindProperty("Jump"); 获取类中的jump变量
EditorGUILayout.IntSlider(_Jump, 0, 100, new GUIContent("跳跃次数"));ip
// Only show the armor progress bar if all the objects have the same armor value:
if (!_Jump.hasMultipleDifferentValues) ProgressBar(_Jump.intValue / 100.0f, "Attack");string
建立滑动条it
打开unity就会显示可供调试的滑动条了.io