EditorGUI.actionKey

Unity · Версия 2020.3 LTS · Scripting · EditorGUI

EditorGUI.actionKey

public static bool actionKey;

Описание

Нажата ли зависящая от платформы клавиша модификатора «действие»? (Только чтение)

Ключ Command в macOS и Control в Windows.

Действие Использование клавиши, клавиша не нажата/клавиша нажата.
using UnityEngine;
using UnityEditor;


// Показывает поле пароля со «скрытым» текстом.
// Когда пользователь нажимает клавишу действия, поле пароля становится текстовым полем.

class EditorGUIActionKey : EditorWindow
{
    string text = "This is some text";

    [MenuItem("Examples/Show Hide password")]
    static void Init()
    {
        var window = GetWindow();
        window.position = new Rect(0, 0, 250, 60);
        window.Show();
    }

    void OnGUI()
    {
        // Show the contents
        if (EditorGUI.actionKey)
        {
            text = EditorGUI.TextField(new Rect(0, 5, 245, 20), "Shown  Text:", text);
        }
        else
        {
            // show the pasword field
            text = EditorGUI.PasswordField(new Rect(0, 5, 245, 20), "Hidden Text:", text);
        }
        if (GUI.Button(new Rect(0, 30, 250, 20), "Close"))
            this.Close();
    }

    void OnInspectorUpdate()
    {
        Repaint();
    }
}

Обновлено 17 ноября 2026 г.