vanilladocs
vanillapunch.com
API / resource/visualasset

resource/visualasset

비주얼 애셋. (비주얼 에디터가 저장한 문서 파일을 읽어 Visual 을 만든다)

Visual asset. (Reads a document file saved by the visual editor and makes a Visual)

VisualAssetextends Asset

짝Counterpart: vanilla-engine VisualAsset

비주얼 애셋. (비주얼 에디터가 저장한 문서 파일을 읽어 Visual 을 만든다)

  • 파일은 비주얼 에디터(tools/visualeditor)가 저장하는 UIDocument JSON 이다. (씬 *.scene.json, 프리팹 *.prefab.json, { version, root, frameSize? })
  • load 가 fetch 로 글을 받아 JSON 객체이고 root 객체가 있는지 보고, 그 글을 든 Visual 을 만들어 담은 뒤 읽힌 것으로 친다. 실패 응답(404 등)이나 문서 꼴이 아니면 읽히지 않은 채로 거부된다.
  • 노드 트리는 Visual.createNode 가 짓는다. (부를 때마다 새 트리)

Visual asset. (Reads a document file saved by the visual editor and makes a Visual)

  • The file is the UIDocument JSON saved by the visual editor (tools/visualeditor). (Scene *.scene.json, prefab *.prefab.json, { version, root, frameSize? })
  • load fetches the text, checks that it is a JSON object with a root object, stores a Visual holding that text, and counts as loaded. A failed response (404 and so on) or a malformed document is rejected and stays unloaded.
  • Visual.createNode builds the node tree. (A new tree on every call)
예제Example비주얼 에디터 프리팹 읽어 노드 짓기Read a visual editor prefab and build nodes
import { VisualAsset, UIDocument } from "./build/vanilla.js";

const documentData = {
	version: 1,
	root: { type: "WorldNode", name: "Panel", contentSize: [200, 120], components: [], children: [] },
};
const documentUrl = "data:application/json," + encodeURIComponent(JSON.stringify(documentData));
const visualAsset = new VisualAsset();
await visualAsset.load(documentUrl);
const visual = visualAsset.getVisual();
const panelNode = visual.createNode(new UIDocument());
console.log(visualAsset.getAssetType(), visualAsset.isLoaded(), panelNode.getName());
생성자constructorconstructor()#0.0.9 부터since 0.0.9소스source

생성.

Constructor.

짝Counterpart: vanilla-engine VisualAsset.new

정적staticstatic createVisualFromText(documentText)#0.4.0 부터since 0.4.0소스source

문서 글로 Visual 만들기. (정적)

Make a Visual from document text. (Static)

documentTextstring
비주얼 에디터가 저장한 UIDocument JSON 글.UIDocument JSON text saved by the visual editor.

반환ReturnsVisual 그 글을 든 Visual. (JSON 객체가 아니거나 root 객체가 없으면 예외를 던진다)Visual holding that text. (Throws when it is not a JSON object or has no root object)

짝Counterpart: vanilla-engine VisualAsset.create_visual_from_text

예제Example문서 글에서 바로 만들기Make one straight from document text
import { VisualAsset, UIDocument } from "./build/vanilla.js";

const documentText = JSON.stringify({ version: 1, root: { type: "WorldNode", name: "Icon", components: [], children: [] } });
const visual = VisualAsset.createVisualFromText(documentText);
const iconNode = visual.createNode(new UIDocument());
console.log(iconNode.getName());
메서드methodasync load(assetPath)#0.0.9 부터since 0.0.9소스source

비동기 애셋 로드.

Loads the asset asynchronously.

assetPathstring
비주얼 에디터가 저장한 문서 파일 경로. (이미 읽혔으면 아무것도 하지 않는다)Path of a document file saved by the visual editor. (Does nothing when already loaded)

반환ReturnsPromise<void> 읽어 Visual 을 담으면 풀리는 약속. (실패 응답(404 등)이나 문서 꼴이 아니면 거부된다)Promise that resolves after reading and storing the Visual. (Rejected for a failed response (404 and so on) or a malformed document)

짝Counterpart: vanilla-engine VisualAsset.load

메서드methodunload()#0.4.0 부터since 0.4.0소스source

애셋 언로드. (담은 Visual 도 비운다)

Unload the asset. (Also clears the stored Visual)

반환ReturnsPromise<void> | undefined 로드되지 않았으면 이미 풀린 프로미스, 로드되어 있었으면 undefined.An already resolved promise if not loaded, undefined if it was loaded.

짝Counterpart: vanilla-engine VisualAsset.unload

메서드methodsetVisual(visual)#0.4.0 부터since 0.4.0소스source

비주얼 설정.

Sets the visual.

visualVisual | null
담을 비주얼. (null 이면 비운다, 읽힌 상태는 바꾸지 않는다)Visual to store. (null clears it, does not change the loaded state)

짝Counterpart: vanilla-engine VisualAsset.set_visual

메서드methodgetVisual()#0.4.0 부터since 0.4.0소스source

비주얼 반환. (없으면 null)

Returns the visual. (null if none)

반환ReturnsVisual | null 담긴 비주얼. (load 가 읽은 문서를 든 것이거나 setVisual 로 넣은 것)Stored visual. (The one holding the document read by load, or the one set with setVisual)

짝Counterpart: vanilla-engine VisualAsset.get_visual