Scripts de Entidad de Cliente

You can make content in Overte interactive by attaching scripts to entities. Client entity scripts are entity scripts that run locally on each user's computer. When a user encounters the entity by loading it into view, it will "preload" (or run) the script, then "unload" (or stop) the script when the user leaves.

There typically are multiple entities in a domain, and each one can have a different client entity script associated with it.

As each client entity script will run on all users' clients simultaneously, it is most suitable for responding to each user interacting with it. If you want to control its behaviour independently, you can give it a brain using a server entity script.

Adjuntar un Script de Entidad del Cliente a una Entidad

Para adjuntar un script de entidad del cliente a una entidad:

  1. En la interfaz, abre tu tableta o HUD y ve a Crear.

  2. Selecciona la entidad que deseas programar haciendo clic sobre ella en Interface o encontrándola en la 'Lista de Entidades'.

  3. In the Create app, go to the 'Properties' tab and select the Scripts icon. paper and quill icon

  4. Para Script, ingresa la URL a tu script de entidad del cliente.

Nota

For client entity scripts, the URL content must be available to every user who visits the domain. This means the URL should be a public http(s) URL, or an Asset Server (ATP) URL for the domain. It cannot be a file URL. The script property also accepts a string as input, allowing you to insert the code directly.

Ejemplo de un Script de Entidad del Cliente

El siguiente script cambia el color de una entidad que no es un modelo (como una caja o una esfera) cuando haces clic sobre ella:

(function () {
    "use strict"
    let clicked = false;
    this.mousePressOnEntity = function (entityID, mouseEvent) {
        if (clicked){
            Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
            clicked = false;
        } else {
            Entities.editEntity(entityID, { color: { red: 255, green: 255, blue: 0} });
            clicked = true;
        }
    };
});

Client Entity Scripts are written as a JavaScript class prototype function, and this example uses the mouse/controller event mousePressOnEntity(). When the user clicks on an entity, mousePressOnEntity() triggers the function associated with that click event. In this case, it changes the entity's color back and forth between yellow and magenta.

Nota

Entity scripts must be inside a class prototype function. In the above example we include "use strict" on the first line of the client entity script to enable strict mode . This must be inside the class prototype function, not the first line of the file as in other scripts.

Ver también