PlayCanvas Editor API Extension

Load as a script extension under Editor in the Asset List. The @namespace link is a sample project.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        PlayCanvas Editor API Extension
// @name:ja     PlayCanvas Editor API拡張
// @namespace   https://playcanvas.com/editor/scene/1636573
// @match       https://playcanvas.com/editor/scene/*
// @grant       none
// @version     1.0
// @author      yushimatenjin
// @description Load as a script extension under Editor in the Asset List. The @namespace link is a sample project.
// @description:ja 「Assets」→「Editor」ファイルの下にあるスクリプトを拡張機能としてロードします。@namespaceのサンプルプロジェクトを御覧ください。
// @license MIT
// ==/UserScript==


(function() {
  // Assetsのフォルダ一覧からEditor以下のJavaScriptファイルを拡張として読み込みます
  const importExtensionsFromAssets = () => {
    const extentionsFolder = editor.assets.list().find((data) => {
      const { type, name, path } = data.json();
      return type === "folder" && name === "Editor" && path.length === 0;
    });

    if (!extentionsFolder) {
      console.warn("Create an Editor folder in the assets.");
      return;
    }

    const extentions = editor.assets.list().filter((data) => {
      const { path, type } = data.json();
      return path[0] === extentionsFolder.json().id && type === "script";
    });

    extentions.forEach((data) => {
      const { url } = data.json().file;
      var script = document.createElement("script");
      script.src = url;
      console.log(url)
      document.head.appendChild(script);
    });
  };

   editor.on('assets:load', () => importExtensionsFromAssets());
})();