unity Editor的使用

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

相關文章
相關標籤/搜索