สร้างโลกของคุณเอง
บันทึกเสียง
VideoRecording
4นาที
คุณสามารถบันทึกหรือแชร์วิดีโอภายในโลกโดยใช้ฟังก์ชันวิดีโอใน worldvideorecorder api และสร้างฟีดโดยใช้วิดีโอ เพื่อใช้ฟังก์ชันการบันทึกวิดีโอและการบันทึก/แชร์/โพสต์ฟีด คุณต้องสร้างคำสั่งนำเข้าดังนี้ import { worldvideorecorder } from 'zepeto world'; worldvideorecorder api มีฟังก์ชันที่เกี่ยวข้องกับวิดีโอดังต่อไปนี้ api คำอธิบาย worldvideorecorder startrecording(camera unityengine camera, resolutions videoresolutions, durationsecond number)\ boolean เริ่มบันทึกวิดีโอ คุณสามารถตั้งค่ากล้องบันทึก ความละเอียดวิดีโอ และเวลาบันทึกเป็นพารามิเตอร์ ผลลัพธ์ที่ส่งกลับจะแสดงว่าการเริ่มบันทึกสำเร็จหรือไม่ \ enum videoresolutions { w1280xh720 = 0, w720xh1280 = 1, w1920xh1080 = 2, w1080xh1920 = 3 } \ durationsecond ค่าสูงสุดคือ 60 ดังนั้นกรุณาใส่ค่าน้อยกว่า 60 หากเป็นไปได้ worldvideorecorder stoprecording() หยุดการบันทึกวิดีโอที่กำลังดำเนินอยู่ worldvideorecorder isrecording()\ boolean ส่งคืนว่าควรดำเนินการบันทึกวิดีโอต่อไปหรือไม่ worldvideorecorder savetocameraroll(callback system action$1) บันทึกวิดีโอลงในห้องสมุดภาพถ่าย worldvideorecorder share(callback system action$1) แชร์วิดีโอกับแอปพลิเคชันภายนอก worldvideorecorder createfeed(contents string, $callback system action$1) อัปโหลดวิดีโอไปยังฟีด ปัจจัยแรกคือ contents ซึ่งช่วยให้คุณกำหนดเนื้อหาของโพสต์ได้ worldvideorecorder addvideoplayercomponent(playerobject unityengine gameobject, rendertexture unityengine rendertexture)\ unityengine video videoplayer เพิ่มส่วนประกอบผู้เล่นวิดีโอลงใน gameobject ที่คุณต้องการเล่นวิดีโอ และเชื่อมต่อไฟล์วิดีโอที่บันทึกไว้ สิ่งนี้จะส่งคืนผู้เล่นวิดีโอที่เพิ่มเข้าไปและให้คุณกำหนดความกว้าง ความสูง หรือ rendertexture เพื่อเล่นวิดีโอ ขึ้นอยู่กับพารามิเตอร์ worldvideorecorder getthumbnail()\ unityengine texture2d; ส่งคืนภาพขนาดย่อของวิดีโอที่บันทึกไว้ ต่อไปนี้คือตัวอย่างการเรียกใช้ฟังก์ชันของการบันทึก/แชร์/โพสต์วิดีโอของฉันภายใน world video recorder ไม่สามารถตรวจสอบได้ในสภาพแวดล้อมของ unity editor แต่สามารถตรวจสอบได้เมื่อเล่นผ่านแอปพลิเคชัน ความละเอียดจะถูกบันทึกตามค่าที่กำหนดเมื่อบันทึกเป็นไฟล์ แต่ความละเอียดอาจเปลี่ยนแปลงเมื่ออัปโหลดไปยัง zepeto feed หากคุณป้อนค่ามากกว่า 60 สำหรับ durationsecond การบันทึกจะไม่ทำงานอย่างถูกต้อง worldvideorecorder savetocameraroll(result => {console log(`${result}`)}); worldvideorecorder share(result => {console log(`${result}`)}); worldvideorecorder createfeed("\[contents]", result => {console log(`${result}`)}); ต่อไปนี้คือตัวอย่างโค้ดทั้งหมดที่ใช้ฟังก์ชันการบันทึกวิดีโอของฉันภายใน worldvideorecorder โดยใช้ rendertexture import { camera, gameobject, rendertexture } from 'unityengine'; import { button, rawimage } from 'unityengine ui'; import { zepetoscriptbehaviour } from 'zepeto script'; import { videoresolutions, worldvideorecorder } from 'zepeto world'; export default class worldvideorecorderexample extends zepetoscriptbehaviour { // worldvideorecorder video ui public startrecordingbutton button; public stoprecordingbutton button; public savevideobutton button; public sharevideobutton button; public createfeedbutton button; public getthumbnailbutton button; public thumbnailimage rawimage; // recorder camera public recordercamera camera; // target texture public targettexture rendertexture; // videoplayer object private videoplayerobject gameobject; awake() { this videoplayerobject = new gameobject(); } start() { this startrecordingbutton onclick addlistener(() => { if (false == worldvideorecorder startrecording(this recordercamera, videoresolutions w1280xh720, 15)) { return; } this startcoroutine(this checkrecording()); }); this stoprecordingbutton onclick addlistener(() => { if (false == worldvideorecorder isrecording()) { return; } worldvideorecorder stoprecording(); }); this savevideobutton onclick addlistener(() => { if (false == worldvideorecorder isrecording()) { worldvideorecorder savetocameraroll(result => { console log(`${result}`) }); } }); this sharevideobutton onclick addlistener(() => { if (false == worldvideorecorder isrecording()) { worldvideorecorder share(result => { console log(`${result}`) }); } }); this createfeedbutton onclick addlistener(() => { if (false == worldvideorecorder isrecording()) { worldvideorecorder createfeed("\[contents]", result => { console log(`${result}`) }); } }); this getthumbnailbutton onclick addlistener(() => { if (false == worldvideorecorder isrecording()) { this thumbnailimage texture = worldvideorecorder getthumbnail(); } }); } checkrecording() { while (worldvideorecorder isrecording()) { yield null; } let videoplayer = worldvideorecorder addvideoplayercomponent(this videoplayerobject, this targettexture); if (videoplayer == null) { return; } videoplayer play(); } } หลังจากเขียนสคริปต์แล้ว ให้สร้างปุ่มและภาพดิบที่จำเป็นบนแคนวาส หลังจากนั้น ให้กำหนดแต่ละส่วนประกอบใน inspector สำหรับกล้อง คุณสามารถใช้ส่วนประกอบกล้องปกติได้ สำหรับพื้นผิวเป้าหมาย สร้าง > กรุณาสร้างเป็น render texture 👍 เคล็ดลับ หากคุณใช้พื้นผิวการเรนเดอร์เดียวกันกับภาพหน้าจอ มันอาจจะไม่เรนเดอร์อย่างถูกต้อง ดังนั้นโปรดสร้างพื้นผิวการเรนเดอร์ใหม่เฉพาะสำหรับการบันทึกและใช้มัน คุณสามารถทดสอบฟังก์ชันการบันทึกวิดีโอโดยการรันผ่านการสร้าง qr บนมือถือ