Cloud Code JavaScript 파일
Manage your Cloud Code scripts from the Unity Editor using script files and the Deployment package.
읽는 시간 1분최근 업데이트: 한 달 전
Cloud Code JavaScript 파일을 사용하여 Unity 에디터에서 스크립트를 관리합니다. Deployment 패키지를 사용하여 Unity Cloud Dashboard에 스크립트를 배포할 수 있습니다.
필수 조건
Cloud Code 스크립트를 사용하려면 Deployment 패키지(com.unity.services.deploymentCloud Code 스크립트 파일을 만듭니다
Cloud Code 스크립트 파일을 만들려면 다음 내용을 따릅니다.- Unity 에디터에서 프로젝트 창을 오른쪽 클릭하고 Create > Services > Cloud Code Js Script를 선택합니다.
파일 포맷
파일 포맷은 .js 표준을 따릅니다.예시
저작(authoring) 옵션에 관한 자세한 내용은 에디터에서 스크립트 작성을 참고하십시오./* * -------- Example Cloud Code Script -------- * * Roll a 6-sided dice and get back the result * * -------------------------------------------- * Additional imports are limited to: * - lodash-4.17 * - axios-0.21 * - @unity-services/cloud-save-1.0 * - @unity-services/economy-2.0 * - @unity-services/remote-config-1.0 */ // Include the lodash module for convenient functions such as "random"const _ = require("lodash-4.17");const NUMBER_OF_SIDES = 6;/* * CommonJS wrapper for the script. It receives a single argument, which can be destructured into: * - params: Object containing the parameters provided to the script, accessible as object properties * - context: Object containing the projectId, environmentId, environmentName, playerId and accessToken properties. * - logger: Logging client for the script. Provides debug(), info(), warning() and error() log levels. */module.exports = async ({ params, context, logger }) => { // Log an info message with the parameters provided to the script and the invocation context logger.info("Script parameters: " + JSON.stringify(params)); logger.info("Authenticated within the following context: " + JSON.stringify(context)); const roll = rollDice(NUMBER_OF_SIDES); if (roll > NUMBER_OF_SIDES) { // Log an error message with information about the exception logger.error("The roll is greater than the number of sides: " + roll); // Return an error back to the client throw Error("Unable to roll dice!"); } // Return the JSON result to the client return { sides: NUMBER_OF_SIDES, roll: roll, };};// Functions can exist outside of the script wrapperfunction rollDice(sides) { return _.random(1, sides);}
파일 배포
Cloud Code 스크립트 파일을 생성하면 선택한 환경에 파일을 배포할 수 있습니다. 파일을 배포하려면 다음 내용을 따릅니다.- Unity 에디터에서 Services > Deployment를 선택합니다. Unity 버전이 2022 미만인 경우 Window > Deployment를 선택합니다. Deployment 창에 로컬 Cloud Code 스크립트 파일이 표시됩니다.
- 선택된 Cloud Code 스크립트 파일을 선택하고 Deploy Selected를 선택합니다.