misc/visual
비주얼 객체. (비주얼 에디터 문서를 정한 자리에 노드 트리로 짓는 컴포넌트)
Visual object. (A component that builds a visual editor document into a node tree at a set location)
Visualextends Component
비주얼 객체. (비주얼 에디터 문서를 정한 자리에 노드 트리로 짓는 컴포넌트)
- 문서는 비주얼 에디터(tools/visualeditor)가 저장하는 UIDocument JSON 글이다. ({ version, root, frameSize? }, 씬과 프리팹 모두) VisualAsset 이 파일을 읽어 문서를 든 Visual 을 만든다.
- createNode(uiDocument) 가 넘겨받은 문서로 노드 트리를 새로 지어 뿌리의 로컬 위치를 location 으로 둔다. (부르는 쪽이 원하는 부모에 붙인다, 부를 때마다 새 트리)
- 스스로 그리거나 갱신하지 않는다.
Visual object. (A component that builds a visual editor document into a node tree at a set location)
- The document is the UIDocument JSON text saved by the visual editor (tools/visualeditor). ({ version, root, frameSize? }, both scenes and prefabs) VisualAsset reads the file and makes a Visual holding the document.
- createNode(uiDocument) builds a new node tree with the given document and sets the root's local position to location. (The caller attaches it to the parent it wants, a new tree on every call)
- It does not draw or update by itself.
import { Visual, UIDocument, WorldNode, Vector2 } from "./build/vanilla.js";
const documentData = {
version: 1,
root: { type: "WorldNode", name: "Badge", position: [300, 200], contentSize: [64, 64], components: [], children: [] },
};
const visual = new Visual();
visual.setDocumentText(JSON.stringify(documentData));
visual.setLocation(Vector2.create(40, 20));
const parentNode = new WorldNode();
const badgeNode = visual.createNode(new UIDocument());
parentNode.addChild(badgeNode);
const localPosition = badgeNode.getLocalPosition();
console.log(badgeNode.getName(), localPosition.x, localPosition.y, visual.getComponentType());위치 설정.
Sets the position.
- locationVector2
- createNode 가 지은 뿌리 노드에 줄 로컬 위치. (부모 기준, 기본 0)Local position given to the root node built by createNode. (Relative to the parent, default 0)
짝Counterpart: vanilla-engine Visual.set_location
import { Visual, Vector2 } from "./build/vanilla.js";
const visual = new Visual();
visual.setLocation(Vector2.create(120, 80));
const location = visual.getLocation();
console.log(location.x, location.y);위치 반환.
Returns the position.
반환ReturnsVector2 지은 뿌리 노드에 줄 로컬 위치. (복사본이 아니다)Local position given to the built root node. (Not a copy)
짝Counterpart: vanilla-engine Visual.get_location
문서 글 설정.
Set the document text.
- documentTextstring | null
- 비주얼 에디터가 저장한 UIDocument JSON 글. (null 이면 비운다, 읽는 것은 createNode 때)UIDocument JSON text saved by the visual editor. (null clears it, it is read at createNode)
짝Counterpart: vanilla-engine Visual.set_document_text
문서 글 반환.
Get the document text.
반환Returnsstring | null 든 문서 글. (없으면 null)Held document text. (null when there is none)
짝Counterpart: vanilla-engine Visual.get_document_text
문서로 노드 트리 짓기. (넘겨받은 UIDocument 로 짓는다, 게임이 등록한 종류와 그림 해석기를 쓴다)
Builds a node tree from the document. (builds with the given UIDocument, using the types and image resolver the game registered)
- uiDocumentUIDocument
- 노드와 컴포넌트를 지을 문서.The document that builds the nodes and components.
반환ReturnsWorldNode | null 새로 지은 뿌리 노드. (어느 부모에도 붙지 않았고 로컬 위치가 location 이다, 문서가 없으면 null, 문서 꼴이 틀리면 예외를 던진다)Newly built root node. (Not attached to any parent, its local position is location. null when there is no document, throws when the document is malformed)
짝Counterpart: vanilla-engine Visual.create_node
import { Visual, UIDocument, Vector2 } from "./build/vanilla.js";
const uiDocument = new UIDocument();
const documentData = {
version: 1,
root: { type: "WorldNode", name: "Coin", contentSize: [32, 32], components: [], children: [] },
};
const visual = new Visual();
console.log(visual.createNode(uiDocument));
visual.setDocumentText(JSON.stringify(documentData));
const firstNode = visual.createNode(uiDocument);
visual.setLocation(Vector2.create(48, 0));
const secondNode = visual.createNode(uiDocument);
const secondPosition = secondNode.getLocalPosition();
console.log(firstNode !== secondNode, secondNode.getName(), secondPosition.x);